Jump to content
  • Advertisement
Sign in to follow this  
Narf the Mouse

How do you combine matrix rotations using a timestep?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!