Page 1 of 2

On the subject of Quaternions

Posted: Tue Mar 20, 2012 8:52 am
by Zieman
I may not be the only one to wonder what are those mysterious Quaternions, and why they are in Oolite. I bet Ahruman could give a nice, compact and easy to understand answer - before that one could read a bit:
However, quaternions have had a revival since the late 20th Century, primarily due to their utility in describing spatial rotations. The representations of rotations by quaternions are more compact and quicker to compute than the representations by matrices. In addition, unlike Euler angles they are not susceptible to gimbal lock. For this reason, quaternions are used in computer graphics,[10] computer vision, robotics, control theory, signal processing, attitude control, physics, bioinformatics, molecular dynamics, computer simulations, and orbital mechanics. For example, it is common for the attitude-control systems of spacecraft to be commanded in terms of quaternions
is a quote from the article http://en.wikipedia.org/wiki/Quaternion

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 9:58 am
by Selezen
I tried reading that article back when I started trying to make OXPs. I tried again after reading this post.
Wikipedia wrote:
In mathematics, the quaternions are a number system that extends the complex numbers. They were first described by Irish mathematician Sir William Rowan Hamilton in 1843[1][2] and applied to mechanics in three-dimensional space. A feature of quaternions is that the product of two quaternions is noncommutative. Hamilton defined a quaternion as the quotient of two directed lines in a three-dimensional space[3] or equivalently as the quotient of two vectors.[4] Quaternions can also be represented as the sum of a scalar and a vector.
I went crosseyed at the word "commutative". Again. Ironically, I use mathematics in my job, and I'm pretty sure quaternions would be useful. If I could only understand them...

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 12:30 pm
by Commander McLane
Zieman wrote:
I may not be the only one to wonder what are those mysterious Quaternions, and why they are in Oolite.
Answer in two sentences: quaternions are a mathematical way to precisely describe a rotation in three-dimensional space. And they are in Oolite because Oolite needs to rotate things in three-dimensional space.

Voilà. :D

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 12:59 pm
by Gimbal Locke
Zieman wrote:
In addition, unlike Euler angles they are not susceptible to gimbal lock.
is a quote from the article http://en.wikipedia.org/wiki/Quaternion
While quaternions may not be susceptible to me, I find this resource most helpful: http://rosettacode.org/wiki/Quaternion_type , it shows how to define and compute with quaternions in 33 programming languages.

This video shows the problem: http://www.youtube.com/watch?v=rrUCBOlJdt4

This video shows the solution: http://www.youtube.com/watch?v=2XehAXAt0DE

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 1:40 pm
by Mauiby de Fug
Non-commutative simply means that the order of operations makes a difference. For example, 2 * 3 = 3 * 2 is commutative. It doesn't matter which comes first. With quaternions, i * j = k, but j * i = -k. You get a different result.

Funnily enough, I can understand/follow almost all of that page. I think the useful bit is
Wikipedia wrote:
Conjugation by a unit quaternion (a quaternion of absolute value 1) with real part cos(θ) is a rotation by an angle 2θ, the axis of the rotation being the direction of the imaginary part.

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 2:04 pm
by Fatleaf
And for a handy tool for working them out I have acquired a !Nothing to see here! along the way. Help yourself :D

EDIT: This isn't the post you are looking for :roll:

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 2:09 pm
by Gimbal Locke
Fatleaf wrote:
And for a handy tool for working them out I have acquired a Quaternion Generator along the way. Help yourself :D
Fatleaf, that links to a Windows executable. Do you have the source code for that or is it Windows-specific?

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 3:05 pm
by Fatleaf
Gimbal Locke wrote:
Fatleaf wrote:
And for a handy tool for working them out I have acquired a Quaternion Generator along the way. Help yourself :D
Fatleaf, that links to a Windows executable. Do you have the source code for that or is it Windows-specific?
That is a good question :roll:

It works on Win7. But I don't have the source code for it. Give it a go and see if it works for you!

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 4:07 pm
by Okti

Re: On the subject of Quaternions

Posted: Tue Mar 20, 2012 5:34 pm
by Thargoid
Selezen wrote:
I went crosseyed at the word "commutative". Again. Ironically, I use mathematics in my job, and I'm pretty sure quaternions would be useful. If I could only understand them...
Commutative : A*B = B*A
Anti-Commutative : A*B = -B*A
Non-Commutative : A*B != B*A

Re: On the subject of Quaternions

Posted: Wed Mar 21, 2012 7:20 am
by PhantorGorth
This image shows why rotations are non-commutative:

Image

90 degree rotations by the z then x axes gives a different outcome for 90 degree rotations by the x then z axes.

Re: On the subject of Quaternions

Posted: Wed Mar 21, 2012 8:27 am
by Gimi
:idea: just lit in my head :mrgreen: . Thank you. (Not that I need it for anything important, but still interesting).

Re: On the subject of Quaternions

Posted: Wed Mar 21, 2012 9:34 am
by SandJ
Oh, I see! Because when you swivel the object around the vertical z axis, the sides move around but the two side-on axes x and y don't move with them.

So if you:
- turn the die over on the x or y axis, then spin it around on the z axis
that won't be the same as:
- spin it around on the z axis, then turn the die over on the x or y axis
because different sides of the die are now facing the x and y axes once the die has been spun.


I now recall an Open University TV programme from the 1980s about the huge machines the Royal Mail use to turn letters the same way up. It does 3 possible transformations:
a) the letters drop edge-on into a hopper which, when full, tips through 90 degrees and the letters carry on - used to move the stamps to the next edge along the envelope, i.e. between the y and z edges. (x axis rotation)
b) the letters pass between two belts which go through a 180 degree twist - used to get the stamps all one the same side. (y axis flip)
c) the letters stack up edge-on on a bunch and a human picks them up, turns round 180 degrees and puts them back in the machine further down the line, to get the stamps from back to front but leaving them at the top. (z axis flip)

Because the envelopes start off 'flat' in a pile, one axis need only ever need a 90 degree turn and so there are 8 possible arrangements of how the letters come into the sorting office (otherwise it would be 16). (Stamp top right, stamp top left, stamp bottom left, stamp bottom right ... x 2 for the stamp being at the back = 8 arrangements.)

They did all the horrid 3D maths and then said "But if you watch this machine, it will make sense". I remember the machine and its transformations very well; it was a huge monstrous piece of mechanised mathematical genius, but the maths fell out of my head long ago.

I did not know I had forgotten so much.

Re: On the subject of Quaternions

Posted: Mon Mar 26, 2012 10:46 am
by Staer9
Fatleaf wrote:
And for a handy tool for working them out I have acquired a Quaternion Generator along the way. Help yourself :D
I aquired (from a different source) the very same thing but was told that it is completely illegal to redistribute it in any way shape or indeed form, so you might want to remove it before said source returns to the BB and gets mad :wink:

unless of course you aquired permission, in which case I appologise :P

Re: On the subject of Quaternions

Posted: Mon Mar 26, 2012 11:56 am
by Fatleaf
Staer9 wrote:
Fatleaf wrote:
And for a handy tool for working them out I have acquired a Quaternion Generator along the way. Help yourself :D
I aquired (from a different source) the very same thing but was told that it is completely illegal to redistribute it in any way shape or indeed form, so you might want to remove it before said source returns to the BB and gets mad :wink:

unless of course you aquired permission, in which case I appologise :P
Thanks for that. The sorce I got it from failed to state that it shouldn't be shared! :roll:

Hey ho, it's gone now!