Sign in to follow this  

the purpose of quaternions

This topic is 4357 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

The purpose of complex numbers is obvious: thanks to complex numbers it's possible to take square roots of negative numbers. A complex number raised to any other complex number has a complex number as result and there are always solutions (unlike with real numbers). But since you can take square roots of any complex number to get another complex number, and I can't think of any other mathematical operations that you can do on a complex number that hasn't got a complex number as result (except maybe tetration, who knows), what's the purpose of quaternions? What possibilities do they add to existing mathematics? Also, why isn't there something defined with 3 numbers? Complex numbers have 2 numbers, quaternions have 4 numbers, octonions have 8 numbers, etc... but why's there nothing with 3, 5, 6, 7, ... numbers?

Share this post


Link to post
Share on other sites
well, that's a huge topic... Even Hamilton himself hadn't come up with answers to some of your questions during his lifetime. It is known that Hamilton was trying to come with a generalization of complex numbers in three dimensions and seemed to be having a really hard time. Finally he came up with the quaternions in 4d and had to assume the 'scalar part' (as he called it) being zero... pure quaternions.

Quaternions were originally geared towards an algebraic re-interpretation of that time's known geometry via (hyper)complex numbers. Concepts like vectors and matrices had yet to come, not to mention their calculus... The analogy between the euclidean 2d plane and the complex plane was obvious, Hamilton couldn't help wandering whether there could be something similar in higher number of dimensions, while keeping the interesting properties of complex numbers.

People were interested in exploring all aspects of things back then.
You may find it interesting, nowadays, that you can re-interpret 3d rotations with quaternions, but they would find it more interesting that a quaternion polynomial equation can have more roots than its degree!
Most of these aspects are theoretical, that's why quaternions -today- seemed to pop-up like a solution without a problem.
The advent of vector algebra and matrices -as we know them- was one of the major reasons why Hamilton's quaternions didn't spread. It was only the beginning of a debate that continues... up to our days.

However, people still think much of Hamilton. He introduced many concepts, quite radical at the time being. Abandoning the commutativity of multiplication was one. He was also the first one to introduce concepts like the inner and cross product. And many more I can't remember right now. I believe that if it wasn't for the huge revolution brought with vectors, there would have been much more research in the area. It's quite intriguing as it seems to provide a unique way of understanding space through the properties of complex numbers.

edit:
btw, for number of dimensions 3, 5 etc. it seems that the properties of hypercomplex numbers can't be defined *that well*.
E.g. for 3 dimensions, you should have 2 roots for -1, 'i' and 'j'.
Given the usual way to this, their product i*j should be the additive inverse of the third imaginary root, but there's not such a thing as '-k' here. I don't know how a second root for -1 can be introduced, and how the multiplication table would be defined, while keeping the properties of complex numbers. You'd also have to come up with associative multiplication and other operations...
I guess Hamilton knew better when he had to work with 4d and constrain one dof.

Share this post


Link to post
Share on other sites
Aside from theoretical math - quaternions allow you to rotate objects without intruducing gimbal lock problem, which you would get when you would rotate them using matrices. And that's pretty important feature, since without it creating smooth animation on computers would be rather difficult... :-)

Share this post


Link to post
Share on other sites
Quaternions were specifically created to analyze 3-space. Everytime the concept of number is extended, because humans are inflexible, they wish to retain properties that were had in the original simplistic meaning. Properties as associativity, distributivity and so on. As to what possibilities quaternions added?

They led to a few discoveries in optics by hamilton and Knott managed to say some stuff on heat and electricity, but really? Nothing much. The main benefit of quaternions is that they helped us broaded the concept of number and not be so inflexible. After quaternions a bunch of new algebras and mathematical concepts, including vectors were let loose like a flood gate. But really, just as with vectors, anything you can do with quaternions you can do without them as Cayley emphasised. Problem is, it will be more cumbersome.

Why not 3,5,6,7? The answer is very complicated. Again, it is to do with the properties we wish to retain and the way we have defined our mathematics. Quaternions are part of what is called a division algebra. The key is in parallelizable spheres S^n-1 (very loosely, ability to derive tangent spaces from arbitrary points) which are only possible in n = 1,2,4,8 (why this is so is even more involved, cross sections of cohomology classes, vector bundles and what not). The linchpin of any proof would be Bott's Periodicity Theorem (Raoul Bott only just recently died a mere few weeks ago! [sad]) which links division algebras to vector bundles, a property of them which can be stated in terms of afore mentioned S^n-1 spheres. In English I would say, just because.

