Struct CubicSpline
Represents a 4-point spline segment using Catmull–Rom interpolation. The curve interpolates smoothly between P1 and P2.
public readonly struct CubicSpline : ICurve
- Implements
- Inherited Members
Remarks
Catmull–Rom splines are useful for generating smooth curves through a sequence of points with minimal configuration. This implementation produces a C¹-continuous cubic curve, influenced by neighboring control points P0 and P3. The segment can also be converted into a CubicBezier for drawing or compatibility.
Constructors
CubicSpline(Point, Point, Point, Point)
Initializes a new Catmull–Rom spline segment from four control points.
public CubicSpline(Point p0, Point p1, Point p2, Point p3)
Parameters
Fields
P0
The control point before the start of the curve.
public readonly Point P0
Field Value
P1
The starting point of the interpolated segment.
public readonly Point P1
Field Value
P2
The ending point of the interpolated segment.
public readonly Point P2
Field Value
P3
The control point after the end of the curve.
public readonly Point P3
Field Value
Properties
this[NFloat]
Indexer-style access to evaluate the curve at a given parameter.
public Point this[NFloat t] { get; }
Parameters
t
NFloat
Property Value
Methods
Length()
Approximates the arc length of the curve using uniform sampling with 16 segments.
public NFloat Length()
Returns
Length(NFloat)
Approximates the arc length using recursive adaptive subdivision.
public NFloat Length(NFloat precision)
Parameters
precision
NFloatThe tolerance used to decide subdivision depth.
Returns
Lerp(NFloat)
Evaluates the point on the spline at the given parameter t
using the Catmull–Rom formula.
public Point Lerp(NFloat t)
Parameters
t
NFloatA normalized parameter in the range [0, 1].
Returns
Tangent(NFloat)
Computes the tangent vector at parameter t
by differentiating the spline.
public Vector Tangent(NFloat t)
Parameters
t
NFloatA normalized parameter in the range [0, 1].
Returns
Operators
implicit operator CubicBezier(CubicSpline)
Converts this Catmull–Rom spline segment to an equivalent CubicBezier. The resulting curve interpolates between P1 and P2.
public static implicit operator CubicBezier(CubicSpline s)