Rotation matrix ortho-normalization

Started by
39 comments, last by minorlogic 19 years, 5 months ago
AP: Good luck with matrix camera, btw [grin]
Can you implement camera like in my The Galaxy?

Quaternion it's just more elegant way to store orthogonal transform. I use quaternions in places where if i woulda have used matrix i woulda need to reorthonormalize.
Advertisement
Quote:Original post by Anonymous Poster
Good luck using those quaternions for everything.

good luck using stawman tactics for everything.
Quote:Original post by MichaelT
(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.

In this case it's easy. It scales by it's length squared;
0.32+0.52+0.52+0.52 = 0.09+0.75 = 0.84

Tangent of half of angle is
sqrt(0.75)/0.3 = sqrt(3/4)/0.3 = sqrt(3)/2/0.3 = sqrt(3)/0.6
Quote:Original post by Eelco
good luck using stawman tactics for everything.


explain: "stawman tactics"
No no no no! :)
/**
create a nonunit quaternion from rotation matrix
martix must contain only rotation (not scale or shear)
the result quaternion length is numerical stable
*/
inline void from_matrix( const matrix33& mtx )
{
typedef float mtx_elm[3][3];
const mtx_elm& m = mtx.m;
float tr = m[0][0] + m[1][1] + m[2][2]; // trace of martix
if (tr > 0.0f){ // if trace positive than "w" is biggest component
set( m[1][2] - m[2][1], m[2][0] - m[0][2], m[0][1] - m[1][0], tr + 1.0f );
}else // Some of vector components is bigger
if( (m[0][0] > m[1][1] ) && ( m[0][0] > m[2][2]) ) {
set( 1.0f + m[0][0] - m[1][1] - m[2][2], m[1][0] + m[0][1],
m[2][0] + m[0][2], m[1][2] - m[2][1] );
}else
if ( m[1][1] > m[2][2] ){
set( m[1][0] + m[0][1], 1.0f + m[1][1] - m[0][0] - m[2][2],
m[2][1] + m[1][2], m[2][0] - m[0][2] );
}else{
set( m[2][0] + m[0][2], m[2][1] + m[1][2],
1.0f + m[2][2] - m[0][0] - m[1][1], m[0][1] - m[1][0] );
}
}



/**
set the rotation to matrix
*/
inline void to_matrix( matrix33& m )const {
float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
float s = 2.0f/norm(); // 4 mul 3 add 1 div
x2 = x * s; y2 = y * s; z2 = z * s;
xx = x * x2; xy = x * y2; xz = x * z2;
yy = y * y2; yz = y * z2; zz = z * z2;
wx = w * x2; wy = w * y2; wz = w * z2;

m.m[0][0] = 1.0f - (yy + zz);
m.m[1][0] = xy - wz;
m.m[2][0] = xz + wy;

m.m[0][1] = xy + wz;
m.m[1][1] = 1.0f - (xx + zz);
m.m[2][1] = yz - wx;

m.m[0][2] = xz - wy;
m.m[1][2] = yz + wx;
m.m[2][2] = 1.0f - (xx + yy);
}


http://www.gamedev.ru/articles/graph/20040603.zip


Quote:Original post by MichaelT
Quote:Original post by Eelco
good luck using stawman tactics for everything.


explain: "stawman tactics"

i think he meant strawman arguments...

BTW, minorlogic: Privet, videl tvoi formuli kasatelno quaternionov na euclideanspace.com, kruto i vnushaet! (Hello, man! Readed your quaternion derivations on euclideanspace.com, pretty impressive!)
Eelco as usual you misunderstood the question: This was the original question

“I'm trying to figure out how to orthonormalize a rotation matrix so that the basis vectors would be unit length and perpendicular. This is to combat floating point precision errors that accumulate in the matrix.”

For which Dmytry gave the correct answer.

I as understand this is the Game dev forum were people comes for answer to specific questions. You basically told Gaimplay that the answer to his question required a rewrite of the entire project for not reason at all. Has his done what you suggested in the end his still have the same problem his started with, would not he?
I just reconfirmed the first answer was the correct one for the question.
What you did was to create and answer in search of a new problem. Part of been smart is not just to accumulate knowledge you also need to understand then questions.
Has it occur to you hi may be working on a very serious project where engineering re-factoring is just not an option.

About the straw man argument: like I said as usual you missing the point again and changing the subject.

Dmytry I think I am or was in you side this question was not about quaternions was about matrices. Make no mistake, do not think you are the only one understanding the algebra of rotation many more people do to.
Quote:Original post by Anonymous Poster
Eelco as usual you misunderstood the question: This was the original question

“I'm trying to figure out how to orthonormalize a rotation matrix so that the basis vectors would be unit length and perpendicular. This is to combat floating point precision errors that accumulate in the matrix.”

For which Dmytry gave the correct answer.

I as understand this is the Game dev forum were people comes for answer to specific questions. You basically told Gaimplay that the answer to his question required a rewrite of the entire project for not reason at all. Has his done what you suggested in the end his still have the same problem his started with, would not he?
I just reconfirmed the first answer was the correct one for the question.
What you did was to create and answer in search of a new problem. Part of been smart is not just to accumulate knowledge you also need to understand then questions.
Has it occur to you hi may be working on a very serious project where engineering re-factoring is just not an option.

i wasnt the one to bring up quaternions, i started out with giving him a possible solution to his stated problem. i merely confirmed what charles and dymtry suggested: quaternions might serve you better, so you might want to consider them. to which i added: probably, if you dont care for the advantages matrices have to offer over quats, which is likely in a gameengine.

Quote:
About the straw man argument: like I said as usual you missing the point again and changing the subject.

believe whatever you wish. youll have to start making arguments though if youre interested in persuading others.

Quote:
Dmytry I think I am or was in you side this question was not about quaternions was about matrices. Make no mistake, do not think you are the only one understanding the algebra of rotation many more people do to.

sure many people understand this, and my understanding probably isnt nearly as deep as that of a lot of others. i doubt those people include you though. i might add to that that dmytry and charlesB are the most knowledgeable people i know on these boards on the subject of math, and they seem to hold the same stance, which i will reiterate again for clarity: quaternions are the best method to store pure rotation (+ uniform scaling optionally).

were not forcing him to rewrite his engine using quats, we answered his question, dmytry corrected me and gave an even better method, and we gave some suggestions beyond the scope of his question: which he is free to act on or completely ignore.
I've got a question about Dimitry's matrix orthonormalizing method.

This way the same columns are used. Is it a good idea to switch the order for which columns are processed for the orthonormalization during the simulation?

first with the order dimitry gave and next orthonormalisation
for example start with Column3=Normalized(CrossProduct(Column1,Column2)) and do other 2 columns

or is this just making things more complicated?
1:Eelco gave keyword for search, therefore, he answered original question. I just failed to remember that it's named after Gramm-Schmidt, so i posted a solution.

After question is answered, it's OK to discuss related topics that can be useful for OP.

2:It's not needed to rewrite everything, because quaternions and rotation-only matrices represent same thing. They both is concatenated by multiplication, both should have functions like "load to openGL", most methods of both is the same. With good design, it's not a problem to replace one by other. Also, it's probably better if OP will rewrite it now than later, because probably the only thing he need to rewrite now is camera class.

3:I don't think no one else there understands rotations better than i. Yes, i sometimes have altitude like "f34r my math skillz", but it's usually when i'm first to reply with some simple calculations done in mind.

4: you gave no mathematical proofs, only some example quaternions that "should do bad things". In fact they don't, and it's pretty easy to mentally figure what 'em do if you know quaternions.

In summary: If you need to store and process variable rotation, quaternions is better than matrices.


f34r skillz part: today and at yesterday evening i worked with matrices for perspective transforms used to do that clickster (matrices that was used to make that hexagons, not camera matrices)

edit: and i must say, i clicked "reply" before i saw Eelco's reply.

[Edited by - Dmytry on October 26, 2004 9:26:21 AM]

This topic is closed to new replies.

Advertisement