🔒 Locked
Axis-Angle Transformations
Advertisement
Original Post
I posted this question before, but I constructed it in the wrong way, which misleaded a lot of people. I''ll try to rephrase it so it will be easier to understand.
I define an orientation of a model in the world using a vector and an angle around it (angle-axis).
I am applying vector-angle transformation v1 to the model.
Then I am applying a different vector-angle transformation v2 to the model.
Is there a way for me to get v1 and v2 combined, meaning the new angle-axes of this model?
The opengl anology of this is the following:
glRotate(v2.a, v2.x, v2.y, v2.z);
glRotate(v1.a, v1.x, v1.y, v1.z);
How do I get v3, the result of the previous two transformations?
Thanks.
My math isn''t very strong so I may be completely wrong. If you run a unit vector through both transforms then the ratio of the components of the resulting vector to the matching components of the orginal unit vector gives you a value to multiply all the vertices by to rotate the entire model. As I said I could be completely wrong so take it with a grain of salt. I may also have completely misunderstood your question.
I think I know the answer to that one. The cross product of the two rotation matrices is a rotation matrix that will result in the same transformation as applying both in the same sequence to the vector. The axis-angle matrix is:
That is assuming (vM)N = v(MN). Although not strong at math I''m pretty certain that one is true.
|
That is assuming (vM)N = v(MN). Although not strong at math I''m pretty certain that one is true.
Well, close, try y*z*(1-c)-(x*s) instead of y*z*(1-c)+(x*s).
quote:
Original post by kill
The opengl anology of this is the following:
glRotate(v2.a, v2.x, v2.y, v2.z);
glRotate(v1.a, v1.x, v1.y, v1.z);
How do I get v3, the result of the previous two transformations?
Thanks.
You can use quaternions to solve this. Convert axis-angle representations to quats, multiply the quats and convert back.
Here''s the breakdown:
//Convert axis-angle to quat (assuming axis is a unit vector)
q1.x = v1.x*sin(v1.a/2);
q1.y = v1.y*sin(v1.a/2);
q1.z = v1.z*sin(v1.a/2);
q1.a = cos(v1.a/2);
q2.x = v2.x*sin(v2.a/2);
q2.y = v2.y*sin(v2.a/2);
q2.z = v2.z*sin(v2.a/2);
q2.a = cos(v2.a/2);
//Multiply quats (q3 = q1q2)
q3.a = q1.a*q2.a - (q1.x*q2.x + q1.y*q2.y + q1.z*q2.z)
q3.x = q1.a*q2.x + q2.a*q1.x + q1.y*q2.z - q1.z*q2.y
q3.y = q1.a*q2.y + q2.a*q1.y + q1.z*q2.x - q1.x*q2.z
q3.z = q1.a*q2.z + q2.a*q1.z + q1.x*q2.y - q1.y*q2.x
//Convert quat to axis-angle
v3.a = 2acos(q3.a)
v3.x = v3.x/sin(v3.a/2)
v3.y = v3.y/sin(v3.a/2)
v3.z = v3.z/sin(v3.a/2)
Of course, you should check for sin(v3.a/2)==0, but that''s the identity transform (v3.a=0), so it doesn''t matter what you set the axis to.
Jason Shankel
quote:
Original post by kill
what do I do if v3.a/2 is 0?
If v3.a/2 is 0, then this is a rotation of 0 degrees about some axis. Any rotation of 0 degrees is the identity rotation, so it doesn''t matter what you set the axis to.
For a rotation quaternion, the vector-part would be set to (0,0,0). If your axis-angle system can tolerate a (0,0,0) axis, you should use this.
As I noted above, you should check for v3.a/2 = 0 before doing the division.
Jason
My guess is that it means you rotated back to the starting point so you do absolutely nothing. The only case I can think of with two rotations is two rotations of zero. I''m not confident enough to say there are no others, but I can''t think of any. If there are then someone please speak up and give an example. If the axis are not at right angles to one another I can see how it would, but then isn''t the entire routine invalidated? Or can it rotate about two arbitrary axis of rotation?
I am new to quaternions, so could someone clear up a couple of questions for me?
I have a quaternion that defines a direction of a model in space. It pretty much has a vector, and an angle around it (well, cosine of half of the angle). That''s clear.
Now, if I want to rotate this vector, I need to create rotation quaternion, and multiply the original quaternion by it. Now, how do I set up the rotation quaternion? I can''t seem to get it to work.
If I want to skew the original vector up or down, what do I do? I tried to set up a rotation quaternion with angle of 0 and vector (0, 1, 0), where 1 defines the y axes. My guess was that the original direction would turn 90 degrees up, but that didn''t happen. Can someone clarify how this works?
Thanks.
I have a quaternion that defines a direction of a model in space. It pretty much has a vector, and an angle around it (well, cosine of half of the angle). That''s clear.
Now, if I want to rotate this vector, I need to create rotation quaternion, and multiply the original quaternion by it. Now, how do I set up the rotation quaternion? I can''t seem to get it to work.
If I want to skew the original vector up or down, what do I do? I tried to set up a rotation quaternion with angle of 0 and vector (0, 1, 0), where 1 defines the y axes. My guess was that the original direction would turn 90 degrees up, but that didn''t happen. Can someone clarify how this works?
Thanks.
quote:
Original post by LilBudyWizer
My guess is that it means you rotated back to the starting point so you do absolutely nothing. The only case I can think of with two rotations is two rotations of zero.
No, they don''t both need to be zero. You''ll get it if the two rotations have the same axis and opposite angles (a,(x,y,z)) and (-a,(x,y,z)) or if two rotations have the same angle and opposite axes (a,(x,y,z)) and (a,(-x,-y,-z)).
Jason
quote:
Original post by kill
I have a quaternion that defines a direction of a model in space. It pretty much has a vector, and an angle around it (well, cosine of half of the angle). That''s clear.
Thanks.
I gather from this that you''re under the impression that the vector-part of a quaternion indicates the direction that a model is "facing" and the scalar-part represents the roll around this axis. This is not the case.
The vector part of a quaternion specifes the axis around which the object is rotated and the scalar part specifies the angle (cosine of the half angle) of rotation about this axis.
So, if you want to rotate an object 90 degrees "up", use the quaternion (cos(45),(sin(45),0,0)). This represents a 90 degree rotation about the x-axis.
Jason
quote:
Original post by kill
Why are you using (sin(45),0,0) to rotate around x axis? Wouldn''t it be (1, 0, 0)?
Edited by - kill on November 9, 2000 5:25:59 PM
No. Rotation quaternions must have unit length. That is, for a quaternion (a,(x,y,z)), a^2+x^2+y^2+z^2 = 1. So the magnitude of the vector-part of a rotation quat is always sin(angle/2).
Jason
I think I''ll just have to get to the point where I''m actually drawing stuff in 3D to understand. Practice makes perfect
and I''m a bit away from practice. Hopefully only a week or two, but right now seems an enternity.
quote:
Original post by shankel
I gather from this that you''re under the impression that the vector-part of a quaternion indicates the direction that a model is "facing" and the scalar-part represents the roll around this axis. This is not the case.
The vector part of a quaternion specifes the axis around which the object is rotated and the scalar part specifies the angle (cosine of the half angle) of rotation about this axis.
But isn''t that the same thing?
quote:
Original post by kill
[quote]Original post by shankel
I gather from this that you're under the impression that the vector-part of a quaternion indicates the direction that a model is "facing" and the scalar-part represents the roll around this axis. This is not the case.
The vector part of a quaternion specifes the axis around which the object is rotated and the scalar part specifies the angle (cosine of the half angle) of rotation about this axis.
But isn't that the same thing?
No. It's a little difficult to explain this without graphics, but I'll give it a try.
You need to stop thinking in terms of objects having a "facing direction". This is an artificial concept. The nose of a jet is the front because we humans say it's so, not because the math does.
Axis-angle rotations describe a change in orientation relative to an arbitrary axis, not a "facing" and "roll" vector.
So, for an axis-angle (ie quaternion) rotation, if the angle is zero, no change in direction occurs. If you have a model of a plane facing down the z-axis and you apply an axis-angle rotation where the angle is zero, *regardless* of what the axis is, the plane stays facing down the z-axis.
Under the scheme you're picturing, the axis would define the direction that the plane is facing and a zero angle would just mean that the plane isn't rolling off the vertical. Under your scheme, if you change the vector while keeping the angle zero, you change the direction that the plane is flying. This is not how axis-angle rotation works.
Axis angle rotation describes what happens to an object if you run it through with a spear and rotate it around that spear. The axis describes the orientation of the spear and the angle describes how much you turn the object around that spear.
If the angle of rotation is zero, then it doesn't matter where the spear runs through, the object is not rotated.
For a practical example, consider an airplane facing down the z-axis. We want to change it so the plane is facing down the x-axis.
Presumably, you would say that the plane's transform would look something like this:
(0,(1,0,0))
That's 0 degrees of roll and facing down the x-axis.
The axis-angle transform would really read something like this:
(90,(0,1,0))
That's a 90 degree rotation about the y-axis. To take a plane that is facing down the z-axis and turn it to face down the x-axis, you would run it through from the top (ie the y-axis) and turn it 90 degrees.
Look at it from the point of view of a toolkit. You have a single tool for changing the orientation of an object. You can run it through with a spear and you can twist it along that spear. You cannot directly set its "facing" vector and "roll" angles. All you can do is stab and twist.
Now, if you want to set facing vectors, you can. But you have to switch to matrices.
Jason
Edited by - shankel on November 13, 2000 5:11:03 PM
Edited by - shankel on November 13, 2000 5:12:15 PM
Ok, my code is almost almost working. I just need to figure out one more thing to make it complete.
I used ur airplane analogy and multiplies the original quaternion by a transformation quaternion to rotate the model. I used (1, 0, 0), (0, 1, 0) and (0, 0, 1) vector parts of the quaternions and multiplied them by the original. I thought that in this case (1, 0, 0) would be a local axes, but it turns out to be global.
My final question is, how do I transform the global x, y, and z axes to the local x, y, and z axes of a model? Another words, when I multiply the original quaternion by a transformation quaternion, how do I make sure that the transformation quaternion transforms around the local set of axes?
Thanks a lot for ur time.
I used ur airplane analogy and multiplies the original quaternion by a transformation quaternion to rotate the model. I used (1, 0, 0), (0, 1, 0) and (0, 0, 1) vector parts of the quaternions and multiplied them by the original. I thought that in this case (1, 0, 0) would be a local axes, but it turns out to be global.
My final question is, how do I transform the global x, y, and z axes to the local x, y, and z axes of a model? Another words, when I multiply the original quaternion by a transformation quaternion, how do I make sure that the transformation quaternion transforms around the local set of axes?
Thanks a lot for ur time.
quote:
Original post by kill
I used ur airplane analogy and multiplies the original quaternion by a transformation quaternion to rotate the model. I used (1, 0, 0), (0, 1, 0) and (0, 0, 1) vector parts of the quaternions and multiplied them by the original. I thought that in this case (1, 0, 0) would be a local axes, but it turns out to be global.
I''m not quite sure what you''re trying to do here. To concatenate rotations, you multiply them. Let''s forget about quaternions for the moment and stick with glRotate.
glRotate multiplies the current transform by a transform defined by an axis and an angle.
What does this mean in English? Consider the airplane facing down the z-axis. Calling glRotate(90,0,1,0) will turn it 90 degrees about the y-axis to face the x-axis.
Now, calling glRotate again will rotate the object about its *local* coordinate system. That is, the airplane''s "x" axis is now pointing down the global z-axis, So calling glRotate(45,1,0,0) will rotate the plane about its local x axis (the global z axis) to tilt its nose up.
quote:
Original post by kill
My final question is, how do I transform the global x, y, and z axes to the local x, y, and z axes of a model? Another words, when I multiply the original quaternion by a transformation quaternion, how do I make sure that the transformation quaternion transforms around the local set of axes?
Every time you multiply the current transform by a new transform you are rotating about the local coordinate system. The net rotation from the global coordinate system is the multiplicative product of all these rotations.
This stuff is very confusing, I know. The best way to learn it is to play with it. It''s easier to visualize the math if you''ve seen it in action.
Jason
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement