BezierCurves.BezierCurve3D.GetApproximateLengthOfCubicCurve C# (CSharp) Method

GetApproximateLengthOfCubicCurve() public static method

public static GetApproximateLengthOfCubicCurve ( Vector3 startPosition, Vector3 endPosition, Vector3 startTangent, Vector3 endTangent, int sampling ) : float
startPosition UnityEngine.Vector3
endPosition UnityEngine.Vector3
startTangent UnityEngine.Vector3
endTangent UnityEngine.Vector3
sampling int
return float
        public static float GetApproximateLengthOfCubicCurve(Vector3 startPosition, Vector3 endPosition, Vector3 startTangent, Vector3 endTangent, int sampling)
        {
            float length = 0f;
            Vector3 fromPoint = GetPointOnCubicCurve(0f, startPosition, endPosition, startTangent, endTangent);

            for (int i = 0; i < sampling; i++)
            {
                float time = (i + 1) / (float)sampling;
                Vector3 toPoint = GetPointOnCubicCurve(time, startPosition, endPosition, startTangent, endTangent);
                length += Vector3.Distance(fromPoint, toPoint);
                fromPoint = toPoint;
            }

            return length;
        }

Same methods

BezierCurve3D::GetApproximateLengthOfCubicCurve ( BezierPoint3D startPoint, BezierPoint3D endPoint, int sampling ) : float

Usage Example

Example #1
0
        public float GetApproximateLength()
        {
            float length           = 0;
            int   subCurveSampling = (this.Sampling / (this.KeyPointsCount - 1)) + 1;

            for (int i = 0; i < this.KeyPointsCount - 1; i++)
            {
                length += BezierCurve3D.GetApproximateLengthOfCubicCurve(this.KeyPoints[i], this.KeyPoints[i + 1], subCurveSampling);
            }

            return(length);
        }
All Usage Examples Of BezierCurves.BezierCurve3D::GetApproximateLengthOfCubicCurve