Struct AffineTransform
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
Fields
A
The matrix component in the first row, first column (scale X / rotate).
public NFloat A
Field Value
B
The matrix component in the second row, first column (shear Y / rotate).
public NFloat B
Field Value
C
The matrix component in the first row, second column (shear X / rotate).
public NFloat C
Field Value
D
The matrix component in the second row, second column (scale Y / rotate).
public NFloat D
Field Value
Identity
The identity transform (no scale, rotation, or translation).
public static readonly AffineTransform Identity
Field Value
Tx
The translation component along the X axis.
public NFloat Tx
Field Value
Ty
The translation component along the Y axis.
public NFloat Ty
Field Value
Properties
Determinant
Returns the determinant of the 2×2 linear portion of the matrix.
public NFloat Determinant { get; }
Property Value
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
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
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
Scale(Vector)
Creates a scaling transform using the specified scale vector.
public static AffineTransform Scale(Vector v)
Parameters
v
Vector
Returns
Shear(NFloat, NFloat)
Creates a shear (skew) transformation along the X and Y axes.
public static AffineTransform Shear(NFloat shearX, NFloat shearY)
Parameters
shearX
NFloatThe shear factor in the X direction.
shearY
NFloatThe shear factor in the Y direction.
Returns
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
Operators
operator *(AffineTransform, AffineTransform)
Composes two affine transforms using matrix multiplication.
public static AffineTransform operator *(AffineTransform lhs, AffineTransform rhs)
Parameters
lhs
AffineTransformrhs
AffineTransform
Returns
- AffineTransform
A new transform representing the application of
rhs
followed bylhs
.
operator *(AffineTransform, Point)
Applies this transform to a Point, including translation.
public static Point operator *(AffineTransform t, Point p)
Parameters
t
AffineTransformThe affine transform.
p
PointThe point to transform.
Returns
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
AffineTransformThe affine transform.
v
VectorThe vector to transform.
Returns
Remarks
Translation is not applied. Use this to transform directions, movement deltas, or normals.