If I wasnt clear please tell me where I should clarify.

Share this post


Link to post
Share on other sites
Quote:
Original post by Koshmaar
Aside from theoretical math - quaternions allow you to rotate objects without intruducing gimbal lock problem, which you would get when you would rotate them using matrices. And that's pretty important feature, since without it creating smooth animation on computers would be rather difficult... :-)


Gimbal lock have nothing to do whether you're using matrices or not, but whether you're using an Euler angle representation to represent your rotation. It's perfectly possible to make a rotation system with matrices that doesn't suffer from gimbal lock problem; just stay away from Euler angles. You can use an axis-angle representation of the rotation instead for example.

Quaternions is not the solution to the gimbal lock problem. The solution is to not use Euler angles.

Share this post


Link to post
Share on other sites
EDIT: Looks like Brother Bob beat me to it....


Quote:
Original post by Koshmaar
Aside from theoretical math - quaternions allow you to rotate objects without intruducing gimbal lock problem, which you would get when you would rotate them using matrices. And that's pretty important feature, since without it creating smooth animation on computers would be rather difficult... :-)


Quaternions used for rotations specify an axis and degree to rotate. A Matrix for rotation shares this property.
It is possible to still have gimbal lock when using quaternions for rotation. And it is possible to avoid gimbal lock when using matrices.

Gimbal lock is really a property of how you logically organize your rotations ordering; it is not a direct result of the implementation used -matrix or quaternion.

The main advantage of quaternions over matrices for graphics, is computational savings. The quaternion representation requires fewer multiplication operations when combining them.

Share this post


Link to post
Share on other sites
Quote:
Original post by someusername
Finally he came up with the quaternions in 4d and had to assume the 'scalar part' (as he called it) being zero... pure quaternions.


Huh? This is not clear. He dropped commutation and added an extra axis. He didnt call anything zero, pure quaterions came later.

Quote:
Quaternions were originally geared towards an algebraic re-interpretation of that time's known geometry via (hyper)complex numbers. Concepts like vectors and matrices had yet to come, not to mention their calculus... The analogy between the euclidean 2d plane and the complex plane was obvious, Hamilton couldn't help wandering whether there could be something similar in higher number of dimensions, while keeping the interesting properties of complex numbers.

No they werent. Quaternions were specifically a geometric treatment of cartesian numbers. They followed a reasoning of a treatment as ordered couples complex numbers. 3-space extensions failed to retain the all important property of non ambigious division among others, so he went to 4 and dropped commutativity. Simply that (seems obvious now but such was complete and utter heresy then). Tait used to lament that Hamilton did not have the courage to remove all those seperate components to treat the quaternion as an entire geometric entity whose properties were so natural to space (according to him. we now know that this is not true)!

Quote:

The advent of vector algebra and matrices -as we know them- was one of the major reasons why Hamilton's quaternions didn't spread. It was only the beginning of a debate that continues... up to our days.


Also, dont forget that they were not as intuitive, were not very physical (square of pure quaternion and gradient as well is negative ) and were limited only to analysis of 3-space. No debate remains or (ever existed actaully) among the mathematics community. The physicist might have passed this legacy on to the engineers.

Quote:
He was also the first one to introduce concepts like the inner and cross product.


No he wasnt, people like Mathew O'Brien, Bellavitis, Saint-Venant, Mobius and Grassman preceded him. Actually, I think Mobius was first although i dont think he had a cross product equivalence.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lode
The purpose of complex numbers is obvious: thanks to complex numbers it's possible to take square roots of negative numbers. A complex number raised to any other complex number has a complex number as result and there are always solutions (unlike with real numbers).

But since you can take square roots of any complex number to get another complex number, and I can't think of any other mathematical operations that you can do on a complex number that hasn't got a complex number as result (except maybe tetration, who knows), what's the purpose of quaternions? What possibilities do they add to existing mathematics?

Also, why isn't there something defined with 3 numbers? Complex numbers have 2 numbers, quaternions have 4 numbers, octonions have 8 numbers, etc... but why's there nothing with 3, 5, 6, 7, ... numbers?


A 3-tuple isn't sufficient to encode the information needed.


I don't know your level of math skills, so please make sure you understand each line before continuing to the next line.


Let's start with a rotation angle and polar coordinates.

We want to just state a rotation angle.

A polar coordinate is (r, Θ), the distance from the center (r) and the angle from the positive x axis (Θ).

If you use a value of r=1 and Θ = angle, you have a unit circle. It's a bit overkill for a single rotation angle, but they still have a 1:1 correspondance.

