Struct QuadraticBezier
Represents a quadratic Bézier curve defined by three control points.
public readonly struct QuadraticBezier : ICurve
- Implements
- Inherited Members
Remarks
A quadratic Bézier curve smoothly interpolates between P0 and P2. The curve is influenced by a single control point P1. Quadratic Béziers are widely used in vector graphics, font rendering, and easing functions.
Constructors
QuadraticBezier(Point, Point, Point)
Initializes a new quadratic Bézier curve with the specified control points.
public QuadraticBezier(Point p0, Point p1, Point p2)
Parameters
Fields
P0
The starting point of the curve.
public readonly Point P0
Field Value
P1
The control point that influences the curvature of the segment.
public readonly Point P1
Field Value
P2
The ending point of the curve.
public readonly Point P2
Field Value
Properties
this[NFloat]
Evaluates the point on the curve at the specified parameter.
public Point this[NFloat t] { get; }
Parameters
t
NFloat
Property Value
Methods
ClosestT(Point)
Finds the t
value where the curve is closest to target
.
Uses uniform sampling across 16 points.
public NFloat ClosestT(Point target)
Parameters
target
Point
Returns
ClosestT(Point, NFloat)
Finds the t
value where the curve is closest to target
.
Uses recursive ternary subdivision with the specified precision
.
public NFloat ClosestT(Point target, NFloat precision)
Parameters
Returns
Drag(NFloat, Vector)
public QuadraticBezier Drag(NFloat t, Vector delta)
Parameters
Returns
DragAt(Point, Vector)
Adjusts the control point so that the curve is moved near origin
by delta
.
Uses coarse sampling to find the closest point.
public QuadraticBezier DragAt(Point origin, Vector delta)
Parameters
Returns
DragAt(Point, Vector, NFloat)
Adjusts the control point so that the curve is moved near origin
by delta
.
Uses adaptive precision to locate the closest point.
public QuadraticBezier DragAt(Point origin, Vector delta, NFloat precision)
Parameters
Returns
Length()
Approximates the arc length using uniform sampling over 16 segments.
public NFloat Length()
Returns
- NFloat
The approximate total length of the curve.
Length(NFloat)
Approximates the arc length using recursive adaptive subdivision.
public NFloat Length(NFloat precision)
Parameters
precision
NFloatThe maximum allowed error for curve flatness.
Returns
Lerp(NFloat)
Evaluates the curve at parameter t
using De Casteljau’s algorithm.
public Point Lerp(NFloat t)
Parameters
t
NFloatA normalized parameter in the range [0, 1].
Returns
- Point
The interpolated point on the curve.
SplitIntoYMonotonicCurves()
Splits the current quadratic Bézier curve into two segments if it is not monotonic in the Y direction.
public MonotonicQuadraticBezier SplitIntoYMonotonicCurves()
Returns
- MonotonicQuadraticBezier
A MonotonicQuadraticBezier instance containing one or two sub-curves, each guaranteed to be monotonic in Y. If the curve is already Y-monotonic (i.e., has no vertical extrema within (0,1)), a single-segment result is returned.
Remarks
This method analyzes the derivative of the Y component of the curve to determine if a vertical extremum occurs within the curve's parameter domain. If a critical point is found in (0,1), the curve is split at that point to ensure each resulting segment is Y-monotonic. This is useful for scanline rasterization, tessellation, or other geometry processing that requires monotonic segments.
Subdivide(NFloat)
Subdivides this quadratic Bézier curve at parameter t, returning two curves.
public (QuadraticBezier, QuadraticBezier) Subdivide(NFloat t)
Parameters
t
NFloat
Returns
Tangent(NFloat)
Computes the tangent vector at parameter t
.
public Vector Tangent(NFloat t)
Parameters
t
NFloatA normalized parameter in the range [0, 1].
Returns
- Vector
The tangent vector at the specified point.
Operators
implicit operator QuadraticBezier((Point p0, Point p1, Point p2))
Converts a tuple of 3 points to a QuadraticBezier.
public static implicit operator QuadraticBezier((Point p0, Point p1, Point p2) value)
Parameters
Returns
implicit operator QuadraticBezier(QuadraticSpline)
Converts a QuadraticSpline to a QuadraticBezier.
public static implicit operator QuadraticBezier(QuadraticSpline spline)
Parameters
spline
QuadraticSpline