Table of Contents

Struct AffineTransform

Namespace
Xui.Core.Math2D
Assembly
Core.dll

Represents a 2D affine transformation matrix in the form:

| A C Tx |
| B D Ty |
| 0 0  1 |

Used for rotating, scaling, translating, and skewing 2D vectors or points.

public struct AffineTransform
Inherited Members

Remarks

Transformation is applied as:

| x' |   | A C Tx |   | x |
| y' | = | B D Ty | * | y |
| 1  |   | 0 0  1 |   | 1 |

Constructors

AffineTransform(NFloat, NFloat, NFloat, NFloat, NFloat, NFloat)

Constructs an affine transform with the specified matrix coefficients.

public AffineTransform(NFloat a, NFloat b, NFloat c, NFloat d, NFloat tx, NFloat ty)

Parameters

a NFloat
b NFloat
c NFloat
d NFloat
tx NFloat
ty NFloat

Fields

A

The matrix component in the first row, first column (scale X / rotate).

public NFloat A

Field Value

NFloat

B

The matrix component in the second row, first column (shear Y / rotate).

public NFloat B

Field Value

NFloat

C

The matrix component in the first row, second column (shear X / rotate).

public NFloat C

Field Value

NFloat

D

The matrix component in the second row, second column (scale Y / rotate).

public NFloat D

Field Value

NFloat

Identity

The identity transform (no scale, rotation, or translation).

public static readonly AffineTransform Identity

Field Value

AffineTransform

Tx

The translation component along the X axis.

public NFloat Tx

Field Value

NFloat

Ty

The translation component along the Y axis.

public NFloat Ty

Field Value

NFloat

Properties

Determinant

Returns the determinant of the 2×2 linear portion of the matrix.

public NFloat Determinant { get; }

Property Value

NFloat

Remarks

This value determines if the matrix is invertible. A value of 0 means the matrix cannot be inverted.

Inverse

Returns the inverse of this affine transform.

public AffineTransform Inverse { get; }

Property Value

AffineTransform

Remarks

This operation assumes the transform is invertible. Division by a zero determinant will cause a runtime exception.

IsIdentity

Returns true if the current transform is the identity matrix.

public bool IsIdentity { get; }

Property Value

bool

Methods

Rotate(NFloat)

Creates a rotation transform around the origin using the given angle in radians.

public static AffineTransform Rotate(NFloat angle)

Parameters

angle NFloat

Returns

AffineTransform

Scale(Vector)

Creates a scaling transform using the specified scale vector.

public static AffineTransform Scale(Vector v)

Parameters

v Vector

Returns

AffineTransform

Shear(NFloat, NFloat)

Creates a shear (skew) transformation along the X and Y axes.

public static AffineTransform Shear(NFloat shearX, NFloat shearY)

Parameters

shearX NFloat

The shear factor in the X direction.

shearY NFloat

The shear factor in the Y direction.

Returns

AffineTransform

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Translate(Vector)

Creates a translation transform using the specified offset vector.

public static AffineTransform Translate(Vector v)

Parameters

v Vector

Returns

AffineTransform

Operators

operator *(AffineTransform, AffineTransform)

Composes two affine transforms using matrix multiplication.

public static AffineTransform operator *(AffineTransform lhs, AffineTransform rhs)

Parameters

lhs AffineTransform
rhs AffineTransform

Returns

AffineTransform

A new transform representing the application of rhs followed by lhs.

operator *(AffineTransform, Point)

Applies this transform to a Point, including translation.

public static Point operator *(AffineTransform t, Point p)

Parameters

t AffineTransform

The affine transform.

p Point

The point to transform.

Returns

Point

A new Point with the transform applied.

Remarks

This operation applies the full affine matrix, including scale, rotation, shear, and translation. Use this when transforming coordinates in space (e.g., an element's position).

operator *(AffineTransform, Vector)

Applies only the linear portion (scale, rotation, shear) of this transform to a Vector.

public static Vector operator *(AffineTransform t, Vector v)

Parameters

t AffineTransform

The affine transform.

v Vector

The vector to transform.

Returns

Vector

A new Vector with the linear transform applied.

Remarks

Translation is not applied. Use this to transform directions, movement deltas, or normals.