Class CurveUtility
A collection of methods for extracting information about Bezier
Inherited Members
Namespace: UnityEngine .Splines
Assembly: Unity.Splines.dll
Syntax
public static class CurveUtility
Methods
ApproximateLength(BezierCurve)
Calculate the approximate length of a Bezier
Declaration
public static float ApproximateLength(BezierCurve curve)
Parameters
Type | Name | Description |
---|---|---|
Bezier |
curve | The Bezier |
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 |
---|---|---|
Bezier |
curve | The Bezier |
Native |
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 |
---|---|---|
Bezier |
curve | The Bezier |
Distance |
lookupTable | A pre-allocated array to populate with distance to interpolation ratio data. |
CalculateLength(BezierCurve, int)
Calculate the length of a Bezier
Declaration
public static float CalculateLength(BezierCurve curve, int resolution = 30)
Parameters
Type | Name | Description |
---|---|---|
Bezier |
curve | The Bezier |
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 |
---|---|---|
Bezier |
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 |
---|---|---|
Bezier |
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 |
---|---|---|
Bezier |
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 |
---|---|---|
Bezier |
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 Bezier
Declaration
public static float GetDistanceToInterpolation(BezierCurve curve, float distance)
Parameters
Type | Name | Description |
---|---|---|
Bezier |
curve | The Bezier |
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
Distance
GetDistanceToInterpolation<T>(T, float)
Return the normalized interpolation (t) corresponding to a distance on a Bezier
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 Calculate |
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 Bezier
Declaration
public static float3 GetNearestPoint(BezierCurve curve, Ray ray, int resolution = 16)
Parameters
Type | Name | Description |
---|---|---|
Bezier |
curve | The Bezier |
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 Bezier
Declaration
public static float GetNearestPoint(BezierCurve curve, Ray ray, out float3 position, out float interpolation, int resolution = 16)
Parameters
Type | Name | Description |
---|---|---|
Bezier |
curve | The Bezier |
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 Bezier |
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 |
---|---|---|
Bezier |
curve | The source curve. |
float | t | A mid-point on the source curve defining where the two smaller curves control points meet. |
Bezier |
left | A curve from the source curve first control point to the mid-point, matching the curvature of the source curve. |
Bezier |
right | A curve from the mid-point to the source curve fourth control point, matching the curvature of the source curve. |