With a small amount of math, you can convert between a location polar(r, Θ) to a location on the 2D cartesian plane Cartesian(x, y).

If you want to through the shortest rotation between polar(1,1) and polar(1,359), you would need to step between (1,2), (1,3), (1,4) ... (1,359).

Even though the Cartesian result is the same, we can't go to polar(1,-1) since it is mathematically a different point than polar(1,359).

But we weren't interested in the same mathematic point in polar coordinates, we really wanted the same mathematic point in cartesian coordinates.

If we converted the same polar(1,1) and polar(1,359) to Cartesian coordinates, we'd see that the shortest distance is going down a tiny bit on the Y axis. So we'd just follow the circle along that tiny bit of Cartesian space. It requires a bit more math if we stay in Cartesian coordinates, but the end result is a the short curve we were interested in.

Complex numbers are basically the same as Cartesian (x,y) coordinate vectors.

So now we have a set of 2D conversions:
angle ↔ (1, Θ) ↔ (X,Y) ↔ complex number

If you don't understand that, please go back and review it.


Let's move to 3D.

To represent an orientation in 3-space, we can use the three Euler angles for yaw, pitch, and roll.

If we want to draw that inside a unit sphere, we get (1, Θ, Φ, ρ).

You might think that since we added a dimension we just need one more polar coordinate, (r, Θ,Φ). But it doesn't work. That gives a point on the sphere (yaw and pitch). That's not the full orientation, since we can also roll in 3-space that we could not do in 2-space.

That four-tuple represents orientation in 3-space using angles.

Now when we want to rotate from polar(1,1,1,1) to polar(1,359,359,359), we still need go around the long way, since (1,-1,-1,-1) is a different point mathematically.

But we are still interested in the Cartesian results, not polar results.

Can we convert that same thing to (X,Y,Z) coordinates and follow the short spherical path as we did in 2D?

No.

The Cartesian coordinate (X,Y,Z) is the same as (r, Θ, Φ), and doesn't encode the possible roll. Instead of a 3x1 matrix for XYZ, we end up needing a 3x3 matrix to include the roll. Nasty.

Using exactly the same conversion math that is used between polar coordinates (r, Θ) ↔ complex numbers, we convert between (r, Θ, Φ, ρ) ↔ quaternions.

So we can use four variables in the quaternion instead of the 9 in an 3x3 matrix. Amazing.



So as far as orientation goes, we can state conversions as

2D: angle ↔ (1, Θ) ↔ (X,Y) orientation ↔ complex number
3D: euler angles ↔ (1, Θ, Φ, ρ) ↔ [3x3] oreintation ↔ quaternion

Hopefully that makes some sense.

frob.

[Edited by - frob on January 10, 2006 11:32:57 AM]

Share this post


Link to post
Share on other sites
Quote:

Finally he came up with the quaternions in 4d and had to assume the 'scalar part' (as he called it) being zero... pure quaternions.

The part "(as he called it)" refers to 'scalar part'

Quote:

He was also the first one to introduce concepts like the inner and cross product.

well, I haven't had the chance to ask Hamilton myself, this are all stuff I've found googling around... I suppose you know better

Share this post


Link to post
Share on other sites
As far as why theres nothing in 3-space, Hamilton struggled for years to figure out how to represent the rotations in 3-space, but he could never find the answer until he did it in 4-space.

I don't know much about math, so I couldn't give you the reason why... I just use the things :)

Share this post


Link to post
Share on other sites
Wow, I hadn't expected such interesting replies, thanks!

About gimbal lock, my 3D engine uses only 3x3 matrices and 3x1 vectors, and I suffer no gimbal lock at all. And both the camera and objects have 6 degrees of freedom, can be rotated around any arbitrary axis, and allow weird transformations like skewing.

Share this post


Link to post
Share on other sites
You do not need quaternions or even matrixes to represent rotations in 3d. 3d Vectors are enough. We can just use the rotation operator Exp(phi X); phi is a 3d vector and X is the cross product. Exp(phi X) v will rotate the v vector around phi by the angel |phi|.
Exp(phi X) v = (1+1/2*phi X+...)v

Share this post


Link to post
Share on other sites
Brother Bob and haphazardlynamed: Ups, sorry for spreading misinformation.

For my defense I must say, that there are some not very clear sentences in chapter 2.7 of GPG #1, which describes what are the applications of quaternions in game programming, and upon which I based that post on.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lode
About gimbal lock, my 3D engine uses only 3x3 matrices and 3x1 vectors, and I suffer no gimbal lock at all.

