Combining Rotation Matrices

Started by
14 comments, last by relsoft 18 years, 9 months ago
Does anyone know a way to combine two rotation matrices that are based upon different control axis? To control the orientation of a flying object, such as an airplane, I use a rotation matrix for the control surfaces such as elevator and rudder, and another rotation matrix for gravity. Because, no matter what attitude the plane is in, I want gravity to pull the nose straight toward the ground. Concatenating these two matrices doesn't seem to work. Can someone tell me how this is done? Does anyone know what I'm talking about? Thanks.
Advertisement
What do you mean by "doesn't seem to work" ?

One thing you can try is to convert your two matrices to two quaternions, do a slerp between these, and convert back to a matrix. It might behave better.

Y.
Well, the big thing to keep in mind is that when dealing with Matricies the order of operations is very VERY important. Rotating on X and then Rotating on Y will give very different results than doing the reverse. It's hard to say the exact order that you should go in, but I would suggest simply toying around with it. Swap the matrix order around and see what you get.

Now, I have a question: Why are you storing gravity as a rotation matrix? A simple translation along the gravity vector should do the trick (as long as it's in the right place in the transformation chain)
// The user formerly known as Tojiro67445, formerly known as Toji [smile]
I agree. Use quaternions in the process, but not exclusively unless you want headaches. My camera class use a matrix to store rotations. When I want to pitch/yaw/roll the camera, I convert the matrix to a quaternion, perform the rotation, and convert the quaternion back to matrix.

Toji, Vectorg isn't talking about gravity pulling the entire plane downward, he's talking about pulling nose of the plane downward, ie, pitching the entire plane forward.
http://blog.protonovus.com/
Thanks for the help.

By "doesn't seem to work", I mean that it definitely doesn't work, but maybe I'm just doing it wrong.

Here's an example of what should happen. The airplane is flying level, but banked (rolled) at a 45* angle. Gravity will pitch the nose downward toward the ground, but not at a 45* angle.

Gravity is causing rotation on an axis different than any of the plane's 3 defined axis, and different than the x,y,z axis defined in the plane's rotation matrix. How can I apply these off-axis rotations to the matrix?

Is this what quaternions can do? I have read about, but not used them. How are they different? Where should I start?

Thanks.
Quote:Gravity is causing rotation on an axis different than any of the plane's 3 defined axis, and different than the x,y,z axis defined in the plane's rotation matrix. How can I apply these off-axis rotations to the matrix?

Is this what quaternions can do? I have read about, but not used them. How are they different? Where should I start?
Short answer on quaternions: forget about them for now. You can do just about anything with a matrix that you can do with a quaternion. Quaternions do have some advantages, but if you introduce quaternions without fully understanding what those advantages are (and, more importantly, are not), you'll just be confusing the issue. All IMHO, but my advice is to just stick with matrices for now.

As for your specific question, I don't know how your airplane orientation matrix is set up, but I think the problem you describe will be easiest to solve if you avoid Euler angles (more specifically, avoid constructing your matrix from scratch each frame from an Euler angle triple).

Let's say your airplane matrix is maintained from frame to frame using relative rotations about the local axes. Then, to pull the nose toward the ground plane, you need to apply one more axis-angle rotation. I'm just guessing at this point (because I really don't know anything about how airplanes actually behave), but I believe the axis for this rotation should have the properties that a) it lies in the ground plane, and b) it is perpendicular to the airplane's forward vector. You should be able to find such a vector as the normalized cross-product of the plane's forward vector and the world up vector. The angle to rotate is then the angle between the forward vector and the ground plane. Presumably, you will only apply some fraction of this angle so as to drop the nose gradually.

That was a little vague - let me know if you'd like a more concrete example.
thanks jyk,

Quote:Let's say your airplane matrix is maintained from frame to frame using relative rotations about the local axes.
Yes, that's what I'm doing.

Quote:Then, to pull the nose toward the ground plane, you need to apply one more axis-angle rotation. I'm just guessing at this point (because I really don't know anything about how airplanes actually behave), but I believe the axis for this rotation should have the properties that a) it lies in the ground plane, and b) it is perpendicular to the airplane's forward vector. You should be able to find such a vector as the normalized cross-product of the plane's forward vector and the world up vector. The angle to rotate is then the angle between the forward vector and the ground plane. Presumably, you will only apply some fraction of this angle so as to drop the nose gradually.
I can picture exactly what you're saying, and I will try it. Yes, the nose will drop gradually and I will do that by subtracting a constant (gravity) from the 'y' value of this 4th vector, then normalize.

But, because this 4th vector will require its own matrix, I have just used 2 distinct rotation matrices to get the plane into its orientation. How do I then combine these into just one matrix that can be carried to the next frame? --This is the part I don't know how to do.--

Any ideas?

Thanks.
I would suggest you do what jyk was saying. Now let's say you have an orientation of the airplane based on 3 orthogonal axis. An you said you have a roll of 45. You can orient your 3 axes so that the right vector is perpendicular to the vector at 45 degrees (your up) and rotate your nose-point around that vector(axis) using the axis-angle representation of rotation.

Unless you represent your rotations with euler angles, I suggest you don't use quats.

Oh on second thought. You said gravity will pitch the nose down after a 45 degree roll.

Would this work?

1. Rotate your up(0,1,0) vector 45 degrees
2. Rotate on that vector n degrees.
Hi.
I must say, i still do not understand what's this "gravity matrix". Gravity is a force that is applied to the center of mass of a rigid body - it does not induce rotations. Can you explain what's your logic behind this ?

Y.
Yea the gravity stuff is kinda confusing. I'm not 100% on the physics and whatnot, but I'm visualizing the airplane like a stick with a weight at only one end (where the nose of the airplane would be). If you throw that stick into the air, the weighted end will be pulled downwards rotating the entire mass.
http://blog.protonovus.com/

This topic is closed to new replies.

Advertisement