Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }