Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Quaternions

Author
Message
NeX the Fairly Fast Ferret
20
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 19th Oct 2009 16:44
Can someone who understands them please explain their meaning as simply as possible? I think the vector describes the direction and the angle describes the roll. Right?

Every article I can find on them jumps straight into the math, and it's over my head.

Ron Erickson
Moderator
22
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 19th Oct 2009 17:26
It isn't logical. You can't really look at a set of quaternion values and imagine the orientation. They are nice to work with though because they are much more stable when combining many transformations than matrices are, which helps avoid things like gimble lock. They are also nice to work with because they use less data to define (4 floats) than matrices (9 floats or 16 floats depending on how the matrix is setup).


a.k.a WOLF!
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 19th Oct 2009 20:16 Edited at: 19th Oct 2009 20:21
You can see how they work through the 2d analogy.

This wikipedia article shows how you can rotate something in 2d using sin and cos: http://en.wikipedia.org/w/index.php?title=Coordinate_rotation#In_two_dimensions

It also shows how you can use a 2x2 matrix to represent the rotation.

Compare the representation of rotation in a 2x2 matrix to the matrix representation of complex numbers:
http://en.wikipedia.org/wiki/Complex_number#Matrix_representation_of_complex_numbers

You can see that if 'a' is 'cos( θ )' and 'b' is 'sin( θ )' then the two are equivalent. This shows that you can represent rotations using complex numbers.

In the same way that complex numbers are pairs of real numbers, one of which has been multiplied by a special value called 'i' which represents the square root of -1, quaternions are pairs of complex numbers, one of which has been multiplied by a different special value, called 'j' which represents a different square root of -1.
There is also a third square root of -1 in quaternions (not including '-i' and '-j') which is 'i' multiplied by 'j', and is often called 'k'.

If you can visualize how the 2d equivalent works, then it is easy enough to realize that there IS logic to the way the 3d version works, it is just not easy for us to understand it in the same way.

@Ron
How are they better than matrices at preventing gimbal lock?

Ron Erickson
Moderator
22
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 19th Oct 2009 21:31 Edited at: 19th Oct 2009 21:31
Quote: "How are they better than matrices at preventing gimbal lock?"


I guess I wrote that sort of wrong. Matrices aren't really prone to Gimbal lock. It's the combination of rotation matrices that can be prone to Gimbal lock. This is because each axis is calculated individualy (in a set order). Euler angles (which DBpro uses) are an example of combining rotation matrices in a set order. Gimbal lock is the biggest problem with using Euler angles (which in a sense is using the combination of matrices).
On the other hand, Quaternions avoid gimbal lock by updating all three axis at the same time. Quaternions are a lot less logical, but they are much more stable to work with.
I think that is why in a lot of 3D file formats, both matrices and quaternions are used. Generally, matrices are used to describe initial rotations. Quaternions are used a lot to describe animation.


a.k.a WOLF!
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 19th Oct 2009 21:42
Another advantage of quaternions is that they can be normalized more easily. When you apply successive rotations to a quaternion or matrix, errors gradually creep in as a result of floating point inaccuracies, and these can cause an object which has this rotation applied to change in size and warp in strange ways.

The way to fix this is by every so often removing any non-rotating part of the matrix or quaternion, leaving only the pure rotation.

With matrices this is difficult and computationally expensive, because 3x3 rotation matrices can store scaling, skew and other transformations. With quaternions however, they can only hold a rotation and a uniform scale. By normalizing a quaternion (the same way you normalize a vector) you can easily remove this unwanted scaling effect.

Killer Wolf
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location:
Posted: 13th Dec 2009 19:45 Edited at: 13th Dec 2009 19:45
hi all

right - given i'm a maths numpty and understand about 1 in 10 of the words related to quaternion texts, could someone give me help w/ a quat multiplication problem please?
i'm building external camera views for a view of the player's spaceship. texts i'm working from say, eg,
q1 = 0 1 0 0 is a 180 rotation about the X axis
q2 = 0 0 1 0 is a 180 around the Y axis.
this much i understand.
my camera by default points forward along the Z axis, and using the above theory etc i've got rear, left and right views. i've even managed to get my rear camera slightly raised and looking down for a cool angle on the ship. where i'm hitting porbs is a similar looking-down angle on the front. this means rotating the camera 180 around the Y axis, and angling it down a bit around the X axis. i'm failing miserably.
i've worked out i can do this by doing a 135 rotation around X so i'm facing back and down, and a 180 around Z to bring the image the right way up. the 2 quats i reckon are :
q1 : 0 0.9238 0 0
q2 : 0 0 0 1

now, all the texts say :
"To multiply Q1 (w1, x1, y1, z1) by Q2 (w2, x2, y2, z2):-
W = w1 x w2 - x1 x x2 - y1 x y2 - z1 x z2
X = w1 x x2 + x1 x w2 + y1 x z2 - z1 x y2
Y = w1 x y2 + y1 x w2 + z1 x x2 - x1 x z2
Z = w1 x z2 + z1 x w2 + x1 x y2 - y1 x x2 "

but as you can see, everything ands up as a multiplication by zero, nilling everything. so what am i not understanding?

thanks in advance.
Jeff032
17
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 14th Dec 2009 03:17
I believe that quaternions are made up of an axis(XYZ) and a rotation around that axis(W), so in the format WXYZ using degrees:

180 around X would be {180, 1, 0, 0}
180 around Z would be {180, 0, 0, 1}
135 around X would be {135, 1, 0, 0}

-Jeff

Killer Wolf
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location:
Posted: 15th Dec 2009 19:50
that's not what i asked tho, and like i said, the versions i quoted (0100 etc) work fine.
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 15th Dec 2009 21:37
@Jeff032
They are not at all

Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 15th Dec 2009 21:49 Edited at: 15th Dec 2009 21:51
Quote: "I believe that quaternions are made up of an axis(XYZ) and a rotation around that axis(W), so in the format WXYZ using degrees:

180 around X would be {180, 1, 0, 0}
180 around Z would be {180, 0, 0, 1}
135 around X would be {135, 1, 0, 0}"


A quaternion for rotation is built as followed:

w = cos(phi / 2)
x = x * sin(phi / 2)
y = y * sin(phi / 2)
z = z * sin(phi / 2)
where (x,y,z) are the coördinates of the normalized rotational vector.

Quote: "but as you can see, everything ands up as a multiplication by zero, nilling everything. so what am i not understanding?"


That is impossible. All possible combinations of factors are used once for the new quaternion.

Quote: "q1 : 0 0.9238 0 0
q2 : 0 0 0 1"

Here x1 and z2 are not 0, so x1 * z2 would produce a result not equal to 0.
This is the case for
Quote: "Y = w1 x y2 + y1 x w2 + z1 x x2 - x1 x z2"

which will result in -x1*z2.
And indeed, the result of 180° around the X and 180° around the Z would result in 180° around the Y.

Might I add: q1 does not have a length of 1 ( |q1| = 0.9238), meaning it will also rescale the new coordinate instead of just rotating it.

Cheers!
Sven

Login to post a reply

Server time is: 2025-05-25 15:12:02
Your offset time is: 2025-05-25 15:12:02