Class CatmullRomSpline2
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
waypointsIReadOnlyList<LengthPoint2>The ordered waypoints. Must contain at least 2 points.
Exceptions
- ArgumentException
Thrown when
waypointscontains fewer than 2 elements.
Properties
Waypoints
Gets the waypoints that define this spline.
public IReadOnlyList<LengthPoint2> Waypoints { get; }
Property Value
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
tdoubleNormalized 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
tRatioNormalized parameter as a UnitsNet.Ratio (0–1).
Returns
- LengthPoint2
The interpolated world-space position.
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
tdoubleNormalized 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
tRatioNormalized parameter as a UnitsNet.Ratio (0–1).
Returns
- Direction2
The unit tangent direction at that point on the spline.
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
resolutionintSegments per spline segment. Must be ≥ 1. Defaults to 16.
Returns
- LengthPath2
A LengthPath2 approximating this spline.