예제 #1
0
        /// <summary>
        /// Interpolates between two unit complex numbers, using spherical linear interpolation.
        /// </summary>
        /// <param name="start">Start complex number.</param>
        /// <param name="end">End complex number.</param>
        /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
        /// <returns>The spherical linear interpolation of the two complex numbers.</returns>
        ///  <remarks>
        /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
        /// </remarks>
        public Complex Slerp(Complex start, Complex end, double amount)
        {
            double cosTheta = Dot(start, end);

            //Cannot use slerp, use lerp instead
            if (Functions.Abs(cosTheta) - 1.0 < double.Epsilon)
            {
                return(Lerp(start, end, amount));
            }

            double theta    = Functions.Acos(cosTheta);
            double sinTheta = Functions.Sin(theta);
            double t0       = Functions.Sin((1.0 - amount) * theta) / sinTheta;
            double t1       = Functions.Sin(amount * theta) / sinTheta;

            return(t0 * start + t1 * end);
        }