Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Spherical Coordinates vs Quaternions?  (Read 6467 times) 0 Members and 1 Guest are viewing this topic.
Troubleshoots

JGO Knight

Medals: 36
Exp: 7-9 months

Damn maths.

 « Posted 2014-01-23 00:10:08 »

I'm up to Chapter 7 of Modern 3D Graphics Programming but I've gotten slightly confused. It mentions using spherical coordinates for rotations around a vector, however I've heard that quaternions are preferred. What's the difference between the two and when is one used over the other?

Edit: Ahh I just browsed through the next chapter and I see that it has a whole topic devoted to quaternions. I might as well just keep this question here though; the maths is quite confusing and multiple explanations will probably help me understand.

Why are all OpenGL tutorials written in Brainf**k?
Dxu1994
 « Reply #1 - Posted 2014-01-23 00:15:49 »

Using Quats instead of Euler Angles will save you from the problem of Gimbal Lock.

quew8

JGO Knight

Medals: 53

 « Reply #2 - Posted 2014-01-23 07:59:34 »

Essentially quaternions are 4d complex numbers - I they are 4 numbers with funky ways of multiplying them, adding them etc. - and it just so happens that they can represent 3d rotations much like a 3d matrix but these have only 4 numbers and are computationally simpler to work with. The only problems are a) you have to generate a rotation matrix to actually use them b) you have to keep them normalised the whole time. c) unless you have a PhD in Mathematics or are simply extremely gifted in mathematics they make absolutely no sense. One of those things that simply works. Fine until it doesn't.
gouessej
 « Reply #3 - Posted 2014-01-23 10:00:23 »

Using Quats instead of Euler Angles will save you from the problem of Gimbal Lock.
It isn't correct, it's more complicated. There are only 2 solutions to avoid gimbal lock:
- Euler angles + non linear corrections for singularities on poles (implemented in Ardor3D)
- Unitary quaternions + non Eulerian transforms

If you use quaternions with Eulerian transforms, you don't avoid gimbal lock. I wrote a report about that at the end of my bachelor degree several years ago but I never translated it into English. Quaternions are easier to interpolate.

Julien Gouesse | Personal blog | Website | Jogamp
Roquen

JGO Kernel

Medals: 517

 « Reply #4 - Posted 2014-01-23 15:10:00 »

Quaternions are dead easy (as far as math beyond Reals is concerned).  People just insist on making them hard.

Quote
Essentially quaternions are 4d complex numbers
No...they are exactly complex numbers in 3 dimensions.  The require 4 elements because a bivector (plane element) is one element in 2D and three in 3D.  So in math speak they are a 4d vector space which is just saying they require 4 elements.

Quote
....with funky ways of multiplying them, adding them etc. - and it just so happens that they can represent 3d rotations much like a 3d matrix but these have only 4 numbers and are computationally simpler to work with.
They only add one new rule...for multiplication.

Quote
a) you have to generate a rotation matrix to actually use them
No they can be used directly.  In fact the so-called quaternion to matrix conversion is simply applying the direct formula three times, one for each: (1,0,0),(0,1,0)&(0,0,1) and shoving the result into a matrix.

Quote
b) you have to keep them normalised the whole time.
Not really required but it is desirable.  Pretty much all code bases will make some simplifying assumptions of unit magnitude and moreover the "structure" of the quaternion product make compounding of errors (in the scale) grow very lowly.

Quote
c) unless you have a PhD in Mathematics or are simply extremely gifted in mathematics they make absolutely no sense. One of those things that simply works. Fine until it doesn't.
This shouldn't be the case.  One could argue that they are easier than vectors and are certainly easier than linear algebra (for basic operations).

@gouessej:
I have no clue about what you mean by "Eulerian transforms", (it can't be anything invented by Euler) but the equivalent of gimbal lock is impossible with quaternions...the structure of the product doesn't allow it.

pitbuller
 « Reply #5 - Posted 2014-01-23 19:21:42 »

http://www.iquilezles.org/www/articles/quaternions/quaternions.htm
gouessej
 « Reply #6 - Posted 2014-01-23 22:26:09 »

@gouessej:
I have no clue about what you mean by "Eulerian transforms", (it can't be anything invented by Euler) but the equivalent of gimbal lock is impossible with quaternions...the structure of the product doesn't allow it.

I mathematically proved that if you use 3 unit quaternions and if you combine them exactly like you would do with Euler angles, you will still be bothered by the gimbal lock. The Professor Pascal Mignot wrote this formula to combine quaternions by using non eulerian transforms:
http://jeux.developpez.com/faq/math/index.php?page=transformations#Q34b

Julien Gouesse | Personal blog | Website | Jogamp
Roquen

JGO Kernel

Medals: 517

 « Reply #7 - Posted 2014-01-24 09:02:53 »

It's impossible to lose a degree of freedom with quaternions.  Anyone that says differently doesn't really understand them.  A combination of Euler angles (which are really due to Roderigues not Euler) is equivalent to a composition of three local coordinate changes.  The local part doesn't really matter (it's just the order of the terms).  The three part doesn't really matter either.

Cayley proved that any quaternion (other than zero) can represent a rotation using the formula: p' = qp(1/q) (by showing it's the same as the Roderigues equation) .  Where 'q' is a quaternion which represents the rotation, p is a bivector which represent the coordinate of the point and p' is the point after the rotation.  So the set of all quaternions which represent the same rotation vary only by their magnitude, so they only have 3 degrees of freedom (are 3D embedded in 4D)...visually they form a line through the origin (if you're choosing to think of them as a coordinate in 4D).  In the same paper he proved that the conjugate of q and 1/q are the same if ||q|| = 1 (unit magnitude) and if you're limiting yourself to unit quaternions then the equation can be reformed as p' = qpq*.  Also in the same paper he proves that the product is equivalent to the composition of rotations.

So let's say we have 3 unit quaternions (a,b,c), to be able to have gimbal lock means:

ab=a, when b != 1 or ab=b when a != 1.  Both of these conditions are impossible.  Or it means that (ab)c != a(bc), which is also impossible.  These are all very basic proven facts.

So if you see something like gimbal lock that means one of two things:  either you're mixing and matching representations or there's a flaw in your math.
Pages: [1]
 ignore  |  Print

 nelsongames (19 views) 2018-04-24 18:15:36 nelsongames (17 views) 2018-04-24 18:14:32 ivj94 (608 views) 2018-03-24 14:47:39 ivj94 (53 views) 2018-03-24 14:46:31 ivj94 (401 views) 2018-03-24 14:43:53 Solater (66 views) 2018-03-17 05:04:08 nelsongames (111 views) 2018-03-05 17:56:34 Gornova (176 views) 2018-03-02 22:15:33 buddyBro (747 views) 2018-02-28 16:59:18 buddyBro (94 views) 2018-02-28 16:45:17
 ByerN 12x KaiHH 12x SHC 10x NuclearPixels 10x Zemlaynin 10x Guerra2442 10x Damocles 6x VaTTeRGeR 5x orangepascal 4x philfrei 4x ndnwarrior15 3x mesterh 3x ags1 3x Phased 2x CommanderKeith 2x delt0r 2x
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org