Struct BezierCurve2
A cubic Bézier curve defined by four LengthPoint2 control points.
The curve passes through P0 at t = 0 and P3 at
t = 1. P1 and P2 are tangent guides — the curve is
attracted to them but does not (in general) pass through them.
Use Evaluate(Ratio) for an exact position at a given curve parameter, and ToPath(int) to convert to an arc-length parameterised LengthPath2 for distance-based traversal.
public readonly record struct BezierCurve2 : IEquatable<BezierCurve2>
- Implements
- Inherited Members
Constructors
BezierCurve2(LengthPoint2, LengthPoint2, LengthPoint2, LengthPoint2)
A cubic Bézier curve defined by four LengthPoint2 control points.
The curve passes through P0 at t = 0 and P3 at
t = 1. P1 and P2 are tangent guides — the curve is
attracted to them but does not (in general) pass through them.
Use Evaluate(Ratio) for an exact position at a given curve parameter, and ToPath(int) to convert to an arc-length parameterised LengthPath2 for distance-based traversal.
public BezierCurve2(LengthPoint2 P0, LengthPoint2 P1, LengthPoint2 P2, LengthPoint2 P3)
Parameters
P0LengthPoint2Start point (curve passes through this at t = 0).
P1LengthPoint2First control point (tangent guide near start).
P2LengthPoint2Second control point (tangent guide near end).
P3LengthPoint2End point (curve passes through this at t = 1).
Properties
P0
Start point (curve passes through this at t = 0).
public LengthPoint2 P0 { get; init; }
Property Value
P1
First control point (tangent guide near start).
public LengthPoint2 P1 { get; init; }
Property Value
P2
Second control point (tangent guide near end).
public LengthPoint2 P2 { get; init; }
Property Value
P3
End point (curve passes through this at t = 1).
public LengthPoint2 P3 { get; init; }
Property Value
Methods
Evaluate(double)
Returns the world-space position on the curve at parameter t.
t = 0 returns P0; t = 1 returns
P3. Values outside [0, 1] extrapolate beyond the endpoints.
public LengthPoint2 Evaluate(double t)
Parameters
tdoubleCurve parameter in [0, 1].
Returns
- LengthPoint2
The interpolated world-space position.
Evaluate(Ratio)
Returns the world-space position on the curve at parameter t.
t = 0 returns P0; t = 1 returns
P3. Values outside [0, 1] extrapolate beyond the endpoints.
public LengthPoint2 Evaluate(Ratio t)
Parameters
tRatioCurve parameter as a UnitsNet.Ratio (normalized 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 curve, parameterised by actual travelled distance rather than the uniform
t ∈ [0, 1] parameter.
public LengthPoint2 EvaluateAtLength(Length distance, int resolution = 64)
Parameters
distanceLengthArc-length distance from the start of the curve.
resolutionintNumber of polyline segments used to approximate the curve. Higher values give more accurate arc-length mapping at the cost of more computation. Defaults to 64.
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 curve = new BezierCurve2(LengthPoint2.FromMeters(0, 0), LengthPoint2.FromMeters(3, 3), LengthPoint2.FromMeters(7, 3), LengthPoint2.FromMeters(10, 0));
var pos = curve.EvaluateAtLength(Length.FromMeters(5));
TangentAt(double)
Returns the forward direction (tangent) of the curve at parameter t.
public Direction2 TangentAt(double t)
Parameters
tdoubleCurve parameter in [0, 1].
Returns
- Direction2
The unit tangent direction at that point on the curve.
TangentAt(Ratio)
Returns the forward direction (tangent) of the curve at parameter t.
public Direction2 TangentAt(Ratio t)
Parameters
tRatioCurve parameter as a UnitsNet.Ratio (normalized 0–1).
Returns
- Direction2
The unit tangent direction at that point on the curve.
TangentAtLength(Length, int)
Returns the forward direction at a given arc-length distance
along the curve.
public Direction2 TangentAtLength(Length distance, int resolution = 64)
Parameters
distanceLengthArc-length distance from the start of the curve.
resolutionintNumber of polyline segments used to approximate the curve. Defaults to 64.
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 curve = new BezierCurve2(LengthPoint2.FromMeters(0, 0), LengthPoint2.FromMeters(3, 3), LengthPoint2.FromMeters(7, 3), LengthPoint2.FromMeters(10, 0));
var dir = curve.TangentAtLength(Length.FromMeters(5));
ToPath(int)
Returns a LengthPath2 that approximates this curve as a polyline
with resolution + 1 uniformly-spaced waypoints.
public LengthPath2 ToPath(int resolution = 64)
Parameters
resolutionintNumber of segments. Must be ≥ 1. Defaults to 64.
Returns
- LengthPath2
A LengthPath2 approximating this curve.