docs.unity3d.com
    Show / Hide Table of Contents

    Class CurveUtility

    A collection of methods for extracting information about BezierCurve types.

    Inheritance
    Object
    CurveUtility
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: UnityEngine.Splines
    Syntax
    public static class CurveUtility

    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
    ApproximateLength(BezierCurve)

    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(BezierCurve, Single)

    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.

    Single distance

    The curve-relative distance to convert to an interpolation ratio (also referred to as 't').

    Returns
    Type Description
    Single

    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, 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.

    GetNearestPoint(BezierCurve, Ray, Int32)

    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.

    Int32 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 Single, Int32)

    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.

    Single interpolation

    The ratio from range 0 to 1 along the curve at which the nearest point is located.

    Int32 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
    Single

    The distance from ray to nearest point on a BezierCurve.

    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.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023