Quaternion newbie needs help

W

wannabe geek

I am attempting to use quaternions for the first time, experimenting with 3D
rotation. I can't understand or control them. I thought they were used for
rotation only, but I am noticing strange scaling effects as well. Does this
have something to do with their 4-dimensionality? Could someone help me or
direct me to a site that explains quaternion rotation in WPF? Not
quaternions, but quaternion rotation.
 
W

wannabe geek

wannabe geek said:
I thought (quaternions) were used for
rotation only, but I am noticing strange scaling effects as well. Does this
have something to do with their 4-dimensionality?

I believe my unwanted scaling was because my quaternions were not normalized
unit vectors.
 
F

Fred Mellender

wannabe geek said:
I am attempting to use quaternions for the first time, experimenting with
3D
rotation. I can't understand or control them. I thought they were used
for
rotation only, but I am noticing strange scaling effects as well. Does
this
have something to do with their 4-dimensionality? Could someone help me or
direct me to a site that explains quaternion rotation in WPF? Not
quaternions, but quaternion rotation.

http://www.codeproject.com/KB/graphics/YLScsDrawing3d.aspx
http://www.flipcode.com/documents/matrfaq.html
 
W

wannabe geek

Fred Mellender said:

Is there a website or person anywhere that can explain in simple terms what
each of the 4 values in a quaternion does, and how they all work together to
achieve the desired result? Or should I use AxisAngle rotations and convert
them to quaternions to take advantage of that extra dimension? Or try to
figure them out on my own? Or scrap the quaternions idea?
 
P

Peter Duniho

wannabe said:
Is there a website or person anywhere that can explain in simple terms what
each of the 4 values in a quaternion does, and how they all work together to
achieve the desired result? Or should I use AxisAngle rotations and convert
them to quaternions to take advantage of that extra dimension? Or try to
figure them out on my own? Or scrap the quaternions idea?

Quaternions should be very useful, if you need them. They provide a
compact, efficient way to represent and calculate rotations in 3D space.

Unfortunately, as is the case for most of the WPF documentation, there
is little in the way of guidance as to how to use the Quaternion
structure. The docs assume you already know what one is, and how it's
to be used.

IMHO, the Wikipedia article on the topic is reasonably good. You can
read up on the actual math, but the article specifically about spatial
rotation is probably more to the point:
http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

With respect to your specific question – "explain in simple terms what
each of the 4 values in a quaternion does" – there's not really a way to
describe that per se, because each value has little meaning by itself
outside the quaternion. However, as you can see from the article above,
the x, y, and z values relate to the vector describing the axis of
rotation, and the w value relates to the amount of rotation.

Note, however, that w isn't actually the amount of rotation per se; you
simply can calculate it based on that. Also, the vector portion (x, y,
and z) also depends on the amount of rotation: it's a unit vector
multiplied by the sine of half the angle of rotation.

Fortunately, WPF doesn't really require you to know all that. You can
work in plain vectors and angles, and it will do the rest for you.

The short version:

– Given a known rotation, you can create a Quaternion value based on
the axis about which the rotation occurs (Vector3D) and the amount of
rotation (double, in degrees). See the Quaternion(Vector3D, double)
constructor overload.

– Given a quaternion, you can rotate a Matrix3D (e.g. the basic
identity matrix) by the rotation indicated by the Quaternion. See the
Matrix3D.Rotate(Quaternion) method, and similar.

– While most of the time you will want to rely on the Matrix3D to set
up a single transform applied to a full world of objects, you can rotate
individual vectors by the Quaternion using the Conjugate() method.

– If you have a known starting rotation and a known ending rotation,
both represented as Quaternions, you can use the Quaternion.Slerp()
method to interpolate between them, for the purpose of smoothly
animating the rotation. Slerp() will calculate intermediate Quaternion
values which you can use for the intermediate rotations for the animation.

– If you have a known rotation and want to compose a new rotation,
both represented as Quaternions, you can simply multiply the first by
the second. This will produce a new, third Quaternion value that is the
composition of the original two.

