Beispiel #1
0
        /// <summary>
        ///   Spherically interpolates between the two passed vectors.
        /// </summary>
        /// <param name="from">First point of the arc.</param>
        /// <param name="to">Last point of the arc.</param>
        /// <param name="step">Interpolation parameter.</param>
        /// <returns>
        ///   Value of <paramref name="step" /> along the path along the line segment in the plane.
        /// </returns>
        public static Vector2F Slerp(Vector2F from, Vector2F to, float step)
        {
            if (step == 0)
            {
                return(from);
            }

            if (from == to || step == 1)
            {
                return(to);
            }

            float theta = MathUtils.ACos(Dot(from, to));

            if (theta == 0)
            {
                return(to);
            }

            float sinTheta = MathUtils.Sin(theta);

            if (sinTheta == 0.0f)
            {
                return(to);
            }

            return(MathUtils.Sin((1 - step) * theta) / sinTheta * from + MathUtils.Sin(step * theta) / sinTheta * to);
        }