Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed May 30, 2007 12:41 am 
Offline

Joined: Wed May 30, 2007 12:36 am
Posts: 3
When converting a 3x3 matrix to its Euler angles, I came across the following code in btMatrix3x3.h:

Code:
void getEuler(btScalar& yaw, btScalar& pitch, btScalar& roll) const
      {
         pitch = btScalar(btAsin(-m_el[2][0]));
         if (pitch < SIMD_2_PI)
         {
            if (pitch > SIMD_2_PI)
            {
               yaw = btScalar(btAtan2(m_el[1][0], m_el[0][0]));
               roll = btScalar(btAtan2(m_el[2][1], m_el[2][2]));
            }
            else
            {
               yaw = btScalar(-btAtan2(-m_el[0][1], m_el[0][2]));
               roll = btScalar(0.0);
            }
         }
         else
         {
            yaw = btScalar(btAtan2(-m_el[0][1], m_el[0][2]));
            roll = btScalar(0.0);
         }
      }


The first if doesn't make sense- asin should never return a value higher than 2pi. The second if statement makes even less sense. How is it even possible to reach that code (only reachable if pitch < 2 pi and greater than 2 pi.

I am in need of this function and it seems to be returning incorrect values. Any insights?

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 3:09 am 
Offline
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3744
Location: California, USA
This was an un-used method and something must have gone wrong when porting the original code. This is the updated version, is checked into svn so should go into next version.

Can you check it?
Thanks for the feedback,
Erwin


Code:
   void getEuler(btScalar& yaw, btScalar& pitch, btScalar& roll) const
      {
         
         if (btScalar(m_el[1].z()) < btScalar(1))
         {
            if (btScalar(m_el[1].z()) > -btScalar(1))
            {
               yaw = btScalar(btAtan2(m_el[1].x(), m_el[0].x()));
               pitch = btScalar(btAsin(-m_el[1].y()));
               roll = btScalar(btAtan2(m_el[2].y(), m_el[2].z()));
            }
            else
            {
               yaw = btScalar(-btAtan2(-m_el[0].y(), m_el[0].z()));
               pitch = SIMD_HALF_PI;
               roll = btScalar(0.0);
            }
         }
         else
         {
            yaw = btScalar(btAtan2(-m_el[0].y(), m_el[0].z()));
            pitch = -SIMD_HALF_PI;
            roll = btScalar(0.0);
         }
      }
      


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 4:48 pm 
Offline

Joined: Wed May 30, 2007 12:36 am
Posts: 3
Yeah it looks like it's working.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group