Find angle from 3x3 matrix components -


i have 3x3 rotation matrix:

[  cos( angle ) sin( angle ) 0 ] [ -sin( angle ) cos( angle ) 0 ] [  0            0            1 ] 

how work out angle?

the methods i'm using is:

void mat3::setangle( const float angle ) {     m[ 0 + 0 * 3 ] = cos( angle );     m[ 1 + 0 * 3 ] = sin( angle );     m[ 0 + 1 * 3 ] = -sin( angle );     m[ 1 + 1 * 3 ] = cos( angle ); } 

and retreive i'm using:

float mat3::getangle( void ) {     return atan2( m[ 1 + 0 * 3], m[ 0 + 0 * 3] ); } 

i'm testing this:

mat3 m; m.setangle( 179.0f ); float = m.getangle(); 

and ends being 3.0708115 not correct.

sin , cos take arguments in radians, while atan2 returns angle in radians.

179 rad = 3.070811 + 14 * 2 * pi rad 

which same angle 3.070811 rad.

you either pass in required angle radians , convert getangle result

m.setangle( 179.0f * m_pi / 180.0f ); float = m.getangle() * 180.0f / m_pi; 

or modify class take degrees

void mat3::setangle( const float angledeg ) {     anglerad = angledeg / 180.0f * m_pi;     m[ 0 + 0 * 3 ] = cos( anglerad );     // etc }  float mat3::getangle( void ) {     return atan2( m[ 1 + 0 * 3], m[ 0 + 0 * 3] ) * 180.0f / m_pi; } 

either way i'd suggest documenting unit class expects.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -