Rotation matrix ortho-normalization

Started by
39 comments, last by minorlogic 19 years, 6 months ago
AP, I didn't quite follow all of your argument against quats, but I'm not sure if they're very well founded. Others have explained the advantages, but I'll reiterate a couple of them.

Yes, quats also need to be re-normalized occasionally. But renormalizing a quaternion is considerably less expensive than re-orthonormalizing a matrix. So quats are a win no matter what.

Quats concatentate rotations just like (3x3) matrices do. And, quaternion multiplication is cheaper than matrix multiplication. If you have a series of rotations to concatenate (such as in a skeletal system), quats are again a win.

Also, interpolating quaternions is easier and more elegant than interpolating matrices. Slerp is invaluable in cases such as keyframe animation or inverse kinematics. Even without all the other factors, this by itself is a sufficient selling point for quaternions.

They also take up less space - 4 floats instead of 9 for orientation information. This can make a difference on certain platforms, if you're dealing with numerous keyframes.

As far as I know, no one rotates vectors directly with quaternions, so the speed of that operation is more or less irrelevant. Instead, you convert the quat to a matrix, but only when you need it. And the conversion is fairly fast as well - less expensive (I think - I'd have to check) than a matrix multiplication.

Anyway, those are some arguments in favor of quats. Pretty much anything you can do with a quaternion you can do with a matrix. But in my experience it's generally easier, faster and more elegant to use a quaternion.
Advertisement
“a quat is always ortho, if not unit length.”

Not really, take quaternion a(0.5, 0.5, 0.5, 0.5)
When multiplied repeatedly by another quat say b(cos(a/2), 0, sin(a/2), 0)
Will introduces and error of the same nature than the product of the equivalent matrices, So in both case normalization is required. In the case of quaternion what you get is not longer a quaternion, it is forced to map into a neighbor quaternion by the normalization which nothing than a projection. So quaternions, just like orthonormal matrices, do lose orthogonality as result of round of errors.

“and one normalization is quite a lot faster than renomalizing and reothogonizing a matrix.”

True, but you have to take the whole picture. The normalization in faster on a single quaternion, but given that this lost of orthogonality can only happens as the result of a multiplication by anther quaternion. When you need to get the product of two matrices from two quaternions the operation is up to 5 to 6 time slower

My point is: quaternions are good for storing rotations and to encode animations, but there are not practical as build block for a graphic engine.
I am not saying quaternions cannot be used to represent rotations, but if you are going to recomend that option you need to explain everything not just a bias opinion.
“AP, I didn't quite follow all of your argument against quats, but I'm not sure if they're very well founded”

I gave you a mathematical prove of what I said, operations with quaternion are not a win in turns of floating point operation, they are convenient for interpolating matrices, and also they take less space. But they are not practical for transformation manipulations.

If you chose then as your building block, that’s fine, but recommending then as the superior solution to general transformation matrices is just wrong
1:There's no such thing as non-orthonormal quaternion.
Quaternion may only be not unit length. It only have to be re-normalized exactly like 4d vector.

If quaternion is not unit-length, and quaternion-to-matrix conversion is done correctly , you'll get matrix that not only rotate but also scale by |q|2 . For camera, it doesn't matter to have precisely unit-length quaternion, because scaling only affect your z-buffer values a bit. So quaternion can be normalized using fast inaccurate inverse square root that costs as much as addition.

2: quaternion (0.5,0.5,0.5,0.5) is perfectly valid unit-length quaternion that stores rotation around axis 1,1,1 by 120 degrees. I instantly computed that in mind without any trouble. It's yet another adwantage of quaternions.
For example,
Quaternion(1,1,1,1)
rotates around same axis by same angle and also scales 4 times.

3: i don't have to choose something as building block. I use quaternions where apporiate, and use matrices where apporiate.
If i need rotation only, i use quaternion. If i need rotation and translation, i use "coordsys". If i need angular velocity, i use vector. If i need arbitrary linear transform on 3d space i use 3x4 matrix. If i need arbitrary projection transform(transform with division), i use 4x4 matrix.
Quote:Original post by Anonymous Poster
“a quat is always ortho, if not unit length.”

Not really, take quaternion a(0.5, 0.5, 0.5, 0.5)
When multiplied repeatedly by another quat say b(cos(a/2), 0, sin(a/2), 0)
Will introduces and error of the same nature than the product of the equivalent matrices, So in both case normalization is required. In the case of quaternion what you get is not longer a quaternion, it is forced to map into a neighbor quaternion by the normalization which nothing than a projection. So quaternions, just like orthonormal matrices, do lose orthogonality as result of round of errors.

youre confusion orthonomality with unit length. a completely random quat just also might cause scaling, nothing more to it. since a quat only defines rotation (3 DOF's) and uniform scaling (one DOF), and has 4 components, there is no overdefinition, hence EVERY possible quaternion is a valid and orthonomal one, although only a subset is also non-scaling.

Quote:
“and one normalization is quite a lot faster than renomalizing and reothogonizing a matrix.”

True, but you have to take the whole picture. The normalization in faster on a single quaternion, but given that this lost of orthogonality can only happens as the result of a multiplication by anther quaternion. When you need to get the product of two matrices from two quaternions the operation is up to 5 to 6 time slower

i really dont get what youre saying here. could you give a more concrete exmaple of how error supposedly builds up faster in quats, making things a whopping 5 to 6 times slower? if i do my math correct, that would imply quats need to be normalized 20 times as much as matrices! (assuming quat normalization is 3-4 times as fast as matrix fixing, which is reasonable)

Quote:
My point is: quaternions are good for storing rotations and to encode animations, but there are not practical as build block for a graphic engine.
I am not saying quaternions cannot be used to represent rotations, but if you are going to recomend that option you need to explain everything not just a bias opinion.

sorry i still think i have defended my position better than you did yours.

if youre not interested in shearing (almost never) or nonuniform rotation, quats are simply > *. but even if you are, i still think its more elegant to keep these things seperated in quats for rotation, and vectors for shearing, translation and scaling, but i admit that might just be a personal thing due to my hang for elegance, and not really be more efficient.
Try to get a matrix from this quat q(0.3, 0.5, 0.5, 0.5) and tell me what you get.

Try to get the aiming vector from a bone way down a skeleton with all transformations are encoded as quaternion, and do the same with matrices.

“i still think its more elegant to keep these things seperated in quats for rotation, and vectors for shearing, translation and scaling, but i admit that might just be a personal thing due to my hang for elegance, and not really be more efficient.”

I already proved quaternion are by no mean faster for transformation manipulation and elegance is in the eye of the beholder, I personally think and a quaternion and a position is less elegant and less efficient, than a single transformation matrix. (one operation, one member representaion for a matrix)
Apparently all video card manufactures, Microsoft directx, Opengl, not to mention all graphic packages like Max, soft image, Maya, Softimage XSI ect. Agree with me.
Quote:Original post by Anonymous Poster
Try to get a matrix from this quat q(0.3, 0.5, 0.5, 0.5) and tell me what you get.

i fail how to see its relevant, but it simply will be some perfectly orthogonal rotationmatrix with a slight downscale.

why?

Quote:
Try to get the aiming vector from a bone way down a skeleton with all transformations are encoded as quaternion, and do the same with matrices.

what the aiming vector? ive never heard the term before. but anyway forward aswell as backward transformations are very possible with quaternions, if thats your concern. easier than with matrices btw.

Quote:
“i still think its more elegant to keep these things seperated in quats for rotation, and vectors for shearing, translation and scaling, but i admit that might just be a personal thing due to my hang for elegance, and not really be more efficient.”

I already proved quaternion are by no mean faster for transformation manipulation and elegance is in the eye of the beholder, I personally think and a quaternion and a position is less elegant and less efficient, than a single transformation matrix. (one operation, one member representaion for a matrix)
Apparently all video card manufactures, Microsoft directx, Opengl, not to mention all graphic packages like Max, soft image, Maya, Softimage XSI ect. Agree with me.

you did no such thing in this thread. all you did was spouting some random stats (x is 6 times faster than y, is that your idea of a proof?), which were way off btw, and misinterpreted aswell.

we also went over the apis already. in short: they have to stick with matrices because they cant limit themselves to rotation and scaling only. the difference being that a gameengine can, and is flexible enough to adapt in the rare case more is needed.
Also, all those API's don't implement physics, collisions, and other things, even including cameras. Read my other reply on these boards about quaternions for camera. It's so simple to do timebased camera rotation with quaternion, yet it isn't simple with matrices.

And, 0.3,0.5,0.5,0.5 .
It rotates around axis 1,1,1 by angle 2*atan(sqrt(3)/0.6) (with some time i can even find angle without using calculator)
, and scales by 0.84
Again, computed in mind.

It's not like "they use quaternions because they don't know matrices". Nothing like that, we know how to work with matrices and how to work with quaternions, and we use quaternions where apporiate. Eelco recently even made thread where said that storing rotation velocity in quaternions sucks , and i totally agreed, rotation velocity should be storen in vector, or vector and angle.
Bot storing rotation in quaternions is good and elegant.
(Dmytry)"...computed in mind..."

My math teacher could calc arbitrary divisions down to the 5th decimal in his mind with little effort ;) That said, not all (actually few) have this talent, so don't take that for granted.
No no no no! :)
Well, I am not trying to convince you or anyone to not using quaternion. You can used quaternion all you want, just don¡¦t expresses your opinions as facts.

I do too used quats for what they are good for, but fortunately I had ground the point when quats are the panacea to all transformation problems.

I did proved my points mathematically you did not get it, I also stated neither quaternion nor matrices are superior to each other, but influencing the community with you ideas is just wrong.

Btw camera is one of those things you do not want to use quats. ļ

Good luck using those quaternions for everything.

This topic is closed to new replies.

Advertisement