Sign in to follow this  
Axiverse

Quaternion's Operators and Combining them?

Recommended Posts

There are lots of good references on the subject. The book '3D Math Primer', google, and the articles section of this site are good places to start.

Briefly, addition and subtraction are component-wise, just like with vectors. The dot product is also defined. Like with vectors, it is the sum of the products of the components, and results in a scalar value that can be viewed as a measure of the 'similarity' between the two quaternions.

Yes, you can concatenate rotations by multiplying quaternions together. You need only convert to matrix form if you specifically need a matrix (e.g. to transform many vertices, or for submission to an API function).

[Edit: fixed typo]

[Edited by - jyk on December 2, 2004 10:56:37 PM]

Share this post


Link to post
Share on other sites
In 3D programming, primitive (quaternion x quaternion -> quaternion) operations other than quaternion multiplication aren't really used; unless you count the additions/subtractions that show up by technicality when performing a multiplication. More common are (quaternion x scalar -> quaternion) operations like scalar multiplication, and even then scalar multiplication is only really used to normalize the quaternions. Though some operations, like power functions are used in interpolating between quaternions.

The concatenation of two rotations represented by two quaternions q1 and q2 can be represented by multiplying q1 and q2 together. Just watch the order of rotations since quaternion multiplications are non-abelian.

Share this post


Link to post
Share on other sites
Not disagreeing with SiCrane, but addition and scalar multiplication do pop up occasionally, so it is useful to have those functions defined in your quaternion class. For example, an implementation of Slerp() might include something like the following:

result = t1 * q1 + t2 * q2; // result, q1 and q2 are quaternions, and t1 and t2 are scalars

Share this post


Link to post
Share on other sites
Addition of unit-length quats doesn't really have a meaning, because it denormalizes them. But, pretty much all vector math has a quaternion equivalent. Vector addition is quaternion multiply. Subtraction is multiplication of inverse. Vector dot is quaternion dot. And scalar multiply for vectors is quaternion power. i.e. if you want to represent a rotation of 1/3 of a quaternion q: r = q^.333f

That's how they get the equation for slerp. Linear interpolation of vectors is rt + s(1-t)... and linear interpolation of quaternions (slerp) is q^t s^(1-t) (where quaternion multiply is analagous to vector addition). The equation you see in books is just that expanded out into sin and cos with some terms simplified for speed.

I wrote a critically-damped quaternion interpolator using the vector code in GPG4, and just turned each of the vector expressions into the quaternion equivalent. It worked perfectly with 2 caveats: 1) you have to do the same dot as in slerp to find the shortest-arc quaternion difference. and 2) you can't represent angular velocities greater than 1 rev/unit time with unit-length quaternions so you have to choose your unit time carefully.

Share this post


Link to post
Share on other sites
Quote:
Original post by Axiverse
I'm just wondering what the operators between quaternions ( add, subtract, dot... ) are used for and also if you can combine the rotations of two quaternions without creating matricies.


Perhaps I am mistaken, but isn't a quaternion just a 4x4 matrix? I don't see how you can get away without creating matricies when it is already one.

Share this post


Link to post
Share on other sites
Yes you are. Go to mathworld and see what a quaternion is. Quaternions are "equivalent" (isomorph) to a subset (subfield, right term in english ?) of 3x3 matrices : the right handed rotation and uniform scaling matrices (which are a subset of the 3D similarity matrices). And 3x3 matrices can be seen as a subset of the 4x4 homogenous matrices (no translation).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this