PDA

View Full Version : Quternion


wamo
04-12-2008, 04:02 AM
Hi TDs,
during researching and looking at refrences i saw sometimes people uses quternion in their rotation space,i really can't undestand it so good also explaining as well,and i really need to understand it and use it,because i road lots of people's papers that they said Quaternion is the only solution for some problems and twisting situations.

I was wondering if you TDs can help me to understand it better than ever...
even a line of script with explaniation would be great.

Cheers,
Ehsan.

eek
04-12-2008, 05:29 AM
Hi TDs,
during researching and looking at refrences i saw sometimes people uses quternion in their rotation space,i really can't undestand it so good also explaining as well,and i really need to understand it and use it,because i road lots of people's papers that they said Quaternion is the only solution for some problems and twisting situations.

I was wondering if you TDs can help me to understand it better than ever...
even a line of script with explaniation would be great.

Cheers,
Ehsan.



A good way of understanding a quaternion is to understand rotation - a rotation isnt really how we 'percieve'it, in math you have matrix transformations which are 3 vectors which denote the x y and z. And a fourth vector the offset from the world.

In quaternions you have a vector and theta (v,w) - the vector in simple terms denotes the direction of the rotation i.e the aim. Theta denotes twist about this direction. But you musnt think of the vector as a standard x y z, because the fourth component theta is part of the system, i.e changing this also changes the vector this is because of the equation:

i^2 = j^2 = k^2 = ijk = -1

or

cos(a/2) + 180 ( x * sin(a/2)) + 180* (y * sin(a/2)) + 180*( z * sin(a/2))

where 'a' denotes the twist about the direction (aim) xyz

loked
04-12-2008, 08:45 AM
a rotation isnt really how we 'percieve'it, in math you have matrix transformations which are 3 vectors which denote the x y and z. And a fourth vector the offset from the world.

This is not entirely accurate... a transformation matrix is a multi dimensional array ... which is basically a vector of vectors and in a transformation matrix, you have three 4x4 matrices that are concatenated and essentially hold the an x matrix, y matrix and z matrix for the angles. The order in which you multiply these matrices is basically what rotate order is on a transform in your 3d package. You really cant represent a rotation with just a vector. You can represent a rotation with an axis and angle, then there is eulers and lastly quaternions (there might be more, but these are the major ones that 3d packages would use)... the big problem with quaternions is that people that want to use them try to visualize them like you would eulers or a vector. The thing is you need to think of it as a mathematical representation that handles certain calculations (interpolation in this case), much more accurately than eulers would. Sorry if I'm misunderstanding what you're saying above, it just didnt seem very clear when I read it.

There is an entire 600 page book on quaternions, but for a TD's sake all you really have to know is that you can convert a standard rotation matrix or eulers into a quaternion representation, then when you lerp (linear interpolation) quaternions will find the most efficient path to wherever you are rotating it. If you use eulers in a package like maya and try and set a bunch of keyframes on different axis and then let maya interpolate you'll notice that it does some weird things. Quaternions fixes this problem and essentially gains you smoother interpolation between angles. I would recommend downloading some sample C code that has a quaternion class implemented and try to make sense of some of the math.

Hope this clears things up a little... the fact is this is really more a mathematical thing than a "CG/rigging" thing...

Good Luck ;)
Judd

IkerCLoN
04-12-2008, 12:37 PM
This was very helpful to me to understand the principles of quaternions:

http://www.isner.com/tutorials/quatSpells/quaternion_spells_14.htm

