| further reading | more topics » |
| mjbWorld program | 3D theory |
3D physics |
3D maths |
3D programming | technology |
about site |
sitemap A-Z |
| index | algebra | geometry | calculus | graph theory | statistics | principles | standards |
index |
space |
elements |
surface |
transformations | trigonometry |
||
| rotation | affine | theory | |||||
index |
angles |
euler |
axis angle |
direction cosines | convertions |
frame-of- reference |
as 2 reflections |
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. |
|
|
Commercial Software Shop Where I can, I have put links to Amazon for commercial software, not directly related to the software project, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them. |
|
|
Can you help? Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page. |
|
|
progam I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here: |
|
This site may have errors. Don't use for critical systems.
Copyright (c) 1998-2008 Martin John Baker - All rights reserved - privacy policy.