Table of Contents

Class LengthPath2

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

An arc-length parameterised polyline defined by a sequence of LengthPoint2 waypoints.

Use Evaluate(Length) to convert a scalar arc-length distance into a world-space position, and TangentAt(Length) to get the forward direction at that point.

public sealed class LengthPath2
Inheritance
LengthPath2
Inherited Members

Constructors

LengthPath2(IReadOnlyList<LengthPoint2>)

Creates a LengthPath2 from a sequence of world-space waypoints. The arc-length table is computed once at construction.

public LengthPath2(IReadOnlyList<LengthPoint2> points)

Parameters

points IReadOnlyList<LengthPoint2>

The ordered waypoints that define the path. Must contain at least 2 points.

Exceptions

ArgumentException

Thrown when points contains fewer than 2 elements.

Properties

Points

Gets the ordered waypoints that define this path.

public IReadOnlyList<LengthPoint2> Points { get; }

Property Value

IReadOnlyList<LengthPoint2>

TotalLength

Gets the total arc length of the path from the first to the last waypoint.

public Length TotalLength { get; }

Property Value

Length

Methods

Evaluate(Length)

Returns the world-space position at the given arc-length distance. Distances outside [0, TotalLength] are clamped.

public LengthPoint2 Evaluate(Length distance)

Parameters

distance Length

The arc-length distance from the path start.

Returns

LengthPoint2

The interpolated world-space position.

FromArc(Arc2, int)

Creates a LengthPath2 that approximates an Arc2 as a polyline with resolution + 1 evenly-spaced sample points.

public static LengthPath2 FromArc(Arc2 arc, int resolution = 32)

Parameters

arc Arc2

The arc to approximate.

resolution int

Number of segments. Must be ≥ 1. Defaults to 32.

Returns

LengthPath2

A LengthPath2 approximating the arc.

Remarks

Accuracy improves with higher resolution. At 32 segments a unit-radius semicircle is within ~0.05 m of its true arc length. Mirror of FromBezier(LengthPoint2, LengthPoint2, LengthPoint2, LengthPoint2, int) and FromCatmullRom(IReadOnlyList<LengthPoint2>, int) in sampling strategy.

var arc = new Arc2(new Circle2(LengthPoint2.FromMeters(0, 0), Length.FromMeters(5)), Direction2.East, Angle.FromDegrees(180));
var path = LengthPath2.FromArc(arc, 32);
var midpoint = path.Evaluate(path.TotalLength / 2);

FromBezier(LengthPoint2, LengthPoint2, LengthPoint2, LengthPoint2, int)

Creates a LengthPath2 that approximates a cubic Bézier curve as a polyline with resolution + 1 uniformly-spaced waypoints. The path is guaranteed to pass through p0 (t=0) and p3 (t=1).

public static LengthPath2 FromBezier(LengthPoint2 p0, LengthPoint2 p1, LengthPoint2 p2, LengthPoint2 p3, int resolution = 64)

Parameters

p0 LengthPoint2

Start point.

p1 LengthPoint2

First control point.

p2 LengthPoint2

Second control point.

p3 LengthPoint2

End point.

resolution int

Number of segments. Must be ≥ 1. Defaults to 64.

Returns

LengthPath2

A LengthPath2 approximating the cubic Bézier curve.

FromCatmullRom(IReadOnlyList<LengthPoint2>, int)

Creates a LengthPath2 that approximates a Catmull-Rom spline as a polyline. The spline passes through all supplied waypoints.

public static LengthPath2 FromCatmullRom(IReadOnlyList<LengthPoint2> waypoints, int resolution = 16)

Parameters

waypoints IReadOnlyList<LengthPoint2>

The ordered waypoints. Must contain at least 2 points.

resolution int

Segments per spline segment. Must be ≥ 1. Defaults to 16.

Returns

LengthPath2

A LengthPath2 approximating the Catmull-Rom spline.

Project(LengthPoint2)

Returns the arc-length distance along the path of the point nearest to worldPoint. O(n) in the number of segments.

public Length Project(LengthPoint2 worldPoint)

Parameters

worldPoint LengthPoint2

The world-space query point.

Returns

Length

Arc-length distance of the nearest point on the path.

Reverse()

Returns a new LengthPath2 with the waypoints in reverse order.

public LengthPath2 Reverse()

Returns

LengthPath2

A new path traversed in reverse.

SegmentAt(Length)

Returns the LengthSegment2 that contains the given arc-length distance. Distances outside [0, TotalLength] are clamped to the first or last segment respectively.

public LengthSegment2 SegmentAt(Length distance)

Parameters

distance Length

The arc-length distance from the path start.

Returns

LengthSegment2

The segment that spans that distance on the path.

TangentAt(Length)

Returns the forward direction (tangent) of the path at the given arc-length distance. Distances outside [0, TotalLength] are clamped; the direction of the nearest endpoint segment is returned.

public Direction2 TangentAt(Length distance)

Parameters

distance Length

The arc-length distance from the path start.

Returns

Direction2

The unit forward direction at that point on the path.

v0.7.0 ▼