Struct Transform2
A 2D spatial transform composed of a position (Position), an orientation (Rotation), and a uniform scale (Scale).
Transform2 converts between local space (relative to the transform's origin) and world space. The order of operations when going local → world is: scale, then rotate, then translate.
public readonly record struct Transform2 : IEquatable<Transform2>
- Implements
- Inherited Members
- Extension Methods
Examples
// Translate 5 m right, rotate 90° CCW, scale by 2
var t = new Transform2(LengthPoint2.FromMeters(5, 0), Direction2.FromDegrees(90), Ratio.FromDecimalFractions(2.0));
var world = t.Apply(LengthPoint2.FromMeters(1, 0)); // (5, 2)
Remarks
Math overview:
-
Apply(p)(local → world):w = Position + Scale × R(Rotation) × p -
ApplyInverse(w)(world → local):l = (1/Scale) × R(-Rotation) × (w - Position) -
Compose(child): applies child in the parent's local space, equivalent to evaluatingparent.Apply(child.Apply(p))for any pointp.
Constructors
Transform2(LengthPoint2, Direction2, Ratio)
Initialises a Transform2 with the given position, rotation, and scale.
public Transform2(LengthPoint2 position, Direction2 rotation, Ratio scale)
Parameters
positionLengthPoint2The world-space position.
rotationDirection2The orientation.
scaleRatioThe uniform scale factor.
Properties
Identity
The identity transform: no translation, no rotation, scale = 1.
Identity.Apply(p) == p for any point p.
public static Transform2 Identity { get; }
Property Value
Position
The world-space position of the transform's origin.
public LengthPoint2 Position { get; init; }
Property Value
Rotation
The orientation of the transform, applied after scale.
public Direction2 Rotation { get; init; }
Property Value
Scale
The uniform scale factor. 1.0 = no scaling.
public Ratio Scale { get; init; }
Property Value
- Ratio
Methods
Apply(LengthPoint2)
Transforms a point from local space to world space.
Order: scale → rotate → translate.
public LengthPoint2 Apply(LengthPoint2 localPoint)
Parameters
localPointLengthPoint2A point in this transform's local coordinate space.
Returns
- LengthPoint2
The equivalent world-space position.
Examples
var t = new Transform2(LengthPoint2.FromMeters(1, 0), Direction2.FromDegrees(90), Ratio.FromDecimalFractions(2.0));
var world = t.Apply(LengthPoint2.FromMeters(1, 0)); // (1, 2)
ApplyInverse(LengthPoint2)
Transforms a point from world space back to local space (the inverse of Apply(LengthPoint2)).
Order: un-translate → un-rotate → un-scale.
public LengthPoint2 ApplyInverse(LengthPoint2 worldPoint)
Parameters
worldPointLengthPoint2A point in world coordinate space.
Returns
- LengthPoint2
The equivalent local-space position.
Examples
var t = new Transform2(LengthPoint2.FromMeters(1, 0), Direction2.FromDegrees(90), Ratio.FromDecimalFractions(2.0));
var local = t.ApplyInverse(t.Apply(LengthPoint2.FromMeters(1, 0))); // back to (1, 0)
Compose(Transform2)
Composes this transform with child, returning a single combined
transform that is equivalent to applying child first, then this one.
result.Apply(p) == this.Apply(child.Apply(p)) for any point p.
public Transform2 Compose(Transform2 child)
Parameters
childTransform2The inner (child) transform to apply first.
Returns
- Transform2
A single Transform2 equivalent to
parent(child(p)).
Examples
var parent = new Transform2(LengthPoint2.FromMeters(2, 0), Direction2.Zero, Ratio.FromDecimalFractions(1.0));
var child = new Transform2(LengthPoint2.FromMeters(1, 0), Direction2.Zero, Ratio.FromDecimalFractions(1.0));
var combined = parent.Compose(child); // translate by (3, 0) total
Inverse()
Returns the inverse of this transform — applying the inverse undoes this transform.
this.Inverse().Apply(this.Apply(p)) ≈ p for any point p.
public Transform2 Inverse()
Returns
- Transform2
The inverse Transform2.
Examples
var t = new Transform2(LengthPoint2.FromMeters(3, 1), Direction2.FromDegrees(30), Ratio.FromDecimalFractions(1.5));
var inv = t.Inverse();
var p = LengthPoint2.FromMeters(5, 2);
// inv.Apply(t.Apply(p)) ≈ p
Lerp(Transform2, Transform2, double)
Linearly interpolates between two transforms.
Position is lerped component-wise; rotation is lerped along the shortest arc (via Lerp(Direction2, Direction2, double)); scale is lerped linearly.
public static Transform2 Lerp(Transform2 a, Transform2 b, double t)
Parameters
aTransform2The start transform.
bTransform2The end transform.
tdoubleInterpolation factor, typically in [0, 1].
Returns
- Transform2
A Transform2 interpolated between
aandb.
Examples
var a = new Transform2(LengthPoint2.Origin, Direction2.Zero, Ratio.FromDecimalFractions(1.0));
var b = new Transform2(LengthPoint2.FromMeters(10, 0), Direction2.North, Ratio.FromDecimalFractions(2.0));
var mid = Transform2.Lerp(a, b, 0.5); // (5, 0), 45°, 1.5×