Table of Contents

Struct BezierCurve2

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

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

P0 LengthPoint2

Start point (curve passes through this at t = 0).

P1 LengthPoint2

First control point (tangent guide near start).

P2 LengthPoint2

Second control point (tangent guide near end).

P3 LengthPoint2

End 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

LengthPoint2

P1

First control point (tangent guide near start).

public LengthPoint2 P1 { get; init; }

Property Value

LengthPoint2

P2

Second control point (tangent guide near end).

public LengthPoint2 P2 { get; init; }

Property Value

LengthPoint2

P3

End point (curve passes through this at t = 1).

public LengthPoint2 P3 { get; init; }

Property Value

LengthPoint2

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

t double

Curve 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

t Ratio

Curve 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

distance Length

Arc-length distance from the start of the curve.

resolution int

Number 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

t double

Curve 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

t Ratio

Curve 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

distance Length

Arc-length distance from the start of the curve.

resolution int

Number 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

resolution int

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

Returns

LengthPath2

A LengthPath2 approximating this curve.

v0.7.0 ▼