Class CurveUtility
A collection of methods for extracting information about BezierCurve types.
Inherited Members
Namespace: UnityEngine.Splines
Assembly: Unity.Splines.dll
Syntax
public static class CurveUtility
Methods
ApproximateLength(BezierCurve)
Calculate the approximate length of a BezierCurve. This is less accurate than CalculateLength(BezierCurve, int), 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 |
|---|---|
| float | An estimate of the length of a curve. |
CalculateCurveLengths(BezierCurve, NativeArray<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, NativeArray<DistanceToInterpolation> lookupTable)
Parameters
| Type | Name | Description |
|---|---|---|
| BezierCurve | curve | The BezierCurve to create a distance to 't' lookup table for. |
| NativeArray<DistanceToInterpolation> | lookupTable | A pre-allocated native array to populate with distance to interpolation ratio data. |
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, int)
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(int).
Declaration
public static float CalculateLength(BezierCurve curve, int resolution = 30)
Parameters
| Type | Name | Description |
|---|---|---|
| BezierCurve | curve | The BezierCurve to calculate length. |
| int | resolution | The number of linear segments used to calculate the curve length. |
Returns
| Type | Description |
|---|---|
| float | The sum length of a collection of linear segments fitting this curve. |
See Also
EvaluateAcceleration(BezierCurve, float)
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. |
| float | 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, float)
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. |
| float | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
| Type | Description |
|---|---|
| float | A curvature value on the curve. |
EvaluatePosition(BezierCurve, float)
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. |
| float | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
| Type | Description |
|---|---|
| float3 | A position on the curve. |
EvaluateTangent(BezierCurve, float)
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. |
| float | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
| Type | Description |
|---|---|
| float3 | A tangent on the curve. |
GetDistanceToInterpolation(BezierCurve, float)
Gets the normalized interpolation, (t), that corresponds to a distance on a BezierCurve.
Declaration
public static float GetDistanceToInterpolation(BezierCurve curve, float distance)
Parameters
| Type | Name | Description |
|---|---|---|
| BezierCurve | curve | The BezierCurve to calculate the distance to interpolation ratio for. |
| float | distance | The curve-relative distance to convert to an interpolation ratio (also referred to as 't'). |
Returns
| Type | Description |
|---|---|
| float | Returns the normalized interpolation ratio associated to distance on the designated curve. |
Remarks
It is inefficient to call this method frequently. For better performance create a DistanceToInterpolation cache with CalculateCurveLengths(BezierCurve, DistanceToInterpolation[]) and use the overload of this method which accepts a lookup table.
GetDistanceToInterpolation<T>(T, float)
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. |
| float | distance | The curve-relative distance to convert to an interpolation ratio (also referred to as 't'). |
Returns
| Type | Description |
|---|---|
| float | The normalized interpolation ratio associated to distance on the designated curve. |
Type Parameters
| Name | Description |
|---|---|
| T | The collection type. |
GetNearestPoint(BezierCurve, Ray, int)
Gets the point on a BezierCurve nearest to a ray.
Declaration
public static float3 GetNearestPoint(BezierCurve curve, Ray ray, int resolution = 16)
Parameters
| Type | Name | Description |
|---|---|---|
| BezierCurve | curve | The BezierCurve to compare. |
| Ray | ray | The input ray. |
| int | resolution | The number of line segments on this curve that are rasterized when testing for the nearest point. A higher value is more accurate, but slower to calculate. |
Returns
| Type | Description |
|---|---|
| float3 | Returns the nearest position on the curve to a ray. |
GetNearestPoint(BezierCurve, Ray, out float3, out float, int)
Gets the point on a BezierCurve nearest to a ray.
Declaration
public static float GetNearestPoint(BezierCurve curve, Ray ray, out float3 position, out float interpolation, int resolution = 16)
Parameters
| Type | Name | Description |
|---|---|---|
| BezierCurve | curve | The BezierCurve to compare. |
| Ray | ray | The input ray. |
| float3 | position | The nearest position on the curve to a ray. |
| float | interpolation | The ratio from range 0 to 1 along the curve at which the nearest point is located. |
| int | resolution | The number of line segments that this curve will be rasterized to when testing for nearest point. A higher value will be more accurate, but slower to calculate. |
Returns
| Type | Description |
|---|---|
| float | The distance from ray to nearest point on a BezierCurve. |
Split(BezierCurve, float, 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. |
| float | 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. |