Beispiel #1
0
        /// <summary>
        /// Gets the arc length of the arc in the interval [t0, t1].
        /// </summary>
        /// <remarks>
        /// This function calculates an integration for the first and the last curve pieces of the arc.
        /// Then adds the precalculated arc lengths for the curves in the middle.
        /// </remarks>
        /// <param name="t0">The start parameter in [0, 1].</param>
        /// <param name="t1">The end parameter in [0, 1].</param>
        /// <returns>The arc length.</returns>
        public float GetArcLength(float t0, float t1)
        {
            _UpdateLengths();

            if (t0 == t1)
            {
                return(0);
            }

            if (t0 > t1)
            {
                float tmp = t0;
                t0 = t1;
                t1 = tmp;
            }

            int curve0 = (int)(t0 * curveCount);
            int curve1 = t1 == 1 ? curveCount - 1 : (int)(t1 * curveCount);

            t0 = t0 * curveCount - curve0;
            t1 = t1 * curveCount - curve1;

            curve0 *= 3;
            curve1 *= 3;

            if (curve0 == curve1)
            {
                return(Bezier.Integrate(_points[curve0], _points[curve0 + 1], _points[curve0 + 2], _points[curve0 + 3], t0, t1));
            }
            else
            {
                float result = 0;

                result += Bezier.Integrate(_points[curve0], _points[curve0 + 1], _points[curve0 + 2], _points[curve0 + 3], t0, 1);

                for (int i = curve0 / 3 + 1; i < curve1 / 3; i++)
                {
                    result += _curveLengths[i];
                }

                result += Bezier.Integrate(_points[curve1], _points[curve1 + 1], _points[curve1 + 2], _points[curve1 + 3], 0, t1);

                return(result);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the length of the get curve.
        /// </summary>
        /// <param name="curveIndex">The curve index.</param>
        /// <returns>The curve length.</returns>
        private float _GetCurveLength(int curveIndex)
        {
            int i = curveIndex * 3;

            return(Bezier.Integrate(_points[i], _points[i + 1], _points[i + 2], _points[i + 3], 0, 1));
        }