# Quaternion Usage for rotation (short problem)

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

## Recommended Posts

Hey guys! I'm hoping someone can help me with understanding where i need to go next here. I have a point in world coords that i need to rotate around an axis. I got that working, but I also need that point to rotate around another point on that axis. How can I have the rotated point rotate around the axis i define in relation to the other static point? Here's the simple code I have so far: Note: I've been using this GameDev article to base my code from: http://www.gamedev.net/reference/articles/download/DA-Quaternion.pdf Glossary: quatPoint is the point that is being rotated around the axis. quatRotate is the rotation quaternion. quatRotateConjugate is quatRotate's conjugate quatResult is the final position of the rotated point angle is the angle around the axis to rotate the point. newRay.dir is the normalized direction of the axis newRay.pos is the point (D3DXVector3) that I want quatPoint to be rotated around (this is not done yet) Here's the code so far:
quatRotate.x = newRay.dir.x * sin(angle/2.0f);
quatRotate.y = newRay.dir.y * sin(angle/2.0f);
quatRotate.z = newRay.dir.z * sin(angle/2.0f);
quatRotate.w = cos(angle/2.0f);

D3DXQuaternionConjugate(&quatRotateConjugate, &quatRotate);

quatResult = quatRotate * quatPoint * quatRotateConjugate;


That's it. It appears that the point is being rotated around the origin... how can i rotate it around newRay.pos? Any help you guys can provide will help. Thanks!

##### Share on other sites
Translate the center of rotation to the origin, then rotate, then translate back. In other words, if v is the point to be rotated and c is center of the rotation, v' = rotate( v - c ) + c, or in matrix form v' = TcRTc-1v

##### Share on other sites
yeah that makes sense... i'm going to fool with this today but i wanted to check and see if quaternions are different from matrices.

##### Share on other sites
Neither Quaternions nor Rotation Matrixes are "rotations".

They are orientations.

The difference is:
You can have a rotation of "spin around 4 times", which is different than a rotation of "spin around 3 times".

But, the orientation after "spin around 4 times" is the same as the orientation after "spin around 3 times".

For a real rotation, you want:
1> A "base point" and an orientation from that point.
This defines the "axis" around which your rotation occurs.
The "space" in which this axis exists is often a tricky point. (global? object local?)

2> An amount of rotation

3> The duration of rotation

To rotate a point around an axis:
1> Calculate the vector (point - axis_base). Make certain you have your "space"s correct.

2> Re-orient the vector using the "orientation" matrix/quaternion.

3> Figure out what fraction of the entire rotation you are doing. Calculate the amount of rotation after that fraction. (ie, are you 1/2 the way through the rotation? Then halve the "amount of rotation")

4> Rotate the vector by that amount. (you will be rotating around an axis of your choice, so this rotation is easy -- you can calculate an easy "orientation" matrix/quaternion and apply it).

5> Invert the re-orientation of the vector.

6> Calculate the new point. new_point = (axis_base + new_vector)

Note that for a given "fraction of rotation", the entire algorithm above can be composed into a single 4x4 affine transformation matrix. And you can compose/repeatedly apply these 4x4 affine transformation matrixes in the naive way and get the result you would want.

The above is only important when you want to be able to answer the question "what point is 1/2 the way along my rotation". If you never need to know this, then orientations are good enough for rotating.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
12

• 9
• 21
• 13
• 9
• 17
• ### Forum Statistics

• Total Topics
632608
• Total Posts
3007391

×