Transform2D
Two axes and translation for a 2D transform.
transform × point applies both axes and Origin. In parent × child composition, the right transform acts first. Positive rotation appears clockwise in ordinary screen 2D because Y points down.
Inverse and point × transform assume an orthonormal basis. Use AffineInverse for invertible scale. Zero determinant means no inverse. This is a C# struct: assign a modified copy back to the Entity property.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors4
Transform2D4 overloads
public Transform2D(Vector2 xAxis, Vector2 yAxis, Vector2 originPos);Creates a transform from two basis columns and a translation. xAxis and yAxis are columns, not matrix rows.
| Name | Type | Default |
|---|---|---|
xAxis | Vector2 | — |
yAxis | Vector2 | — |
originPos | Vector2 | — |
xAxisFirst basis column.
yAxisSecond basis column.
originPosOrigin translation.
public Transform2D(float rotation, Vector2 origin);Creates a transform from a rotation in radians and a translation. The basis has unit scale and no skew; positive rotation turns Right toward Down in ordinary 2D.
| Name | Type | Default |
|---|---|---|
rotation | float | — |
origin | Vector2 | — |
rotationRotation in radians.
originOrigin translation.
public Transform2D(float rotation, Vector2 scale, float skew, Vector2 origin);Creates a transform from rotation, scale, skew and translation. Rotation and skew are in radians; zero scale can make the basis noninvertible.
| Name | Type | Default |
|---|---|---|
rotation | float | — |
scale | Vector2 | — |
skew | float | — |
origin | Vector2 | — |
rotationRotation in radians.
scaleScale along the local X and Y axes.
skewSkew in radians.
originOrigin translation.
public Transform2D(float xx, float xy, float yx, float yy, float ox, float oy);Constructs a Transform2D from 3 Vector2 values representing Transform2D.X, Transform2D.Y, and the Transform2D.Origin (the three matrix columns).
| Name | Type | Default |
|---|---|---|
xx | float | — |
xy | float | — |
yx | float | — |
yy | float | — |
ox | float | — |
oy | float | — |
xxThe X component of the X column vector, accessed via t.X.X or [0][0].
xyThe Y component of the X column vector, accessed via t.X.Y or [0][1].
yxThe X component of the Y column vector, accessed via t.Y.X or [1][0].
yyThe Y component of the Y column vector, accessed via t.Y.Y or [1][1].
oxThe X component of the origin vector, accessed via t.Origin.X or [2][0].
oyThe Y component of the origin vector, accessed via t.Origin.Y or [2][1].
Properties8
FlipXProperty
public static Transform2D FlipX { get; }When any transform is multiplied by Transform2D.FlipX, it negates all components of the Transform2D.X axis (the X column).
When Transform2D.FlipX is multiplied by any transform, it negates the Vector2.X component of all axes (the X row).
FlipYProperty
public static Transform2D FlipY { get; }When any transform is multiplied by Transform2D.FlipY, it negates all components of the Transform2D.Y axis (the Y column).
When Transform2D.FlipY is multiplied by any transform, it negates the Vector2.Y component of all axes (the Y row).
IdentityProperty
public static Transform2D Identity { get; }Identity transform without translation, rotation or scale change. In C#, parameterless new Transform2D() contains zeros and is not a substitute for Identity.
Item2 overloads
public Vector2 this[int column] { get; set; }Access whole columns in the form of Vector2.
The third column is the Transform2D.Origin vector.
public float this[int column, int row] { get; set; }Access matrix elements in column-major order.
The third column is the Transform2D.Origin vector.
RotationProperty
public float Rotation { get; }Returns the transform's rotation (in radians).
ScaleProperty
public Vector2 Scale { get; }Returns the scale.
SkewProperty
public float Skew { get; }Returns the transform's skew (in radians).
Methods29
AffineInverseTransform2D
public Transform2D AffineInverse();Returns an affine inverse including scale. The determinant must be nonzero; an exactly zero determinant throws InvalidOperationException.
Transform2DThe inverse value. An exactly zero determinant throws InvalidOperationException instead of returning a result.
BasisXformVector2
public Vector2 BasisXform(Vector2 v);Transforms a vector by the basis without Origin translation. Scale and skew still apply; normalize separately when a unit direction is required.
| Name | Type | Default |
|---|---|---|
v | Vector2 | — |
vVector without positional translation.
Vector2Basis-transformed vector, without translation.
BasisXformInvVector2
public Vector2 BasisXformInv(Vector2 v);Applies the transposed basis without translation. This is an inverse only for an orthonormal basis; with scale or skew use AffineInverse().BasisXform(v).
| Name | Type | Default |
|---|---|---|
v | Vector2 | — |
vVector without positional translation.
Vector2Vector transformed by the transposed basis; a correct inverse result requires orthonormality.
Determinantfloat
public float Determinant();Returns the basis determinant X.X * Y.Y - X.Y * Y.X. Zero means noninvertible, a negative value reverses orientation; translation does not affect the result.
floatSigned basis determinant, excluding Origin.
Equals2 overloads
public bool Equals(Transform2D other);Returns true if the transforms are exactly equal.
Note: Due to floating-point precision errors, consider using
Transform2D.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
other | Transform2D | — |
otherThe other transform to compare.
boolWhether or not the matrices are exactly equal.
public override bool Equals(object? obj);Returns true if the transform is exactly equal
to the given object (obj).
Note: Due to floating-point precision errors, consider using
Transform2D.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
obj | object | — |
objThe object to compare with.
boolWhether or not the transform and the object are exactly equal.
GetHashCodeint
public override int GetHashCode();Serves as the hash function for Transform2D.
intA hash code for this transform.
InterpolateWithTransform2D
public Transform2D InterpolateWith(Transform2D transform, float weight);Returns the result of the linear interpolation between this transform and xform by the given weight.
The weight should be between 0.0 and 1.0 (inclusive). Values outside this range are allowed and can be used to perform extrapolation instead.
| Name | Type | Default |
|---|---|---|
transform | Transform2D | — |
weight | float | — |
transformThe other transform.
weightA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Transform2DThe interpolated transform.
InverseTransform2D
public Transform2D Inverse();Fast inverse for orthonormal axes. Use AffineInverse for invertible scale.
Transform2DThe inverse matrix.
IsEqualApproxbool
public bool IsEqualApprox(Transform2D other);Returns true if this transform and xform are approximately equal, by running @GlobalScope.is_equal_approx on each component.
| Name | Type | Default |
|---|---|---|
other | Transform2D | — |
otherThe other transform to compare.
boolWhether or not the matrices are approximately equal.
IsFinitebool
public bool IsFinite();Returns true if this transform is finite, by calling @GlobalScope.is_finite on each component.
boolWhether this vector is finite or not.
OrthonormalizedTransform2D
public Transform2D Orthonormalized();Returns a copy of this transform with its basis orthonormalized. An orthonormal basis is both orthogonal (the axes are perpendicular to each other) and normalized (the axes have a length of 1.0), which also means it can only represent a rotation.
Transform2DThe orthonormalized transform.
RotatedTransform2D
public Transform2D Rotated(float angle);Returns a copy of this transform rotated by the given angle (in radians).
If angle is positive, the transform is rotated clockwise.
This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the left, i.e., R * X.
This can be seen as transforming with respect to the global/parent frame.
| Name | Type | Default |
|---|---|---|
angle | float | — |
angleThe angle to rotate, in radians.
Transform2DThe rotated transformation matrix.
RotatedLocalTransform2D
public Transform2D RotatedLocal(float angle);Returns a copy of the transform rotated by the given angle (in radians).
This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the right, i.e., X * R.
This can be seen as transforming with respect to the local frame.
| Name | Type | Default |
|---|---|---|
angle | float | — |
angleThe angle to rotate, in radians.
Transform2DThe rotated transformation matrix.
ScaledTransform2D
public Transform2D Scaled(Vector2 scale);Returns a copy of the transform scaled by the given scale factor.
This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the left, i.e., S * X.
This can be seen as transforming with respect to the global/parent frame.
| Name | Type | Default |
|---|---|---|
scale | Vector2 | — |
scaleThe scale to introduce.
Transform2DThe scaled transformation matrix.
ScaledLocalTransform2D
public Transform2D ScaledLocal(Vector2 scale);Returns a copy of the transform scaled by the given scale factor.
This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the right, i.e., X * S.
This can be seen as transforming with respect to the local frame.
| Name | Type | Default |
|---|---|---|
scale | Vector2 | — |
scaleThe scale to introduce.
Transform2DThe scaled transformation matrix.
ToString2 overloads
public override string ToString();Converts this Transform2D to a string.
stringA string representation of this transform.
public string ToString(string? format);Converts this Transform2D to a string with the given format.
| Name | Type | Default |
|---|---|---|
format | string | — |
stringA string representation of this transform.
TranslatedTransform2D
public Transform2D Translated(Vector2 offset);Returns a copy of the transform translated by the given offset.
This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the left, i.e., T * X.
This can be seen as transforming with respect to the global/parent frame.
| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
offsetThe offset to translate by.
Transform2DThe translated matrix.
TranslatedLocalTransform2D
public Transform2D TranslatedLocal(Vector2 offset);Returns a copy of the transform translated by the given offset.
This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the right, i.e., X * T.
This can be seen as transforming with respect to the local frame.
| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
offsetThe offset to translate by.
Transform2DThe translated matrix.
op_Equalitybool
public static bool operator ==(Transform2D left, Transform2D right);Returns true if the transforms are exactly equal.
Note: Due to floating-point precision errors, consider using
Transform2D.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
left | Transform2D | — |
right | Transform2D | — |
leftThe left transform.
rightThe right transform.
boolWhether or not the transforms are exactly equal.
op_Inequalitybool
public static bool operator !=(Transform2D left, Transform2D right);Returns true if the transforms are not equal.
Note: Due to floating-point precision errors, consider using
Transform2D.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
left | Transform2D | — |
right | Transform2D | — |
leftThe left transform.
rightThe right transform.
boolWhether or not the transforms are not equal.
op_Multiply7 overloads
public static Rect2 operator *(Rect2 rect, Transform2D transform);Returns a Rect2 transformed (multiplied) by the inverse transformation matrix,
under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection
is fine, scaling/skew is not).
rect * transform is equivalent to transform.Inverse() * rect. See Transform2D.Inverse.
For transforming by inverse of an affine transformation (e.g. with scaling) transform.AffineInverse() * rect can be used instead. See Transform2D.AffineInverse.
| Name | Type | Default |
|---|---|---|
rect | Rect2 | — |
transform | Transform2D | — |
rectA Rect2 to inversely transform.
transformThe transformation to apply.
Rect2The inversely transformed Rect2.
public static Rect2 operator *(Transform2D transform, Rect2 rect);Returns a Rect2 transformed (multiplied) by the transformation matrix.
| Name | Type | Default |
|---|---|---|
transform | Transform2D | — |
rect | Rect2 | — |
transformThe transformation to apply.
rectA Rect2 to transform.
Rect2The transformed Rect2.
public static Transform2D operator *(Transform2D left, Transform2D right);Composes transforms: left * right applies right first, then left. For a hierarchy this is the parent transform multiplied by the child transform.
| Name | Type | Default |
|---|---|---|
left | Transform2D | — |
right | Transform2D | — |
leftOuter transform, applied second.
rightInner transform, applied first.
Transform2DComposed transform left * right.
public static Vector2 operator *(Transform2D transform, Vector2 vector);Transforms a point by the basis and adds Origin. For a direction without translation use BasisXform.
| Name | Type | Default |
|---|---|---|
transform | Transform2D | — |
vector | Vector2 | — |
transformTransform; reversed order with Vector2 requires an orthonormal basis.
vectorPoint in the source coordinate system.
Vector2Point in the destination space, subject to this operator's basis requirements.
public static Vector2[] operator *(Transform2D transform, Vector2[] array);Returns a copy of the given Vector2[] transformed (multiplied) by the transformation matrix.
| Name | Type | Default |
|---|---|---|
transform | Transform2D | — |
array | Vector2[] | — |
transformThe transformation to apply.
arrayA Vector2[] to transform.
Vector2[]The transformed copy of the Vector2[].
public static Vector2 operator *(Vector2 vector, Transform2D transform);Inverse-transforms a point assuming an orthonormal basis. With scale or skew this operand order does not replace transform.AffineInverse() * vector.
| Name | Type | Default |
|---|---|---|
vector | Vector2 | — |
transform | Transform2D | — |
vectorPoint in the source coordinate system.
transformTransform; reversed order with Vector2 requires an orthonormal basis.
Vector2Point in the destination space, subject to this operator's basis requirements.
public static Vector2[] operator *(Vector2[] array, Transform2D transform);Returns a copy of the given Vector2[] transformed (multiplied) by the inverse transformation matrix,
under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection
is fine, scaling/skew is not).
array * transform is equivalent to transform.Inverse() * array. See Transform2D.Inverse.
For transforming by inverse of an affine transformation (e.g. with scaling) transform.AffineInverse() * array can be used instead. See Transform2D.AffineInverse.
| Name | Type | Default |
|---|---|---|
array | Vector2[] | — |
transform | Transform2D | — |
arrayA Vector2[] to inversely transform.
transformThe transformation to apply.
Vector2[]The inversely transformed copy of the Vector2[].
Fields and constants3
OriginField
public Vector2 Origin;Translation applied when transforming a point. BasisXform applies only the basis and does not add Origin.
XField
public Vector2 X;First basis column: the transformed local X axis. Does not include Origin translation.
YField
public Vector2 Y;Second basis column: the transformed local Y axis. In ordinary 2D coordinates positive Y points down.