By: nobody ( Nobody/Anonymous ) |
Hi there, |
By: martinbaker ( Martin Baker
) |
Thank you very much
for this, I have updated the web page. |
By: nobody ( Nobody/Anonymous ) |
Sorry, my mistake.
It seems that I copied wrongly my own version. I think the following is
the right version finally: |
By: nobody ( Nobody/Anonymous ) |
|
By: martinbaker ( Martin Baker
) |
Angel, |
By: minorlogic ( Michaele Norel
) |
Hi Martin!
May be this version look more clear.
// create a unit quaternion
void mat_to_quat( const matrix33& mtx, quaternion& q ) {
typedef float mtx_elm[3][3];
const mtx_elm& m = mtx.m;
float n4; // the norm of quaternion multiplied by 4
float tr = m[0][0] + m[1][1] + m[2][2]; // trace of martix
if (tr > 0.0f){
q.set( m[1][2] - m[2][1], m[2][0] - m[0][2], m[0][1] - m[1][0], tr+1.0f );
n4 = q.w;
} else if( (m[0][0] > m[1][1] ) && ( m[0][0] > m[2][2]) ) {
q.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] );
n4 = q.x;
}else if ( m[1][1] > m[2][2] ){
q.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] );
n4 = q.y;
}else {
q.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] );
n4 = q.z;
}
q.scale( 0.5f/(float)sqrt(n4) );
}
// create a nonunit quaternion !!!
void mat_to_quat( const matrix33& mtx, quaternion& q ) {
typedef float mtx_elm[3][3];
const mtx_elm& m = mtx.m;
multiplied by 4
float tr = m[0][0] + m[1][1] + m[2][2]; // trace of martix
if (tr > 0.0f){
q.set( m[1][2] - m[2][1], m[2][0] - m[0][2], m[0][1] - m[1][0], tr+1.0f );
} else if( (m[0][0] > m[1][1] ) && ( m[0][0] > m[2][2]) ) {
q.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] ){
q.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 {
q.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] );
}
}
|
By: minorlogic ( Michaele Norel
) |
But ! Sorry i didn't check , possible it not compartible with your matrix. |
metadata block |
|
see also: |
|
Correspondence about this page | |
Book Shop - Further reading. Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them. |
|
This site may have errors. Don't use for critical systems.
Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.