## Need help with Quaternions!

### Need help with Quaternions!

I have some questions about quaternions.

I've seen lots of references to them, but have yet to see a clear
explaination of how they work.

I know that a quaternion is an method of storing a 3d orientation,
a superior (as it's smaller, and faster to compute) alternative
to a Euler matrix.

I know that a quaternion  some how represents a direction vector, and
the rotation around that vector.

I know that a quaternion Q is defined as Q = r,(vx,vy,vz), where r is
a scalar, and (vx,vt,vz) is a vector, but I'm not sure how this
relates to the description immediately above.

I've some "black box" code to convert Euler Matrices to Quaternions,
and
vice versa, but it's been of little assistance!

An application where I'd like to use quaternions is as follows:
I have a cuboid object, with associated orientation quaternion, which
I'm
trying to rest on a plane.I have the  plane normal. The object is not
quite
flat on the plane plane. It seems to me, that I could use the plane
normal
as the direction part of the quaternion, to align the object in the
plane normal axis, and retain the angle information of the quaternion,
so that the orientation in the other 2 axes perpendicular to the plane
normal is not lost.
(I hope this makes sense!)
Does this seem like a good appropriate way to use quaternions?

I'd greatly appreciate any help with any of these questions, or
pointers
to on-line places to look.

Thanks

Jim Williams

### Need help with Quaternions!

> I know that a quaternion  some how represents a direction vector, and
> the rotation around that vector.

> I know that a quaternion Q is defined as Q = r,(vx,vy,vz), where r is
> a scalar, and (vx,vt,vz) is a vector, but I'm not sure how this
> relates to the description immediately above.

It can't get much simpler or more intuitive:

If u is a _unit_ vector in 3-space, then a rotation about u as the _axis_
can be represented by the quaternion c+su, where c,s are a cosine and a
sine of the same angle, respectively.  There is some disagreement as to
whether the angle in the representation is the angle of the rotation or
_half_ the angle of the rotation -- you can come up with a reasonable
system using either representation.

### Need help with Quaternions!

Hi

In my own work in 3d worlds I found quaternions very, very useful
because compacticy, elegance and ease of use.

Quaternions are mathematical entities which you may considere as four
dimensional _r_e_a_l_
vectors. You may add, subtract couples of them and you may multiply by
real numbers (scalars) as you do with 2d or 3d vectors. Thus a
quaternion Q is a entity determined by four real (not complex) numbers

Q = (a, b, c, d)

There are four distinguished quaternions:

1 = (1, 0, 0, 0)
i = (0, 1, 0, 0)
j = (0, 0, 1, 0)
k = (0, 0, 0, 0)

which acts as a system basis, as vectors i, j, k in 3d vector system do.
You have

Q = (a, b, c, d) = a + bi + cj + dk

Because bi + cj + dk = V may be seen as a 3d vector, you may write

Q = (a, b, c, d) = a + bi + cj + dk = a + V

You may compute quaternion modules in this way

|Q| = sqrt(a^2 + b^2 + c^2 + d^2) = sqrt(a^2 + |V|^2)

Unlikely 3d vectors but likely 2d vectors (see them as complex numbers)
you may multiply two quaternions obtaining a new quaternion. Algebraic
rules are as usual but you must reminder these new rules

ii = -1 ;  ij = k ; ik = -j ;
ji = -k ;  jj = -1 ; jk = i ;
ki = j ;  kj = -i ; kk = -1

Notice that quaternion product is _n_o_t_ commutative!

The product rules yield

Q* = (a, -b, -c, -d) = a - bi -cj - dk = a - V

compulsory for conjugation. Then you have

QQ* = Q*Q = |Q|^2
Q^(-1) = Q*/|Q|^2

You may divide quaternions:

QR^(-1) = QR*/|R|^2
R^(-1)Q = R*Q/|R|^2

but writing Q/R is not allowed because QR* != R*Q. (Some authors use Q/R
for QR^(-1) and
Q\R for R^(-1)Q)

Obviously, if |Q| = 1, then Q^(-1) = Q*.

A 3d vector, V = (p, q, r) is a quaternion in this way

V = (p, q, r) = pi + qj + rk = (0, p, q, r)

and for a scalar s (_r_e_a_l_ number) you may put

s = (s, 0, 0, 0)

Let V, W be two 3d vectors. Then

VW = VxW - V.W = (-V.W, VxW)   ("x" for cross product and "." for
dot product)

The importance of quaternions in 3d work lies in the fact that they are
very related with rotations and homoteces

If you whish rotate a vector V a angle _g (in radians) around an axis
containing the vector X, you will act in this way

1) Calculate the unitary vector in the direction an sense of the axis Y
= X/|X|
2) Construct the quaternion Q = (cos_g, Y)
3) Rotate the vector V as follows