Note that WPF provides matrix-based rotation support that also allow
specification of rotation in terms of axis and angle. Composition of
those is simply by matrix multiplication as usual. So strictly
speaking, for simply dealing with static rotations, you don't need the
Quaternion support. The place where it's especially useful is when you
would like to interpolate between one known rotation and another.

Finally, you may find value in reviewing the "Graphics and Multimedia"
section of the WPF documentation. There's nothing detailed about
quaternions, at least not that I know of, but at least there's some
samples and brief descriptions of dealing with rotations, both with and
without quaternions. You can start here:
http://msdn.microsoft.com/en-us/library/ms752061.aspx

Pete
 
V

vanderghast

Charles Petzold, in his "3D Programming for Windows", Microsoft Press, gives
a decent explanation, pp 337-366.

I prefer to select the axis about which the rotation has to occur, than to
use quaternion.


Vanderghast, Access MVP
 
J

John Rivers

I like to keep orientations in Quaternions until the last possible
moment - then convert to a matrix

So a camera that supports yaw and pitch would use Yaw and Pitch
variables
then create a Quaternion from those variables
and any other objects could use that Quaternion to create modified
orientations (wobbling etc.)
because the quaternion is the most flexible (and light) orientation
encoding
then - right at the end - convert to a matrix for rendering

if you are continually modifying a single quaternion - you need to
normalize it at regular intervals
(say after every 50 multiplications)
 
V

vanderghast

They are nice for 'automated' animations (computed generated intermediate
scenes between a starting and an ending position).

Vanderghast, Access MVP
 
W

wannabe geek

Peter Duniho said:
Quaternions should be very useful, if you need them. They provide a
compact, efficient way to represent and calculate rotations in 3D space.

Unfortunately, as is the case for most of the WPF documentation, there
is little in the way of guidance as to how to use the Quaternion
structure. The docs assume you already know what one is, and how it's
to be used.

IMHO, the Wikipedia article on the topic is reasonably good. You can
read up on the actual math, but the article specifically about spatial
rotation is probably more to the point:
http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

With respect to your specific question – "explain in simple terms what
each of the 4 values in a quaternion does" – there's not really a way to
describe that per se, because each value has little meaning by itself
outside the quaternion. However, as you can see from the article above,
the x, y, and z values relate to the vector describing the axis of
rotation, and the w value relates to the amount of rotation.

Note, however, that w isn't actually the amount of rotation per se; you
simply can calculate it based on that. Also, the vector portion (x, y,
and z) also depends on the amount of rotation: it's a unit vector
multiplied by the sine of half the angle of rotation.

Fortunately, WPF doesn't really require you to know all that. You can
work in plain vectors and angles, and it will do the rest for you.

The short version:

– Given a known rotation, you can create a Quaternion value based on
the axis about which the rotation occurs (Vector3D) and the amount of
rotation (double, in degrees). See the Quaternion(Vector3D, double)
constructor overload.

– Given a quaternion, you can rotate a Matrix3D (e.g. the basic
identity matrix) by the rotation indicated by the Quaternion. See the
Matrix3D.Rotate(Quaternion) method, and similar.

– While most of the time you will want to rely on the Matrix3D to set
up a single transform applied to a full world of objects, you can rotate
individual vectors by the Quaternion using the Conjugate() method.

– If you have a known starting rotation and a known ending rotation,
both represented as Quaternions, you can use the Quaternion.Slerp()
method to interpolate between them, for the purpose of smoothly
animating the rotation. Slerp() will calculate intermediate Quaternion
values which you can use for the intermediate rotations for the animation.

– If you have a known rotation and want to compose a new rotation,
both represented as Quaternions, you can simply multiply the first by
the second. This will produce a new, third Quaternion value that is the
composition of the original two.

Note that WPF provides matrix-based rotation support that also allow
specification of rotation in terms of axis and angle. Composition of
those is simply by matrix multiplication as usual. So strictly
speaking, for simply dealing with static rotations, you don't need the
Quaternion support. The place where it's especially useful is when you
would like to interpolate between one known rotation and another.

