Rotations

Started by
5 comments, last by ChristophR 17 years, 9 months ago
Hi! I have a sequence of rotations around differet axes. Each is described by a rotation axis and a rotation angle (I think this is called quaternion rotation or so). Now I need an algorithm which combines all these rotations and returns just 1 rotation (around 1 axis). For instance: The input is a rotation of 180° around the x-axis and then a 180° rotation around the y-axis. The result would be the same if I perform only one rotation: a 180° rotation around the z-axis. The input can be any number of rotations. The rotation axes can be freely chosen, they do not need to be the axes of the coordinate system. The output shall be exactly 1 rotation axis and an and a corresponding angle. PS: I do not want to work with rotation matrices and matrix multiplications, because if I do so the result would be another rotation matrix. But like I mentioned above I am interested in the final rotation axis and angle, not in the matrix. Thanks in advance! rgds
Advertisement
Just multiply your matrices together to get the final matrix.

BTW, it euler not quats.

edit: Since you don't want to do matrix multiplications then you could use the axis-angle rotation. There are lots of example in the articles secion of this site.

Hi.
Quote:Original post by relsoft
Just multiply your matrices together to get the final matrix.


I know, but I said that I am not interested in the final rotation matrix. What I want is the final rotation axis + rotation angle.
Okay, here it is. x y and z are components of the vector(axis) you would wnat to rotate.


void CMatrix::rotate_on_axis (float angle, float x, float y, float z){ 	 float sa = (float)sin(angle); 	 float ca = (float)cos(angle); 	 float recip_leng = 1.0f / (float)sqrt( x*x + y*y + z*z ); 	 x *= recip_leng; 	 y *= recip_leng; 	 z *= recip_leng; 	  	 element[0]  = ca + (1.0f-ca) * x * x;	 	//x1     element[1]  = (1.0f-ca) * x*y + sa*z;      //x2     element[2]  = (1.0f-ca) * x*z - sa*y;	 	//x3     element[3]  = 0.0f;                        //w1     element[4]  = (1.0f-ca) * y*x - sa*z;      //y1     element[5]  = ca + (1.0f-ca) * y * y;      //y2     element[6]  = (1.0f-ca) * y*z + sa*x;      //y3     element[7]  = 0.0f;                        //w2     element[8]  = (1.0f-ca) * z*x + sa*y;      //z1     element[9]  = (1.0f-ca) * y*z - sa*x;      //z2     element[10] = ca + (1.0f-ca) * z * z;      //z3     element[11] = 0.0f;                        //w3     element[12] = 0.0f;	 		  			//tx     element[13] = 0.0f;                        //ty     element[14] = 0.0f;                        //tz     element[15] = 1.0f;                        //w4}


BTW, to get your axis you could...

target and pos are vector3d.

vector3d v = target - pos
normalize(v)
Hi.
Googling for 30 seconds I found this: http://www.mathworks.com/access/helpdesk/help/toolbox/physmod/mech/f13-25936.html. It seems to be what you were looking for. Combine your rotations as matrices or as quaternions, and then convert the result to axis-angle representation.
I am not sure if you understood what I mean (it's difficulat to explain):

I give you an example. If I have the following sequence of rotations
- 180° around the x-axis
- 180° around the y-axis

the point 1/1/1 would be at 1/-1/-1 after the first rotation and at -1/-1/1 after the second one.

But I could also perform a 180° rotation around the z-axis. This would also move the point 1/1/1 to -1/-1/1 with only one rotation.

Your example code builds a rotation matrix. But what I want is an output like "Your sequence of 2 rotations has the same result than one 180° rotation around the z-axis" (more technical: 180°; (0, 0, 1) ). I do not understand what you mean with
>> vector3d v = target - pos

If I calculate: (-1/-1/1) - (1/1/1), I get: (-2/-2/0). The normalized vector would be (-sqrt(0.5), -sqrt(0.5), 0), but this vector has nothing to do with the z-axis.

But note: the 1/1/1-point above was just an example. In the end I do not want to rotate any points at all. All I want to know is the rotation axis and the angle.
Quote:Original post by alvaroCombine your rotations as matrices or as quaternions, and then convert the result to axis-angle representation.


Yes, that is exactly what I need. Thank you!

This topic is closed to new replies.

Advertisement