Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Spherical Coordinates vs Quaternions?  (Read 1104 times)
0 Members and 1 Guest are viewing this topic.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Posted 2014-01-23 01: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?
Offline Dxu1994
« Reply #1 - Posted 2014-01-23 01:15:49 »

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

Offline quew8

JGO Coder


Medals: 29



« Reply #2 - Posted 2014-01-23 08: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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2014-01-23 11: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.

Online Roquen
« Reply #4 - Posted 2014-01-23 16: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.



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

http://www.iquilezles.org/www/articles/quaternions/quaternions.htm
Offline gouessej
« Reply #6 - Posted 2014-01-23 23: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
Sorry, Google Translate might help you.

Online Roquen
« Reply #7 - Posted 2014-01-24 10: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (3 views)
2014-07-29 10:59:34

E.R. Fleming (20 views)
2014-07-29 03:07:13

E.R. Fleming (8 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!