Ejemplo n.º 1
0
        /// <summary>
        /// Subtracts the provided <see cref="quatf"/> from this
        /// <see cref="quatf"/>.
        /// </summary>
        /// <param name="rhs">
        /// The <see cref="quatf"/> to subtract from this
        /// <see cref="quatf"/>.
        /// </param>
        /// <returns>
        /// The resultant <see cref="quatf"/> from the subtraction.
        /// </returns>
        public quatf Subtract(quatf rhs)
        {
            var q = rhs;

            return(new quatf(
                       -q.X * W + q.W * X + q.Z * Y - q.Y * Z,
                       -q.Y * W - q.Z * X + q.W * Y + q.X * Z,
                       -q.Z * W + q.Y * X - q.X * Y + q.W * Z,
                       q.W * W + q.X * X + q.Y * Y + q.Z * Z));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts an orientation represented as a quaternion to a
        /// direction cosine matrix.
        /// </summary>
        /// <param name="quat">
        /// The quaternion to convert.
        /// </param>
        /// <returns>
        /// The corresponding direction cosine matrix.
        /// </returns>
        public static mat3f Quat2Dcm(quatf quat)
        {
            var q1 = quat.X;
            var q2 = quat.Y;
            var q3 = quat.Z;
            var q0 = quat.W;

            return(new mat3f(
                       q0 * q0 + q1 * q1 - q2 * q2 - q3 * q3,
                       2f * (q1 * q2 + q0 * q3),
                       2f * (q1 * q3 - q0 * q2),
                       2f * (q1 * q2 - q0 * q3),
                       q0 * q0 - q1 * q1 + q2 * q2 - q3 * q3,
                       2f * (q2 * q3 + q0 * q1),
                       2f * (q1 * q3 + q0 * q2),
                       2f * (q2 * q3 - q0 * q1),
                       q0 * q0 - q1 * q1 - q2 * q2 + q3 * q3));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new <c>AttitudeF</c> from a quaternion.
 /// </summary>
 /// <param name="quat">
 /// The orientation expressed as a quaternion.
 /// </param>
 /// <returns>
 /// The new <c>AttitudeF</c>.
 /// </returns>
 public static AttitudeF FromQuat(quatf quat)
 {
     return(new AttitudeF(AttitudeType.Quat, quat));
 }