QVQ*

Doing the same but Q = (a, Z) being not unitary you obtain QVQ*, a
vector enlarged |Q|^2 times
rotated arc_cos(a/|Q|) around the axis Z.

More:
Rotation R1 -----> quaternion Q
Rotation R2 -----> quaternion R
--------------------------------------------------
Rotation R2 after Rotation R1 -----> quaternion RQ

Quaternions were invented by Sir William Rowan Hamilton and he believed
they would become an
useful language for mathematical physics at the time field theory began.
But physicists found
quaternions abstract and they preferred the language of scalars,
vectors, dot product, cross
product and the like (notice that quaternions includes all of the
concepts in a single entity!)
rendering field theory as we know it nowadays. In the other side
mathematicians quickly found other algebra systems and they created the
general theory of algebras in which quaternions are nothing than a
single example.
Maybe this facts explain why to found a clear and useful explanation of
quaternions in the literature is a hard task for us!

May be computer graphics science will recover quaternions and establish
them as a leading tool.

I hope this helps!

Carles Romero
I.E.S."Manuel Blancafort"
08530 La Garriga, Catalonia, Spain

http://www.xtec.es/~cromero/index0.htm

> I have some questions about quaternions.

> I've seen lots of references to them, but have yet to see a clear
> explaination of how they work.