Gimbal lock is this ridiculous game development bogeyman which gets trotted out whenever the topic of rotations comes up. Ridiculous because 99% of game developers could use euler angles all their life and never actually run into gimbal lock. It's a subject which is of primary importance to robotics and aerospace engineers, and which only really intersects game development in certain special IK cases. Usually, game developers who say "gimbal lock" really just mean non-commutativity of rotations.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Quote:
Original post by Lode
About gimbal lock, my 3D engine uses only 3x3 matrices and 3x1 vectors, and I suffer no gimbal lock at all.

Gimbal lock is this ridiculous game development bogeyman which gets trotted out whenever the topic of rotations comes up. Ridiculous because 99% of game developers could use euler angles all their life and never actually run into gimbal lock. It's a subject which is of primary importance to robotics and aerospace engineers, and which only really intersects game development in certain special IK cases. Usually, game developers who say "gimbal lock" really just mean non-commutativity of rotations.


It's something that in practice you will rarely encounter, and if you implement things correctly should never encounter. But it's very annoying when it hits you.

You might be able to fly a virtual helicopter all over the northern hemisphere in your war simulation. Then a meticulous tester tries to land at the North Pole to see what Santa is doing. The instant he hits the North Pole, Santa pulls out his gimbal lock and the helicopter is doomed to never escape, or maybe get thrown out in a random direction.

Share this post


Link to post
Share on other sites
Heheh... sounds like unhappy personal experience there. Sorry to hear it. [grin] I'd say that most people don't run into this problem purely because maintaining progressively combined rotations is such a pain in the ass, completely independent of gimbal lock. The latitude/longitude thing coming up in flight simulators is interesting, though... I'd never thought of that possibility.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kambiz
You do not need quaternions or even matrixes to represent rotations in 3d. 3d Vectors are enough. We can just use the rotation operator Exp(phi X); phi is a 3d vector and X is the cross product. Exp(phi X) v will rotate the v vector around phi by the angel |phi|.
Exp(phi X) v = (1+1/2*phi X+...)v


I don't really understand what you mean, partially because there seems to be something wrong with the brackets in the notation "Exp(phi X) v". Do you mean "Exp(phi) X v" or "Exp(phi X v)" instead? I mean, something like (a +) b doesn't make sense either.

Also, by Exp do you mean the exponential of the vector? Because I know you can take exponentials of matrices which is useful to solve differential equations, but I've never heard about exponentials of vectors to represent rotation. Can you explain this a bit more?

Share this post


Link to post
Share on other sites
I mean "Exp(phi X) v" phi and v are vectors and X means Cross!
Exp(phi X) v = (1+phiX+phiXphiX/2!+...)v =v+phi X v+1/2!*(phi X phi X v)+...
An example :

#include<stdio.h>
#include<math.h>

struct _v3
{
double x,y,z;
};
_v3 operator+(_v3 a,_v3 b){_v3 r;r.x=a.x+b.x;r.y=a.y+b.y;r.z=a.z+b.z;return r;}
_v3 operator*(double k,_v3 v){_v3 r;r.x=k*v.x;r.y=k*v.y;r.z=k*v.z;return r;}
_v3 cross(_v3 a,_v3 b)
{
_v3 r;
r.x=a.y*b.z-a.z*b.y;
r.y=-(a.x*b.z-a.z*b.x);
r.z=a.x*b.y-a.y*b.x;
return r;
}
_v3 cross2(_v3 a,_v3 b,int n)
{
if(0==n) return b;
if(1==n) return cross(a,b);
return(cross2(a,cross(a,b),n-1));
}
double fac(int n)
{
double r=1;
if(0==n)return 1.0;
for(int i=n;i>1;i--)r*=(double)i;
return r;
}
double abs(_v3 v){return(sqrt(v.x*v.x+v.y*v.y+v.z*v.z));}
int main()
{
//let us rotate <1,0,0> around <1,1,1> by 2*pi/3
//phi=(Norm<1,1,1>)*2pi/3=<2pi/3/sqrt(3),...,...>
_v3 phi={1.2092,1.2092,1.2092};
_v3 v={1,0,0};
_v3 r={0,0,0},t;
//exp x = 1+x+x^2/2!+x^3/3!+...
int i=0;
do{
t=(1./fac(i))*cross2(phi,v,i);
r=r+t;
i++;
}while(abs(t)>1e-6);
printf("<%f,%f,%f>\n",r.x,r.y,r.z);
}






Output:
<-0.000000,1.000000,0.000000>

Share this post


Link to post
Share on other sites

This topic is 4357 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.

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