Buexe
04-12-2008, 02:34 PM
You really cant represent a rotation with just a vector.
But you can do that with 3 vectors and I guess that is what eek was referring to. When you have an identity matrix:
1000
0100
0010
0001
You can take the first row as a vector for where your x-axis is pointing, second row for y-axis and third for z-axis. So each single vector doesn`t represent an orientation or a rotation, but all combined do. So understanding this, allows to manipulate the matrix by very simple means, for example mirroring the transformation across an axis.

wamo
04-12-2008, 04:41 PM
i^2 = j^2 = k^2 = ijk = -1

or

cos(a/2) + 180 ( x * sin(a/2)) + 180* (y * sin(a/2)) + 180*( z * sin(a/2))

where 'a' denotes the twist about the direction (aim) xyz






eek thanks for reply ,what i could understand from what you said is : start learning matrix books and fall into matrix math,also this equation is abit hard to get it,if you can explain it more...


There is an entire 600 page book on quaternions

thanks dude it's clear,but can you introduce this book!!?


http://www.isner.com/tutorials/quat...n_spells_14.htm

hey bud,it's a perfect tutorial ,thanks for good reply..

labbejason
04-12-2008, 05:11 PM
Oh boy, I JUST woke up and decided to read this thread. I'll have to come back to it :P

eek
04-12-2008, 09:10 PM
This is not entirely accurate... a transformation matrix is a multi dimensional array ... which is basically a vector of vectors and in a transformation matrix, you have three 4x4 matrices that are concatenated and essentially hold the an x matrix, y matrix and z matrix for the angles. The order in which you multiply these matrices is basically what rotate order is on a transform in your 3d package. You really cant represent a rotation with just a vector. You can represent a rotation with an axis and angle, then there is eulers and lastly quaternions (there might be more, but these are the major ones that 3d packages would use)... the big problem with quaternions is that people that want to use them try to visualize them like you would eulers or a vector. The thing is you need to think of it as a mathematical representation that handles certain calculations (interpolation in this case), much more accurately than eulers would. Sorry if I'm misunderstanding what you're saying above, it just didnt seem very clear when I read it.

There is an entire 600 page book on quaternions, but for a TD's sake all you really have to know is that you can convert a standard rotation matrix or eulers into a quaternion representation, then when you lerp (linear interpolation) quaternions will find the most efficient path to wherever you are rotating it. If you use eulers in a package like maya and try and set a bunch of keyframes on different axis and then let maya interpolate you'll notice that it does some weird things. Quaternions fixes this problem and essentially gains you smoother interpolation between angles. I would recommend downloading some sample C code that has a quaternion class implemented and try to make sense of some of the math.

Hope this clears things up a little... the fact is this is really more a mathematical thing than a "CG/rigging" thing...

Good Luck ;)
Judd


Hey Judd, hows Kevin Hayes over at your work? :) - remember also matrix mutiplication that a matrix can only multiply by another matrix or n-dimensional vector if it has the same amount of columns as the subsequent rows. i.e

1 2 3__1 2 _____________________1 2 3 _1 2
4 5 6 * 3 4_____will work however_4 5 6 * 3 4_wont.
7 8 9 __5 6_____________________7 8 8



Also in common terms as I know then you would have a 3X4 matrix and not a 4X4 matrix - as in the case:
matrix3 1

[1,0,0] [0,1,0] [0,0,1] [0,0,0]

1 0 0
0 1 0
0 0 1
0 0 0




To Buexe,

Exactly Correct :), i tend to skip the semantics because im looking at the system as a whole.

Maybe, just maybe I'll show of some major powerful features of quaternions - when using them in the form of spinors. If you study the belt-trick or duriac your'll know that for a rotation to resolve itself past 360 it has to go another 360 degrees - the nice thing about this is that it allows for rotation of -360 to +360.

You do this with a plate its called the 'waiter trick' - take a plate with you hand holding under it out in front of you. Then start to rotate you hand towards your side clockwise then until its out away from you - now start to bring your elbow up and keep rotating your hand - this is 360 degrees - now bring you elbow back down and keep rotating your hand - this is another 360 degree back to the start position - 720 degrees :)

In 1800s, when the quaternion was invented it wasnt used as a method for rotation, it was just developed because Hamilton couldnt get 3 dimensional number systems to work, when he tried 4 dimensions it worked.

An euler based system, doesnt respect the system as a whole, i.e in a quaternion the spin, fazer or twist of the direction also affects the direction and vice versa. Why is this?

A quaternion is denoted by 3 imaginary dimensions and 1 real dimension, each imaginary dimension has a unit value of the square root of -1 all mutually perpedicular to each other ( you could say similair to an othogonalized transform matrix) so this is a way of understanding it:


(a)realPart + (imaginaryPart * b) + (imaginaryPart *c) + (imaginaryPart * d)


I, J, and K are essentially quaternions of 180 degrees about the x y and z axis this is why i^2 = -1 = 360 degrees. So 1 and -1 both represent 360 degrees i.e 0. So when it gets rotated by 360 degrees it gets invert and needs another 360 degrees to go back to 0. i.e


(a)realPart + (imaginaryPart * b) + (imaginaryPart *c) + (imaginaryPart * d)

is the same as

(a)realPart - (imaginaryPart * b) - (imaginaryPart *c) - (imaginaryPart * d)

This site can explain better: http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/index.htm

Buexe
04-12-2008, 10:53 PM
I guess eek is trying to get the fuses of us simple earthlings to boil here : )
Quaternions belong to complex numbers, I guess it is clear now that they deserve this name ; ). The good news is that one can use them without fully understanding the mathematics behind it. Of course the more you kow about them the better, but if you are working with some sort of API, there is probably already some sort of class to work with Quaternions, so you can do your slerp ("morphing" from one rotation into another) or whatever without knowing the exact math behind it.
Cheers
PS: How can I do the waiter trick if I need to rotate a character`s leg beyond 360 degrees ?
: )

