Esempio n. 1
0
        /// <summary>
        /// Calculates the logarithm of a given quaternion.
        /// </summary>
        /// <param name="a">A <see cref="QuaternionD"/> instance.</param>
        /// <returns>The quaternion's logarithm.</returns>
        public static QuaternionD Log(QuaternionD a)
        {
            QuaternionD result = new QuaternionD(0, 0, 0, 0);

            if (MathFunctions.Abs(a.W) < 1.0)
            {
                double angle = System.Math.Acos(a.W);
                double sin   = System.Math.Sin(angle);

                if (MathFunctions.Abs(sin) >= 0)
                {
                    double coeff = angle / sin;
                    result.X = coeff * a.X;
                    result.Y = coeff * a.Y;
                    result.Z = coeff * a.Z;
                }
                else
                {
                    result.X = a.X;
                    result.Y = a.Y;
                    result.Z = a.Z;
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates the logarithm of a given quaternion.
        /// </summary>
        /// <param name="a">A <see cref="QuaternionF"/> instance.</param>
        /// <returns>The quaternion's logarithm.</returns>
        public static QuaternionF Log(QuaternionF a)
        {
            QuaternionF result = new QuaternionF(0.0f, 0.0f, 0.0f, 0.0f);

            if (MathFunctions.Abs(a.W) < 1.0f)
            {
                float angle = (float)System.Math.Acos(a.W);
                float sin   = (float)System.Math.Sin(angle);

                if (MathFunctions.Abs(sin) >= 0.0f)
                {
                    float coeff = angle / sin;
                    result.X = coeff * a.X;
                    result.Y = coeff * a.Y;
                    result.Z = coeff * a.Z;
                }
                else
                {
                    result.X = a.X;
                    result.Y = a.Y;
                    result.Z = a.Z;
                }
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Calculates the exponent of a quaternion.
        /// </summary>
        /// <param name="a">A <see cref="QuaternionD"/> instance.</param>
        /// <returns>The quaternion's exponent.</returns>
        public QuaternionD Exp(QuaternionD a)
        {
            QuaternionD result = new QuaternionD(0, 0, 0, 0);

            double angle = System.Math.Sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z);
            double sin   = System.Math.Sin(angle);

            if (MathFunctions.Abs(sin) > 0)
            {
                double coeff = angle / sin;
                result.X = coeff * a.X;
                result.Y = coeff * a.Y;
                result.Z = coeff * a.Z;
            }
            else
            {
                result.X = a.X;
                result.Y = a.Y;
                result.Z = a.Z;
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Calculates the exponent of a quaternion.
        /// </summary>
        /// <param name="a">A <see cref="QuaternionF"/> instance.</param>
        /// <returns>The quaternion's exponent.</returns>
        public QuaternionF Exp(QuaternionF a)
        {
            QuaternionF result = new QuaternionF(0.0f, 0.0f, 0.0f, 0.0f);

            float angle = (float)System.Math.Sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z);
            float sin   = (float)System.Math.Sin(angle);

            if (MathFunctions.Abs(sin) > 0.0f)
            {
                float coeff = angle / sin;
                result.X = coeff * a.X;
                result.Y = coeff * a.Y;
                result.Z = coeff * a.Z;
            }
            else
            {
                result.X = a.X;
                result.Y = a.Y;
                result.Z = a.Z;
            }

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Calculates the exponent of a quaternion.
        /// </summary>
        /// <param name="quaternion">A <see cref="QuaternionD"/> instance.</param>
        /// <returns>The quaternion's exponent.</returns>
        public QuaternionD Exp(QuaternionD quaternion)
        {
            QuaternionD result = new QuaternionD(0, 0, 0, 0);

            double angle = System.Math.Sqrt(quaternion.X * quaternion.X + quaternion.Y * quaternion.Y + quaternion.Z * quaternion.Z);
            double sin   = System.Math.Sin(angle);

            if (MathFunctions.Abs(sin) > 0)
            {
                double coeff = angle / sin;
                result.X = coeff * quaternion.X;
                result.Y = coeff * quaternion.Y;
                result.Z = coeff * quaternion.Z;
            }
            else
            {
                result.X = quaternion.X;
                result.Y = quaternion.Y;
                result.Z = quaternion.Z;
            }

            return(result);
        }