Table of Contents

Struct LengthPoint2

Namespace
Thunder.UnitsNET.Vectors
Assembly
Thunder.UnitsNET.Vectors.dll

A 2D point whose components represent a position in length-unit space, each expressed as a UnitsNet.Length (e.g. metres, feet, kilometres).

Use this type to represent where something is — a world-space coordinate, a shape vertex, a contact point. It is intentionally distinct from LengthVector2, which represents a displacement (how far something has moved). This distinction prevents accidental arithmetic that would produce nonsensical results, such as adding two positions together.

Allowed algebra:

  • LengthPoint2 + LengthVector2 → LengthPoint2 (translate a point)
  • LengthPoint2 - LengthVector2 → LengthPoint2 (reverse translate)
  • LengthPoint2 - LengthPoint2 → LengthVector2 (displacement between points)

To convert between types explicitly, use ToVector() or ToPoint().

public readonly record struct LengthPoint2 : IEquatable<LengthPoint2>
Implements
Inherited Members
Extension Methods

Examples

// A position 3 metres right and 4 metres up from the origin
var position = new LengthPoint2(Length.FromMeters(3), Length.FromMeters(4));

// Convenience factory — avoids repeating Length.FromMeters
var same = LengthPoint2.FromMeters(3, 4);

// Translate a point by a displacement vector
var target = position + LengthVector2.FromMeters(1, 0); // (4, 4)

// Displacement between two points
var displacement = target - position; // LengthVector2(1, 0)

Constructors

LengthPoint2(Length, Length)

A 2D point whose components represent a position in length-unit space, each expressed as a UnitsNet.Length (e.g. metres, feet, kilometres).

Use this type to represent where something is — a world-space coordinate, a shape vertex, a contact point. It is intentionally distinct from LengthVector2, which represents a displacement (how far something has moved). This distinction prevents accidental arithmetic that would produce nonsensical results, such as adding two positions together.

Allowed algebra:

  • LengthPoint2 + LengthVector2 → LengthPoint2 (translate a point)
  • LengthPoint2 - LengthVector2 → LengthPoint2 (reverse translate)
  • LengthPoint2 - LengthPoint2 → LengthVector2 (displacement between points)

To convert between types explicitly, use ToVector() or ToPoint().

public LengthPoint2(Length X, Length Y)

Parameters

X Length
Y Length

Examples

// A position 3 metres right and 4 metres up from the origin
var position = new LengthPoint2(Length.FromMeters(3), Length.FromMeters(4));

// Convenience factory — avoids repeating Length.FromMeters
var same = LengthPoint2.FromMeters(3, 4);

// Translate a point by a displacement vector
var target = position + LengthVector2.FromMeters(1, 0); // (4, 4)

// Displacement between two points
var displacement = target - position; // LengthVector2(1, 0)

Properties

Origin

The origin — the point at (0, 0) in world space.

public static LengthPoint2 Origin { get; }

Property Value

LengthPoint2

X

public Length X { get; init; }

Property Value

Length

Y

public Length Y { get; init; }

Property Value

Length

Methods

DistanceTo(LengthPoint2)

Returns the straight-line Euclidean distance between this point and other.

public Length DistanceTo(LengthPoint2 other)

Parameters

other LengthPoint2

The other point.

Returns

Length

The non-negative distance between the two points.

Examples

var a    = LengthPoint2.Origin;
var b    = LengthPoint2.FromMeters(3, 4);
Length d = a.DistanceTo(b); // 5 m — classic 3-4-5 triangle

FromMeters(double, double)

Creates a LengthPoint2 from raw metre values — a convenience factory that avoids repeating Length.FromMeters(...) for each component.

public static LengthPoint2 FromMeters(double x, double y)

Parameters

x double

The X component in metres.

y double

The Y component in metres.

Returns

LengthPoint2

A LengthPoint2 at the given metre coordinates.

Examples

var a = new LengthPoint2(Length.FromMeters(3), Length.FromMeters(4));
var b = LengthPoint2.FromMeters(3, 4); // identical

Lerp(LengthPoint2, double)

Linearly interpolates from this point toward other.

public LengthPoint2 Lerp(LengthPoint2 other, double t)

Parameters

other LengthPoint2

The end point.

t double

Interpolation factor. Values outside [0, 1] extrapolate.

Returns

LengthPoint2

The interpolated point.

Examples

var a   = LengthPoint2.FromMeters(0, 0);
var b   = LengthPoint2.FromMeters(10, 0);
var mid = a.Lerp(b, 0.5); // (5, 0)

Lerp(LengthPoint2, LengthPoint2, double)

Linearly interpolates between two points.

public static LengthPoint2 Lerp(LengthPoint2 a, LengthPoint2 b, double t)

Parameters

a LengthPoint2

The start point (returned when t is 0).

b LengthPoint2

The end point (returned when t is 1).

t double

Interpolation factor. Values outside [0, 1] extrapolate.

Returns

LengthPoint2

The interpolated point.

Examples

var a    = LengthPoint2.FromMeters(0, 0);
var b    = LengthPoint2.FromMeters(10, 20);
var mid  = LengthPoint2.Lerp(a, b, 0.5); // (5, 10)

ToVector()

Converts this point to a LengthVector2 with the same components.

This is an explicit escape hatch for cases where you genuinely need to treat a position as a displacement — for example, to compute a direction from the origin. Prefer the typed algebra operators where possible.

public LengthVector2 ToVector()

Returns

LengthVector2

A LengthVector2 with the same X and Y values.

Examples

var point  = LengthPoint2.FromMeters(3, 4);
var vector = point.ToVector(); // LengthVector2(3 m, 4 m)

Operators

operator +(LengthPoint2, LengthVector2)

Translates this point by a displacement vector, returning a new point.

public static LengthPoint2 operator +(LengthPoint2 point, LengthVector2 vector)

Parameters

point LengthPoint2

The starting position.

vector LengthVector2

The displacement to apply.

Returns

LengthPoint2

The point after translation.

Examples

var start  = LengthPoint2.FromMeters(1, 2);
var offset = LengthVector2.FromMeters(3, 4);
var end    = start + offset; // (4, 6)

operator -(LengthPoint2, LengthPoint2)

Returns the displacement vector from b to a.

public static LengthVector2 operator -(LengthPoint2 a, LengthPoint2 b)

Parameters

a LengthPoint2

The target point.

b LengthPoint2

The source point.

Returns

LengthVector2

The LengthVector2 that, when added to b, produces a.

Examples

var a          = LengthPoint2.FromMeters(5, 7);
var b          = LengthPoint2.FromMeters(2, 3);
var delta      = a - b; // LengthVector2(3, 4)
var roundTrip  = b + delta; // back to (5, 7)

operator -(LengthPoint2, LengthVector2)

Reverse-translates this point by a displacement vector, returning a new point.

public static LengthPoint2 operator -(LengthPoint2 point, LengthVector2 vector)

Parameters

point LengthPoint2

The starting position.

vector LengthVector2

The displacement to reverse-apply.

Returns

LengthPoint2

The point after reverse translation.

Examples

var end    = LengthPoint2.FromMeters(4, 6);
var offset = LengthVector2.FromMeters(3, 4);
var start  = end - offset; // (1, 2)
v0.7.0 ▼