eek
04-12-2008, 11:58 PM
I guess eek is trying to get the fuses of us simple earthlings to boil here : )
Quaternions belong to complex numbers, I guess it is clear now that they deserve this name ; ). The good news is that one can use them without fully understanding the mathematics behind it. Of course the more you kow about them the better, but if you are working with some sort of API, there is probably already some sort of class to work with Quaternions, so you can do your slerp ("morphing" from one rotation into another) or whatever without knowing the exact math behind it.
Cheers
PS: How can I do the waiter trick if I need to rotate a character`s leg beyond 360 degrees ?
: )


Yes, very true - firstly Quaternions are very hard to understand and im still trying to get the 'idea' of complex numbers. Take primes for example, Rienmans conjecture is still not solved on the matter!

Anyway, ive spent months and months just getting quaternions, sometimes the understanding pops into my head other times it doesnt :). Its very illusive because you have to allow it to work sort of like n-space paradigms. Im still understanding them all the time - the best thing to do is to read alot and then not look at anymore info, let you head digest it slowly.


The waiter trick can be applied to any rotational system, but you first have to understand how rotational space works. A lot of people get confused what a rotation really is - Pixar basically defrobulate rotations giving them 1 a direction and 2 a rotation about this direction - and then convert this into eulers in the graph editor i.e

inside the viewport it acts like a quaternion but inside the graph editor it acts like an euler! - pretty clever :)

A rotation im my thinking resides in a space and is bound by this space eg. our upper arm resides in the should socket - it cant go beyond 180, in both its direction about its spherical center: the socket or its twist about its length: the arm rotating. This spherical space exists in its parent space too which also crucial. Knowing this you can apply duriac method of rotation on this system to allow for -360 to +360 degrees of twist.

Also a spine system and a tentacle system are very different, its the rotation space that the control mechanism exists in thats key - it denotes the twist. Treating a spine like a tentacle allows for complex twisting but, hinders the animator and vice versa - so you have to find the best of both systems.

wamo
04-13-2008, 06:49 PM
Hey Judd, hows Kevin Hayes over at your work? :) - remember also matrix mutiplication that a matrix can only multiply by another matrix or n-dimensional vector if it has the same amount of columns as the subsequent rows. i.e

1 2 3__1 2 _____________________1 2 3 _1 2
4 5 6 * 3 4_____will work however_4 5 6 * 3 4_wont.
7 8 9 __5 6_____________________7 8 8



Also in common terms as I know then you would have a 3X4 matrix and not a 4X4 matrix - as in the case:
matrix3 1

[1,0,0] [0,1,0] [0,0,1] [0,0,0]

1 0 0
0 1 0
0 0 1
0 0 0




To Buexe,

Exactly Correct :), i tend to skip the semantics because im looking at the system as a whole.

Maybe, just maybe I'll show of some major powerful features of quaternions - when using them in the form of spinors. If you study the belt-trick or duriac your'll know that for a rotation to resolve itself past 360 it has to go another 360 degrees - the nice thing about this is that it allows for rotation of -360 to +360.

You do this with a plate its called the 'waiter trick' - take a plate with you hand holding under it out in front of you. Then start to rotate you hand towards your side clockwise then until its out away from you - now start to bring your elbow up and keep rotating your hand - this is 360 degrees - now bring you elbow back down and keep rotating your hand - this is another 360 degree back to the start position - 720 degrees :)

In 1800s, when the quaternion was invented it wasnt used as a method for rotation, it was just developed because Hamilton couldnt get 3 dimensional number systems to work, when he tried 4 dimensions it worked.

An euler based system, doesnt respect the system as a whole, i.e in a quaternion the spin, fazer or twist of the direction also affects the direction and vice versa. Why is this?

A quaternion is denoted by 3 imaginary dimensions and 1 real dimension, each imaginary dimension has a unit value of the square root of -1 all mutually perpedicular to each other ( you could say similair to an othogonalized transform matrix) so this is a way of understanding it:


(a)realPart + (imaginaryPart * b) + (imaginaryPart *c) + (imaginaryPart * d)


I, J, and K are essentially quaternions of 180 degrees about the x y and z axis this is why i^2 = -1 = 360 degrees. So 1 and -1 both represent 360 degrees i.e 0. So when it gets rotated by 360 degrees it gets invert and needs another 360 degrees to go back to 0. i.e


(a)realPart + (imaginaryPart * b) + (imaginaryPart *c) + (imaginaryPart * d)

is the same as

(a)realPart - (imaginaryPart * b) - (imaginaryPart *c) - (imaginaryPart * d)

This site can explain better: http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/index.htm

eek,really thanks,it's going me into Quternions,great explainations from you
and the website you introduced.
just i can say more than a CG/Rigging we need math to solves lots of these issues.

eek
04-14-2008, 04:18 AM
eek,really thanks,it's going me into Quternions,great explainations from you
and the website you introduced.
just i can say more than a CG/Rigging we need math to solves lots of these issues.


Im slowly finding out some general rules about rigging such as the shoulder exists in a single quaternion space and the wrist exists in a double quaternions space, like the ankle - I'll try to post some more on my blog - very busy with production atm.

wamo
04-14-2008, 09:52 AM
Im slowly finding out some general rules about rigging such as the shoulder exists in a single quaternion space and the wrist exists in a double quaternions space, like the ankle - I'll try to post some more on my blog - very busy with production atm.
will be looking for this issue on your blog...
eek can you introduce some examples of usage of Quaternion?,
i heard TDs solve wrist twisting with Quaternions.

IkerCLoN
04-15-2008, 08:56 AM
will be looking for this issue on your blog...
eek can you introduce some examples of usage of Quaternion?,
i heard TDs solve wrist twisting with Quaternions.

Yep, it's not a legend!

http://ruramuq.blogspot.com/2008/02/twist-bones-avoiding-flipping.html

I found in Wikipedia some interesting links about quaternions for us 'advanced math newbies' ;)

uiron
04-15-2008, 11:30 AM
Yes, very true - firstly Quaternions are very hard to understand and im still trying to get the 'idea' of complex numbers.

you don't even need to bother about number math inside black boxes like "matrix" or "quaternion". you use them as a whole anyway, using "upper level" math, like "multiply matrix by matrix", and understanding what these operations do.

quaternion is yet another "operation", used when you need to rotate along custom axis by given amount of angles. example task would be.. imagine an object, sitting on a curve. you want to rotate that object on a curve by 10 angles. what you do?

1 get vector vDirection, which represents curve tangent at that point; this is our rotation "axis";
2 construct the rotation offset operation - quaternion qOffset from VDirection, 10 angles; creating quaternion from vector and angle values is a standart quaternion constructor;
3 as we want to rotate along object's pivot, we're have to "put it" to 0,0,0 before applying rotation operation: extract translate part of transform matrix mTranslate, multiply transform matrix by inverse mTranslate;
4 multiply transform matrix by qOffset;
5 put the object back to it's original position by multiplying transform matrix by mTranslate.

steps 3-5 ofc is just a single code line something like "objTransform = objTransform*inverse(mTranslate)*qOffset*mTranslate".


rotating along given axis by N angles is not the only usage of quaternion ofc, this is just an example how you can not to care what complex number math in 4-dimentional space is happening there.

loked
04-16-2008, 03:29 AM
uiron's point is kind of the point I was making... it seems like this thread has turned into an overwhelming amount of mathematical complexity, where the function of quaternions is more what I think a TD would initially need to concern themselves with. Dont get me wrong, I definitely agree that the deeper you delve the better, but it seems that when starting out so much detailed information can increase the learning curve unneccesarily. Either way, its up to the person learning how much info he chooses to expose himself to, so thats obviously just my opinion and what I generally find easier.

Eek: Hey man, I'm not sure who Kevin Hayes is :) I think you might be referring to Ryan Trowbridge ?

later ;)

eek
04-16-2008, 03:58 AM
uiron's point is kind of the point I was making... it seems like this thread has turned into an overwhelming amount of mathematical complexity, where the function of quaternions is more what I think a TD would initially need to concern themselves with. Dont get me wrong, I definitely agree that the deeper you delve the better, but it seems that when starting out so much detailed information can increase the learning curve unneccesarily. Either way, its up to the person learning how much info he chooses to expose himself to, so thats obviously just my opinion and what I generally find easier.

Eek: Hey man, I'm not sure who Kevin Hayes is :) I think you might be referring to Ryan Trowbridge ?

later ;)


hehe soz man, too many contacts- too busy during the day :). I was thinking that you worked at Propaganda. :)

Very true to the above point - I didnt mean to over complicate things. The best way is to use them and only learn more if you need to essentially - else your brain may explode.

wamo
04-16-2008, 05:35 AM
Yep, it's not a legend!

http://ruramuq.blogspot.com/2008/02/twist-bones-avoiding-flipping.html

I found in Wikipedia some interesting links about quaternions for us 'advanced math newbies' ;)

hey , i got that dude,it's really nice and funny,
tried to do so but :buttrock: now try again with quaternions ...thanks.

CGTalk Moderation
04-16-2008, 05:35 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.