the purpose of quaternions

Started by
18 comments, last by biaze 4 years, 3 months ago
Quote:Original post by frob
Some good stuff.


That explanation of quaternions is one of the most helpful I've read. Thanks.

[size="1"]
Advertisement
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.
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
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.
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.
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.
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.
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?
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>

@Lode To pass from an element z1 of IR^3 to an element z2 of IR^3, the first must be multiplied by a quaternion q ( z2 = q * z1 ).

Here's another way to see quaternions as complex numbers : Spherical-vectors and geometric interpretation of unit quaternions

This topic is closed to new replies.

Advertisement