Table of Contents

Class CatmullRomSpline2

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

A Catmull-Rom spline defined by an ordered sequence of LengthPoint2 waypoints that the curve passes through.

Unlike a Bézier curve, a Catmull-Rom spline passes through every supplied waypoint. This makes it well-suited for game AI paths, camera rails, and any use-case where control points are intended as actual pass-through positions.

Evaluate the spline with Evaluate(Ratio) using a normalized parameter t ∈ [0, 1] that maps uniformly across all segments. Use ToPath(int) to convert to an arc-length parameterised LengthPath2 for distance-based traversal.

public sealed class CatmullRomSpline2
Inheritance
CatmullRomSpline2
Inherited Members

Constructors

CatmullRomSpline2(IReadOnlyList<LengthPoint2>)

Creates a CatmullRomSpline2 from a sequence of waypoints. The spline passes through all supplied waypoints.

public CatmullRomSpline2(IReadOnlyList<LengthPoint2> waypoints)

Parameters

waypoints IReadOnlyList<LengthPoint2>

The ordered waypoints. Must contain at least 2 points.

Exceptions

ArgumentException

Thrown when waypoints contains fewer than 2 elements.

Properties

Waypoints

Gets the waypoints that define this spline.

public IReadOnlyList<LengthPoint2> Waypoints { get; }

Property Value

IReadOnlyList<LengthPoint2>

Methods

Evaluate(double)

Returns the world-space position on the spline at normalized parameter t.

t = 0 returns the first waypoint; t = 1 returns the last waypoint. Each waypoint i is reached at t = i / (n-1) where n is the number of waypoints. Values outside [0, 1] are clamped.

public LengthPoint2 Evaluate(double t)

Parameters

t double

Normalized parameter in [0, 1].

Returns

LengthPoint2

The interpolated world-space position.

Evaluate(Ratio)

Returns the world-space position on the spline at normalized parameter t.

t = 0 returns the first waypoint; t = 1 returns the last waypoint. Each waypoint i is reached at t = i / (n-1) where n is the number of waypoints. Values outside [0, 1] are clamped.

public LengthPoint2 Evaluate(Ratio t)

Parameters

t Ratio

Normalized parameter as a UnitsNet.Ratio (0–1).

Returns

LengthPoint2

The interpolated world-space position.

EvaluateAtLength(Length, int)

Returns the world-space position at a given arc-length distance along the spline, parameterised by actual travelled distance rather than the uniform t ∈ [0, 1] parameter.

public LengthPoint2 EvaluateAtLength(Length distance, int resolution = 16)

Parameters

distance Length

Arc-length distance from the start of the spline.

resolution int

Segments per spline segment used to approximate the path. Higher values give more accurate arc-length mapping. Defaults to 16.

Returns

LengthPoint2

The world-space position at the given arc-length distance.

Remarks

Distances outside [Length.Zero, path.TotalLength] are clamped. This method builds a LengthPath2 on every call. For hot-path use (e.g. every frame), cache ToPath(int) and call Evaluate(Length) directly.

var spline = new CatmullRomSpline2(new[] { LengthPoint2.FromMeters(0, 0), LengthPoint2.FromMeters(5, 5), LengthPoint2.FromMeters(10, 0) });
var pos = spline.EvaluateAtLength(Length.FromMeters(5));

TangentAt(double)

Returns the forward direction (tangent) of the spline at normalized parameter t. Values outside [0, 1] are clamped.

public Direction2 TangentAt(double t)

Parameters

t double

Normalized parameter in [0, 1].

Returns

Direction2

The unit tangent direction at that point on the spline.

TangentAt(Ratio)

Returns the forward direction (tangent) of the spline at normalized parameter t. Values outside [0, 1] are clamped.

public Direction2 TangentAt(Ratio t)

Parameters

t Ratio

Normalized parameter as a UnitsNet.Ratio (0–1).

Returns

Direction2

The unit tangent direction at that point on the spline.

TangentAtLength(Length, int)

Returns the forward direction at a given arc-length distance along the spline.

public Direction2 TangentAtLength(Length distance, int resolution = 16)

Parameters

distance Length

Arc-length distance from the start of the spline.

resolution int

Segments per spline segment used to approximate the path. Defaults to 16.

Returns

Direction2

The normalised forward direction at the given arc-length distance.

Remarks

Distances outside [Length.Zero, path.TotalLength] are clamped. For hot-path use, cache ToPath(int) and call TangentAt(Length) directly.

var spline = new CatmullRomSpline2(new[] { LengthPoint2.FromMeters(0, 0), LengthPoint2.FromMeters(5, 5), LengthPoint2.FromMeters(10, 0) });
var dir = spline.TangentAtLength(Length.FromMeters(5));

ToPath(int)

Returns a LengthPath2 that approximates this spline as a polyline with resolution segments per spline segment.

public LengthPath2 ToPath(int resolution = 16)

Parameters

resolution int

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

Returns

LengthPath2

A LengthPath2 approximating this spline.

v0.7.0 ▼