Jump to content
  • Advertisement
Sign in to follow this  
cold_storm

quaternions as orientation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anybody know how to use quaternions to orient a mesh in OpenGL?? It does not make sense to me how 3 imaginary numbers and a real number can represent the orientation of a mesh.

Share this post


Link to post
Share on other sites
Advertisement
First of all, they aren't three imaginary numbers and a real number. They're four real numbers which are used as a single four-dimensional complex number, just as two real numbers can be used as a single two-dimensional complex number.

Secondly, OpenGL does not use quaternions directly. To use quaternions with OpenGL, you generally convert them into rotation matrices.

Thirdly, if you're interested in knowing exactly how quaternions work, rather than just how you can use them, read this.

Share this post


Link to post
Share on other sites
What you suggest, (using quaternions to orient objects) seems more like a convention to me, rathen than an intuitive/straight forward approach.

Quaternions are used in rotations, because they can uniquely describe an axis (3-vector) and an amount of rotation around that axis. The only possible way I see, to determine an orientation from a quaternion, is *to make a convention* that the rotation axis should always represent the "look-at" axis of your object (this one is usually the local Z axis), and the remaining scalar part should represent the 'roll angle' of your object around that axis. This is enough information to uniquely describe an orientation in 3d space.

edit:
I'm tired of posting this, but you'll probably need it...

To convert the quaternion to a DCM matrix (orientation) do the following:
Define vectors: localX, localY, localZ to store the object's local axes
localZ = Normalize( quaternion rotation axis {x,y,z} );
localX = cross( localZ, 'unit world up vector' );
localY = cross( localZ, localX );

The orientation matrix will be the product: R*O,
where R is:
[ cos(w) -sin(w) 0 0 ]
[ sin(w) cos(w) 0 0 ]
[ 0 0 1 0 ]
[ 0 0 0 1 ]


and O is:
[ localX.x localY.x localZ.x 0 ]
[ localX.y localY.y localZ.y 0 ]
[ localX.z localY.z localZ.z 0 ]
[ 0 0 0 1 ]

This is the DCM matrix for your object.
If you are using a left-handed system, negate the results of the cross products, and if you work with row-vectors instead of columns, use the transpose of that product.

Btw, have you come across this in physics simulation? I've lately discovered that people often choose this approach, to describe the instantaneous axis of an object's rotation and the angle it has rotated by, with respect to its previous state, when solving for the specific time step.

[Edited by - someusername on January 1, 2006 9:36:18 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
First of all, they aren't three imaginary numbers and a real number. They're four real numbers which are used as a single four-dimensional complex number, just as two real numbers can be used as a single two-dimensional


Isnt it 3 complex numbers and 1 real number. W(X, Y, Z): W being the Real number?

Share this post


Link to post
Share on other sites
A "complex number" is a number in complex space (where complex space has 2, 4, or 8 dimensions) that is not a real number. But yeah, it can be thought of as three imaginary numbers and 1 real number. The reason I refer to it as 4 real numbers is to hammer in the point that there are exactly 4 scalar quantities and that quaternions are thus a 4-dimensional space.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
A "complex number" is a number in complex space (where complex space has 2, 4, or 8 dimensions) that is not a real number. But yeah, it can be thought of as three imaginary numbers and 1 real number. The reason I refer to it as 4 real numbers is to hammer in the point that there are exactly 4 scalar quantities and that quaternions are thus a 4-dimensional space.


Thats not the correct way to refer to them, but its probably the easiest way to work them out! Hell its the way I successfully figured them out!

Share this post


Link to post
Share on other sites
Considering quaterions ARE 3 complex numbers, 1 real number, quoting them as anything else is incorrect.

Share this post


Link to post
Share on other sites
No they aren't. Each quaternion is an element of a four dimensional normed division algebra over the real numbers. Each quaternion can be represented as linear combinations of four basis quaternions 1, i, j and k, but are each themselves single numbers. Much in the same way x + 1 is a single polynomial even though it is composed of two terms x and 1.

Share this post


Link to post
Share on other sites
SiCrane is right on this one. If x, y, and z were complex numbers, you'd be allowed to write a quaternion such as (1, -3.5i, 2+7i, -12.1). You can't. All 4 values must be real-valued.

Now, when talking about complex and hypercomplex numbers, one of the values is referred to as the real part and the others the imaginary part.

You can see the nomenclature in use at Mathworld:
http://mathworld.wolfram.com/Quaternion.html

It clearly states that the 4 numbers are real. It mentions the real & imaginary part. It even shows a representations of quaternions as 4 complex numbers in a 2x2 matrix.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!