Advertisement

Rotations on arbitrary axis

Started by April 03, 2001 09:21 AM
5 comments, last by Ehawki 23 years, 7 months ago
Hi, Can somebody help me out a little with this rotation problem? All the rotations matrix that I have came up with so far is a rotation around the x axis or y axis, or z axis or a combination of the three. How do I go about rotating a vector V1 45 degrees around an arbitrary vector V2 say (0.1,0.2,0.5) Say we have Mx as the rotation matrix for the x axis My as the rotation matrix for the y axis Mz as the rotation matrix for the z axis Thanks for you help.
Hi,

OpenGL is designed to work with arbitrary angles. If you look at the parameters to glRotate(), you can specify the axis to rotate around. So for your example, the code would be simply -

glRotate(45.0f, 0.1f, 0.2f, 0.5f);

I assume that the vector you specify in paramters 2, 3 + 4 should be normalised, although it is not mentioned in the blue book so maybe it will be ok not to. I would recommend that you do anyway though as different driver writers may have different ideas.

Dan

Dan

Advertisement
I think he means how to rotate a vector, not an opengl object. I have no idea as to how to do this simply. I figured that if you had a vector [1,1,1] then you''d line it up with the x-axis so that the z value becomes zero (remembering the rotation) and then then rotating it until it lies on the x-axis (so that the y value becomes zero) and then rotating that vector [1,0,0] (or whatever you have left) about the x-axis, and then do the exact reverse to get the new rotated vector. No time to explain.. sorry
Thanks for the reponses,

They are helpful,

But can you give me a mathematical example
eg. Rotate V1(0.2,0.2,0.1) 45 degrees around V2(0.1,0.2,0.2)

If Mx is the x-axis Rotation matrix
If My is the y-axis Rotation matrix
If Mz is the z-axis Rotation matrix

I kind of see what you are saying, but when I do the reverse, wouldn''t I get the same vector back? I''m a little confuse as to which vector I do the reverse to and also in your explanation you did not include the angle of rotation around the vector V2.

I just need to overcome this problem to continue on, I would greatly appreciate your help.

Thanks for all your help.
eHawkI
Real Time Rendering tells exactly how to do this. I don''t have the book in front of me to give you the exact algorithm but i can give you a tad of theory.

First, you have your vector that represents an axis that you want to rotate around. Now you need to construct this vector''s basis( e.g. the x and z axis is the basis for the y axis). Now you transform this new set of axis to be lines up with a normal xyz axis. Now do the rotation(we know the matrices for rotating around the x y or z axis), say the x axis, now translate back to where the original basis was. The matrix will now represent a rotation around the axis you wanted to rotate around.

ECKILLER
ECKILLER
One more thing, to rotate v0 around v1:

matrix m( v1, 45); // make a matrix representing a 45 degree
// rotation around v1

vector rotatedVector = m * v0;

ECKILLER
ECKILLER
Advertisement
Thanks,

I kinda get it.

So basically I just do my rotation with with the normal xyz axis, but how do I know which axis to rotate on if say the
v1=(0.1,0.2,0.2) or v1=(0.1,0.2,0)(the vector I want v0 to rotate around). Do I do a normal rotation on all x-axis, y-axis, and z-axis even if one of the v1''s entry is 0? So I''ll have something like this

So if v1 = {0.1,0.2,0.2} or v2 = {0.1,0.2,0.0}
Basis for normal xyz axis is say B1 = [{0,0,1},{0,1,0},{1,0,0}]
Basis for v1 axis is say B2 =? (I''m not sure, need to do some reading)

So,
v0*B1 = v0 (transtated into the normal vector space spefied by B1
the normal xyz axis)

Mx*My*Mz*v0 = v'' rotated vector in normal xyz axis,

Then,
v''*B2 = rotated vector in v1 axis?

Is this correct? Something like this?

Thanks for your help once again.

This topic is closed to new replies.

Advertisement