> I know that a quaternion is an method of storing a 3d orientation,
> a superior (as it's smaller, and faster to compute) alternative
> to a Euler matrix.

> I know that a quaternion  some how represents a direction vector, and
> the rotation around that vector.

> I know that a quaternion Q is defined as Q = r,(vx,vy,vz), where r is
> a scalar, and (vx,vt,vz) is a vector, but I'm not sure how this
> relates to the description immediately above.

> I've some "black box" code to convert Euler Matrices to Quaternions,
> and
> vice versa, but it's been of little assistance!

> An application where I'd like to use quaternions is as follows:
> I have a cuboid object, with associated orientation quaternion, which
> I'm
> trying to rest on a plane.I have the  plane normal. The object is not
> quite
> flat on the plane plane. It seems to me, that I could use the plane
> normal
> as the direction part of the quaternion, to align the object in the
> plane normal axis, and retain the angle information of the quaternion,

> so that the orientation in the other 2 axes perpendicular to the plane

> normal is not lost.
> (I hope this makes sense!)
> Does this seem like a good appropriate way to use quaternions?

> I'd greatly appreciate any help with any of these questions, or
> pointers
> to on-line places to look.

> Thanks

> Jim Williams

### Need help with Quaternions!

Sorry! sorry!

There was a mistake in my response

Rotating and angle _g requires the quaternion (cos (_g/2), X)

I apologise for the bad information!

Carles Romero
I.E.S."Manuel Blancafort"
08530 La Garriga, Catalonia, Spain

http://www.xtec.es/~cromero/index0.htm

> I have some questions about quaternions.

> I've seen lots of references to them, but have yet to see a clear
> explaination of how they work.

> I know that a quaternion is an method of storing a 3d orientation,
> a superior (as it's smaller, and faster to compute) alternative
> to a Euler matrix.

> I know that a quaternion  some how represents a direction vector, and
> the rotation around that vector.

> I know that a quaternion Q is defined as Q = r,(vx,vy,vz), where r is
> a scalar, and (vx,vt,vz) is a vector, but I'm not sure how this
> relates to the description immediately above.

> I've some "black box" code to convert Euler Matrices to Quaternions,
> and
> vice versa, but it's been of little assistance!

> An application where I'd like to use quaternions is as follows:
> I have a cuboid object, with associated orientation quaternion, which
> I'm
> trying to rest on a plane.I have the  plane normal. The object is not
> quite
> flat on the plane plane. It seems to me, that I could use the plane
> normal
> as the direction part of the quaternion, to align the object in the
> plane normal axis, and retain the angle information of the quaternion,

> so that the orientation in the other 2 axes perpendicular to the plane

> normal is not lost.
> (I hope this makes sense!)
> Does this seem like a good appropriate way to use quaternions?

> I'd greatly appreciate any help with any of these questions, or
> pointers
> to on-line places to look.

> Thanks

> Jim Williams

### Need help with Quaternions!

Just a brief note.  Quaternions are used a lot in flight simulation,
and I have seen discussions of them in a couple of good flight
simulation textbooks.  (I got interested in flight simulation,
briefly, a few years ago.)

I don't have references handy, unfortunately, but ask the question
over in sci.aeronautics.simulation and you should get some good
references.

says...

>Maybe this facts explain why to found a clear and useful explanation
of
>quaternions in the literature is a hard task for us!

>> I've seen lots of references to them, but have yet to see a clear
>> explaination of how they work.

### Need help with Quaternions!

> Just a brief note.  Quaternions are used a lot in flight simulation,
> and I have seen discussions of them in a couple of good flight
> simulation textbooks.  (I got interested in flight simulation,
> briefly, a few years ago.)

Not only in flightsimulation, just anything that uses keyframing uses
quaternions (almost)

> I don't have references handy, unfortunately, but ask the question
> over in sci.aeronautics.simulation and you should get some good
> references.

> says...
> >Maybe this facts explain why to found a clear and useful explanation
> of
> >quaternions in the literature is a hard task for us!

> >> I've seen lots of references to them, but have yet to see a clear
> >> explaination of how they work.

Well, I searched the net for a while and had plenty of accurate document
about quaternions. Also every book on Animation talks about quaternions.
Really there's enough info out there, you just need to know where to
look......

### Need help with Quaternions!

...

> >> I've seen lots of references to them, but have yet to see a clear
> >> explaination of how they work.

Quaternions were originally invented by Hamilton in an attempt to extend
complex numbers to more than 2 dimensions.  They weren't entirely
successful for his intended purpose, but they have found a lot of use in
aerospace because they provide a way of doing arbitrary rotations that
have no singularities.  They are also faster, since fewer operations are
required to multiply quaternions compared to multiplying transformation
matrices.

When used for rotations, they work like this:  A quaternion has 4
elements.  Three elements define a vector and the fourth defines the
amount of rotation about the vector to go from one orientation to
another.  Any rotation that you'd do with three Euler angles can be done
with a single quaternion.  BTW, it turns out that for spacecraft, this
is the minimum fuel way of getting from one orientation to another, so
quaternions are the method of choice for programming one's attitude
control.

The quaternion is defined as:
q = q1i + q2j +q3k + q4
where
i^2 = j^2 = k^2 = -1
ij = -ji = k
jk = -kj = i
ki = -ik = j

and the conjgate or inverse of q is

q* = -q1i - q2j - q3k + q4

Successive rotations are done by multiplying the quaternions:

q'' = q q' = (q1i + q2j +q3k + q4)(q1'i + q2'j +q3'k + q4')
q'' = ( q1q4'+q2q3'-q3q2'+q4q1')i +
(-q1q3'+q2q4'+q3q1'+q4q2')j +
( q1q2'-q2q1'+q3q4'+q4q3')k +
(-q1q1'-q2q2'-q3q3'+q4q4')

Given a 3x3 direction cosine matrix, A, with elements a11, a12, ..., one
way (there are 3 others) to get the elements of the equivalent
quaternion is:

q4 = +- 1/2 (1 + a11 + a22 + a33)^(1/2)
q1 = (a23-a32)/(4 q4)
q2 = (a31-a13)/(4 q4)
q3 = (a12-a21)/(4 q4)

Going the other way:

a11 = q1^2 - q2^2 - q3^2 + q4^2
a12 = 2(q1q2 + q3q4)
a13 = 2(q1q3 - q2q4)
a21 = 2(q1q2 - q3q4)
a22 = -q1^2 + a2^2 - q3^2 + q4^2
a23 = 2(q2q3 + q1q4)
a31 = 2(q1q3 + q2q4)
a32 = 2(q2q3 - q1q4)
a33 = -q1^2 - q2^2 + q3^2 +q4^2

(If I've made any typo's, it's "do as I mean, not as I say")
References:

Hamilton, Sir W.R., "Elements of Quaternions," London: Longmans, Green &
Co., 1866.

Whittaker, E.T., "A Treatise on the Analytical Dynamics of Particles and
Rigid Bodies," Cambridge:  Cambridge University Press, 1961.

Wertz, J.R.(ed), "Spacecraft Attitude Determination and Control,"
Boston: D. Reidel Publishing Co., 1978 (reprinted 1980, 1984).

Good luck,

Tom Speer

Does anyone know where I can get some info on the net for Quaternion->Euler
angles conversion? I got the reverse from somewhere Euler->Quaternion but I
really want the former. I'd really like to know where I can get some
implementation of a camera using quaternions from somewhere too. Thank you