# How do you combine matrix rotations using a timestep?

This topic is 3168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Specifically, how do you handle cases such as this? Would some sort of interpolation using "dt" work? ("dt" being the timestep)
state.Rotation *= state.AngularMomentum * dt;
state.AngularMomentum *= state.AngularAcceleration * dt;


Thanks.

##### Share on other sites
I think what you want would be:

state.Rotation *= state.AngularMomentum ^ dt;

Unfortunately, this is not that easy to compute. For general matrices, this is usually done using eigen decomposition, which is not easy on matrices larger than 2x2, and is in fact generally approximated using an iterative algorithm (using the QR algorithm for example).

Eigen decomposition of A:

A = E * D * inv(E)

where E is a matrix containing the eigenvectors as columns, and D a diagonal matrix containing the eigen values.

then:

A^t = E * D^t * inv(E)

In this case though, we know it's a rotation only matrix, so we might use an easier approach:

Since we know that one eigen value will be 1, we can find the axis of rotation by solving the following system for x

(A - I)x = 0

Then any vector y perpendicular to this axis will lay on the plane of rotation. If we then calculate the angle between y and A * y, we know the angle of rotation. Once we know this angle, we can do a slerp between the identity matrix, and your matrix, using dt as parameter, which should give you the desired matrix.

But anyway, if it would be possible, I'd actually just advice you to use quaternions, since it would make it all a lot easier.

##### Share on other sites
Angular velocity is usually stored as a 3-vector, with the direction indicating the axis of rotation and the magnitude indicating the speed of rotation.

##### Share on other sites
...Thank you, that's probably the impetus I need to implement Quaternions...

##### Share on other sites
Quaternions are rarely used for this, in part because they artificially restrict your maximum angular speed.

##### Share on other sites
Good to know, thanks.

##### Share on other sites
Something like this?

Edit: Ok, now what do I store angular acceleration as?...
        /// <summary>        /// Makes a rotation matrix around an axis and an angle.        /// </summary>        /// <param name="a">The axis to rotate around.</param>        /// <param name="angle">The angle to rotate.</param>        /// <returns>Returns a RotationMatrix.</returns>        public static RotationMatrix MakeRotationAxis(Vector3 a, double angle)        {            //	assert(axis is normalized);            RotationMatrix matrix = RotationMatrix.Identity;            double c = Math.Cos(angle);            double c1 = 1 - c;            double s = Math.Sin(angle);            matrix.M11 = c + c1 * a.X * a.X;            matrix.M21 = c1 * a.X * a.Y + s * a.Z;            matrix.M31 = c1 * a.X * a.Z - s * a.Y;            matrix.M12 = c1 * a.X * a.Y - s * a.Z;            matrix.M22 = c + c1 * a.Y * a.Y;            matrix.M32 = c1 * a.Y * a.Z + s * a.X;            matrix.M13 = c1 * a.X * a.Z + s * a.Y;            matrix.M23 = c1 * a.Y * a.Z - s * a.X;            matrix.M33 = c + c1 * a.Z * a.Z;            return matrix;        }        /// <summary>        /// Rotates a rotation matrix by a vector.        /// </summary>        /// <param name="a">The rotation matrix.</param>        /// <param name="b">The vector to rotate by. The normalized vector         /// is the axis; the vector magnitude is the angle.</param>        /// <returns>Returns a rather rotated rotation matrix.</returns>        public static RotationMatrix Rotate(RotationMatrix a, Vector3 b)        {            return MakeRotationAxis(b.Normalized, b.Length) * a;        }

##### Share on other sites
Quote:
 Ok, now what do I store angular acceleration as?

Vector.

##### Share on other sites
...Well, then, far as I can figure, I either do a Lerp when adding two angular acceleration figures - Or, somewhere in the math I'm going to have to implement, there's at least one mathematical symbol that resembles Cthulthu.

...Or I'm missing something.

##### Share on other sites
Angular accelerations, expressed as vectors, can be added to each other in the usual way in which you add vectors. (It's more common to add torques, though.)

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013710
×