Class CurveUtility
A collection of methods for extracting information about BezierCurve types.
Namespace: UnityEngine.Splines
Syntax
public static class CurveUtility : object
Methods
ApproximateLength(BezierCurve)
Calculate the approximate length of a BezierCurve. This is less accurate than CalculateLength(BezierCurve, Int32), but can be significantly faster. Use this when accuracy is not paramount and the curve control points are changing frequently.
Declaration
public static float ApproximateLength(BezierCurve curve)
Parameters
Type | Name | Description |
---|---|---|
BezierCurve | curve | The BezierCurve to calculate length. |
Returns
Type | Description |
---|---|
Single | An estimate of the length of a curve. |
CalculateCurveLengths(BezierCurve, DistanceToInterpolation[])
Populate a pre-allocated lookupTable array with distance to 't' values. The number of table entries is dependent on the size of the passed lookupTable.
Declaration
public static void CalculateCurveLengths(BezierCurve curve, DistanceToInterpolation[] lookupTable)
Parameters
Type | Name | Description |
---|---|---|
BezierCurve | curve | The BezierCurve to create a distance to 't' lookup table for. |
DistanceToInterpolation[] | lookupTable | A pre-allocated array to populate with distance to interpolation ratio data. |
CalculateLength(BezierCurve, Int32)
Calculate the length of a BezierCurve by unrolling the curve into linear segments and summing the lengths of the lines. This is equivalent to accessing GetCurveLength(Int32).
Declaration
public static float CalculateLength(BezierCurve curve, int resolution = 30)
Parameters
Type | Name | Description |
---|---|---|
BezierCurve | curve | The BezierCurve to calculate length. |
Int32 | resolution | The number of linear segments used to calculate the curve length. |
Returns
Type | Description |
---|---|
Single | The sum length of a collection of linear segments fitting this curve. |
See Also
EvaluateAcceleration(BezierCurve, Single)
Given a bezier curve, return an interpolated acceleration at ratio t.
Declaration
public static float3 EvaluateAcceleration(BezierCurve curve, float t)
Parameters
Type | Name | Description |
---|---|---|
BezierCurve | curve | A cubic bezier curve. |
Single | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
Type | Description |
---|---|
float3 | An acceleration vector on the curve. |
EvaluateCurvature(BezierCurve, Single)
Given a bezier curve, return an interpolated curvature at ratio t.
Declaration
public static float EvaluateCurvature(BezierCurve curve, float t)
Parameters
Type | Name | Description |
---|---|---|
BezierCurve | curve | A cubic bezier curve. |
Single | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
Type | Description |
---|---|
Single | A curvature value on the curve. |
EvaluatePosition(BezierCurve, Single)
Given a bezier curve, return an interpolated position at ratio t.
Declaration
public static float3 EvaluatePosition(BezierCurve curve, float t)
Parameters
Type | Name | Description |
---|---|---|
BezierCurve | curve | A cubic bezier curve. |
Single | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
Type | Description |
---|---|
float3 | A position on the curve. |
EvaluateTangent(BezierCurve, Single)
Given a bezier curve, return an interpolated tangent at ratio t.
Declaration
public static float3 EvaluateTangent(BezierCurve curve, float t)
Parameters
Type | Name | Description |
---|---|---|
BezierCurve | curve | A cubic bezier curve. |
Single | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
Type | Description |
---|---|
float3 | A tangent on the curve. |
GetDistanceToInterpolation<T>(T, Single)
Return the normalized interpolation (t) corresponding to a distance on a BezierCurve. This method accepts a look-up table (referred to in code with acronym "LUT") that may be constructed using CalculateCurveLengths(BezierCurve, DistanceToInterpolation[]). The built-in Spline class implementations (Spline and NativeSpline) cache these look-up tables internally.
Declaration
public static float GetDistanceToInterpolation<T>(T lut, float distance)
where T : IReadOnlyList<DistanceToInterpolation>
Parameters
Type | Name | Description |
---|---|---|
T | lut | A look-up table of distance to 't' values. See CalculateCurveLengths(BezierCurve, DistanceToInterpolation[]) for creating this collection. |
Single | distance | The curve-relative distance to convert to an interpolation ratio (also referred to as 't'). |
Returns
Type | Description |
---|---|
Single | The normalized interpolation ratio associated to distance on the designated curve. |
Type Parameters
Name | Description |
---|---|
T | The collection type. |
Split(BezierCurve, Single, out BezierCurve, out BezierCurve)
Decompose a curve into two smaller curves matching the source curve.
Declaration
public static void Split(BezierCurve curve, float t, out BezierCurve left, out BezierCurve right)
Parameters
Type | Name | Description |
---|---|---|
BezierCurve | curve | The source curve. |
Single | t | A mid-point on the source curve defining where the two smaller curves control points meet. |
BezierCurve | left | A curve from the source curve first control point to the mid-point, matching the curvature of the source curve. |
BezierCurve | right | A curve from the mid-point to the source curve fourth control point, matching the curvature of the source curve. |