Finally, you may find value in reviewing the "Graphics and Multimedia"
section of the WPF documentation. There's nothing detailed about
quaternions, at least not that I know of, but at least there's some
samples and brief descriptions of dealing with rotations, both with and
without quaternions. You can start here:
http://msdn.microsoft.com/en-us/library/ms752061.aspx

Pete
.

I gather that quaternions are maybe not as useful as I thought? They can
avoid gimbal lock (I don't know how that would happen in WPF 3D) and
supposedly create smoother animation or something. But you can do that with
AxisAngle rotations or what?
 
V

vanderghast

Definitively, you can switch to a standard matrix notation, it is just that
each terms is more complex (not as in square root of -1, but as involving
many terms), but that complexity is generally hidden to you by the procedure
you call.

Quaternions have been promoted by Hamilton, but as reported by Petzold,
"James Clerk Maxwell used quaternions in a limited, rather unorthodox manner
in his influential Treatise on Electricity and Magnetism (1873), which
suggested to some readers that quaternions were more useful without the
scalar part." (which is ironic, by the way, since they are then... 3D
vectors). In fact, a quaternion generally expressed as:

scalar + vector

is an oxymoron, since the + is out of its usual meaning: remember that we
cannot add apples with oranges, neither scalar and vector, so the + just
stands as "tied together", like fields (members) of a class are "tied
together", we could say. As example, we can use a quaternion to store
Temperature (the scalar) at a given 3D point (vector). It is not, in
general, a real additive +. It just happens that using quaternions, and
some process on them (process more or less remotely similar to complex
numbers and 2D geometry) we can define useful rotation about an arbitrary
axis if the scalar is the cosinus of half the angle of rotation, and the
vector, the direction of the axis (passing trough the origine) times the
scalar value of the sinus of half the angle of rotation. And to effectively
produce a rotation, the involved math does not end there, is not trivial and
many authors (as Peter Walsh in one of his many DirectX book does) would
rather prove that the quaternion math just produce the same result, in the
end, than a more classical (even if, historically, it came after) already
proven matrix/geometry based result. Note that the first book about vector
analysis was published in 1901
(http://www.charlespetzold.com/blog/2006/07/250713.html), quite after
Hamilton's quaternion... which still can be seen as some odd extension to 3D
of complex numbers (that is where I suggest to consult Petzold book, if I
arose your curiosity on that matter).



Vanderghast, Access MVP
 
P

Peter Duniho

wannabe said:
I gather that quaternions are maybe not as useful as I thought?

That depends entirely on just how useful you thought they are. If you
thought that quaternions would solve every programming problem you've
ever run into, well…sure, they definitely aren't as useful as that.

On the other hand, if you thought that quaternions were a convenient way
to represent and compose rotations, in particularly to interpolate new
rotations between two given rotations, then they would have been exactly
as useful as you thought.
They can
avoid gimbal lock (I don't know how that would happen in WPF 3D)

You could run into gimbal lock if you were processing your rotations in
a particular way. I'm not an expert there, but I believe you'd be
correct to think that quaternions aren't the only way to avoid that.
and
supposedly create smoother animation or something. But you can do that with
AxisAngle rotations or what?

I don't think that offers the interpolation features of quaternions.

Pete
 
N

noel hughes

go to my website,

noelhughes.net

I have several papers on quaternions. The quaternion training is a good place to start, although I recently noticed a typographic error in it that I will fix when i get time.



wannabe geek wrote:

:Is there a website or person anywhere that can explain
18-Feb-10


Is there a website or person anywhere that can explain in simple terms wha
each of the 4 values in a quaternion does, and how they all work together t
achieve the desired result? Or should I use AxisAngle rotations and conver
them to quaternions to take advantage of that extra dimension? Or try t
figure them out on my own? Or scrap the quaternions idea

-

Wannabe Geek

Previous Posts In This Thread:

Quaternion newbie needs help
I am attempting to use quaternions for the first time, experimenting with 3
rotation. I cannot understand or control them. I thought they were used fo
rotation only, but I am noticing strange scaling effects as well. Does thi
have something to do with their 4-dimensionality? Could someone help me o
direct me to a site that explains quaternion rotation in WPF? No
quaternions, but quaternion rotation

-

Wannabe Geek

:I believe my unwanted scaling was because my quaternions

I believe my unwanted scaling was because my quaternions were not normalize
unit vectors

-

Wannabe Geek

http://www.codeproject.com/KB/graphics/YLScsDrawing3d.aspxhttp://www.flipcode.
http://www.codeproject.com/KB/graphics/YLScsDrawing3d.asp
http://www.flipcode.com/documents/matrfaq.html

:Is there a website or person anywhere that can explain

Is there a website or person anywhere that can explain in simple terms wha
each of the 4 values in a quaternion does, and how they all work together t
achieve the desired result? Or should I use AxisAngle rotations and conver
them to quaternions to take advantage of that extra dimension? Or try t
figure them out on my own? Or scrap the quaternions idea

-

Wannabe Geek

wannabe geek wrote:Quaternions should be very useful, if you need them.
wannabe geek wrote

Quaternions should be very useful, if you need them. They provide
compact, efficient way to represent and calculate rotations in 3D space

Unfortunately, as is the case for most of the WPF documentation, ther
is little in the way of guidance as to how to use the Quaternio
structure. The docs assume you already know what one is, and how it i
to be used

IMHO, the Wikipedia article on the topic is reasonably good. You ca
read up on the actual math, but the article specifically about spatia
rotation is probably more to the point
http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotatio

With respect to your specific question ??? "explain in simple terms wha
each of the 4 values in a quaternion does" ??? there is not really a way t
describe that per se, because each value has little meaning by itsel
outside the quaternion. However, as you can see from the article above
the x, y, and z values relate to the vector describing the axis o
rotation, and the w value relates to the amount of rotation

Note, however, that w is not actually the amount of rotation per se; yo
simply can calculate it based on that. Also, the vector portion (x, y
and z) also depends on the amount of rotation: it is a unit vecto
multiplied by the sine of half the angle of rotation

Fortunately, WPF does not really require you to know all that. You ca
work in plain vectors and angles, and it will do the rest for you

The short version

??? Given a known rotation, you can create a Quaternion value based o
the axis about which the rotation occurs (Vector3D) and the amount o
rotation (double, in degrees). See the Quaternion(Vector3D, double)
constructor overload.

??? Given a quaternion, you can rotate a Matrix3D (e.g. the basic
identity matrix) by the rotation indicated by the Quaternion. See the
Matrix3D.Rotate(Quaternion) method, and similar.

??? While most of the time you will want to rely on the Matrix3D to set
up a single transform applied to a full world of objects, you can rotate
individual vectors by the Quaternion using the Conjugate() method.

??? If you have a known starting rotation and a known ending rotation,
both represented as Quaternions, you can use the Quaternion.Slerp()
method to interpolate between them, for the purpose of smoothly
animating the rotation. Slerp() will calculate intermediate Quaternion
values which you can use for the intermediate rotations for the animation.

??? If you have a known rotation and want to compose a new rotation,
both represented as Quaternions, you can simply multiply the first by
the second. This will produce a new, third Quaternion value that is the
composition of the original two.

Note that WPF provides matrix-based rotation support that also allow
specification of rotation in terms of axis and angle. Composition of
those is simply by matrix multiplication as usual. So strictly
speaking, for simply dealing with static rotations, you do not need the
Quaternion support. The place where it is especially useful is when you
would like to interpolate between one known rotation and another.

Finally, you may find value in reviewing the "Graphics and Multimedia"
section of the WPF documentation. There is nothing detailed about
quaternions, at least not that I know of, but at least there is some
samples and brief descriptions of dealing with rotations, both with and
without quaternions. You can start here:
http://msdn.microsoft.com/en-us/library/ms752061.aspx

Pete

Charles Petzold, in his "3D Programming for Windows", Microsoft Press, givesa
Charles Petzold, in his "3D Programming for Windows", Microsoft Press, gives
a decent explanation, pp 337-366.

I prefer to select the axis about which the rotation has to occur, than to
use quaternion.


Vanderghast, Access MVP

I like to keep orientations in Quaternions until the last possiblemoment -
I like to keep orientations in Quaternions until the last possible
moment - then convert to a matrix

So a camera that supports yaw and pitch would use Yaw and Pitch
variables
then create a Quaternion from those variables
and any other objects could use that Quaternion to create modified
orientations (wobbling etc.)
because the quaternion is the most flexible (and light) orientation
encoding
then - right at the end - convert to a matrix for rendering

if you are continually modifying a single quaternion - you need to
normalize it at regular intervals
(say after every 50 multiplications)

They are nice for 'automated' animations (computed generated
They are nice for 'automated' animations (computed generated intermediate
scenes between a starting and an ending position).

Vanderghast, Access MVP

:I gather that quaternions are maybe not as useful as I
:


I gather that quaternions are maybe not as useful as I thought? They can
avoid gimbal lock (I do not know how that would happen in WPF 3D) and
supposedly create smoother animation or something. But you can do that with
AxisAngle rotations or what?

--

Wannabe Geek

Definitively, you can switch to a standard matrix notation, it is just
Definitively, you can switch to a standard matrix notation, it is just that
each terms is more complex (not as in square root of -1, but as involving
many terms), but that complexity is generally hidden to you by the procedure
you call.

Quaternions have been promoted by Hamilton, but as reported by Petzold,
"James Clerk Maxwell used quaternions in a limited, rather unorthodox manner
in his influential Treatise on Electricity and Magnetism (1873), which
suggested to some readers that quaternions were more useful without the
scalar part." (which is ironic, by the way, since they are then... 3D
vectors). In fact, a quaternion generally expressed as:

scalar + vector

is an oxymoron, since the + is out of its usual meaning: remember that we
cannot add apples with oranges, neither scalar and vector, so the + just
stands as "tied together", like fields (members) of a class are "tied
together", we could say. As example, we can use a quaternion to store
Temperature (the scalar) at a given 3D point (vector). It is not, in
general, a real additive +. It just happens that using quaternions, and
some process on them (process more or less remotely similar to complex
numbers and 2D geometry) we can define useful rotation about an arbitrary
axis if the scalar is the cosinus of half the angle of rotation, and the
vector, the direction of the axis (passing trough the origine) times the
scalar value of the sinus of half the angle of rotation. And to effectively
produce a rotation, the involved math does not end there, is not trivial and
many authors (as Peter Walsh in one of his many DirectX book does) would
rather prove that the quaternion math just produce the same result, in the
end, than a more classical (even if, historically, it came after) already
proven matrix/geometry based result. Note that the first book about vector
analysis was published in 1901
(http://www.charlespetzold.com/blog/2006/07/250713.html), quite after
Hamilton's quaternion... which still can be seen as some odd extension to 3D
of complex numbers (that is where I suggest to consult Petzold book, if I
arose your curiosity on that matter).



Vanderghast, Access MVP

wannabe geek wrote:That depends entirely on just how useful you thought they
wannabe geek wrote:

That depends entirely on just how useful you thought they are. If you
thought that quaternions would solve every programming problem you have
ever run into, well???sure, they definitely are not as useful as that.

On the other hand, if you thought that quaternions were a convenient way
to represent and compose rotations, in particularly to interpolate new
rotations between two given rotations, then they would have been exactly
as useful as you thought.


You could run into gimbal lock if you were processing your rotations in
a particular way. I am not an expert there, but I believe you would be
correct to think that quaternions are not the only way to avoid that.


I do not think that offers the interpolation features of quaternions.

Pete


Submitted via EggHeadCafe - Software Developer Portal of Choice
BizTalk Configure and Send SMTP Mail Based on Message Within an Orchestration
http://www.eggheadcafe.com/tutorial...1-a2f309a021c2/biztalk-configure-and-sen.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top