code-google-com / bullet

Automatically exported from code.google.com/p/bullet
0 stars 0 forks source link

btMatrix3x3 getEulerZYX singularity wrong values #328

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a btMatrix3x3 with m_el[2].x = +1 or -1

What version of the product are you using? On what operating system?
2.75

Please provide any additional information below.

With theese formulas
http://www.gregslabaugh.name/publications/euler.pdf

it works

the corrected method is like this: in mentioned paper yaw = ф, pitch = ψ,
roll = ψ. seems that yaw & roll are switched. 

void getEulerZYX(btScalar& yaw, btScalar& pitch, btScalar& roll, unsigned
int solution_number = 1) const
  {
    struct Euler{btScalar yaw, pitch, roll;};
    Euler euler_out;
    Euler euler_out2; //second solution
    //get the pointer to the raw data

    // Check that pitch is not at a singularity
    if (btFabs(m_el[2].x()) >= 1)
    {
      euler_out.yaw = 0;
      euler_out2.yaw = 0;

      // From difference of angles formula
      btScalar delta = btAtan2(m_el[0].y(),m_el[0].z());
      if (m_el[2].x() < 0)  //gimbal locked up
      {
        euler_out.pitch = SIMD_PI / btScalar(2.0);
        euler_out2.pitch = SIMD_PI / btScalar(2.0);
        euler_out.roll = euler_out.yaw + delta;
        euler_out2.roll = euler_out.yaw + delta;
      }
      else // gimbal locked down
      {
        euler_out.pitch = -SIMD_PI / btScalar(2.0);
        euler_out2.pitch = -SIMD_PI / btScalar(2.0);
        euler_out.roll = -euler_out.yaw - delta;
        euler_out2.roll = -euler_out.yaw - delta;
      }
    }
    else
    {
      euler_out.pitch = - btAsin(m_el[2].x());
      euler_out2.pitch = SIMD_PI - euler_out.pitch;

      euler_out.roll = btAtan2(m_el[2].y()/btCos(euler_out.pitch), 
                   m_el[2].z()/btCos(euler_out.pitch));
      euler_out2.roll = btAtan2(m_el[2].y()/btCos(euler_out2.pitch), 
                m_el[2].z()/btCos(euler_out2.pitch));

      euler_out.yaw = btAtan2(m_el[1].x()/btCos(euler_out.pitch), 
                  m_el[0].x()/btCos(euler_out.pitch));
      euler_out2.yaw = btAtan2(m_el[1].x()/btCos(euler_out2.pitch), 
                               m_el[0].x()/btCos(euler_out2.pitch));
    }

    if (solution_number == 1)
    { 
        yaw = euler_out.yaw; 
        pitch = euler_out.pitch;
        roll = euler_out.roll;
    }
    else
    { 
        yaw = euler_out2.yaw; 
        pitch = euler_out2.pitch;
        roll = euler_out2.roll;
    }
  }

Original issue reported on code.google.com by plbar...@gmail.com on 13 Jan 2010 at 11:54

GoogleCodeExporter commented 9 years ago

Thank for the report.

We probably remove all euler support in Bullet 3.x and provide some separate 
utility 
functions for developers.

Original comment by erwin.coumans on 20 Jan 2010 at 4:14

GoogleCodeExporter commented 9 years ago
well I have already done the functions i need, you mean something like that, 
isn't it?

Original comment by plbar...@gmail.com on 22 Jan 2010 at 2:15

Attachments:

GoogleCodeExporter commented 9 years ago
a new problemm appeared at gimbal block at pitch = - PI/2.

cos ( yaw + roll ) = -M13
-sin ( yaw + roll ) = M12

then

cos ( yaw + roll ) = -M13
sin ( yaw + roll ) = -M12

tan ( yaw + roll ) = M11 / M13. 

is not valid whwen using atan2,

yaw  +  roll = atan2 ( M12,  M13) incorrect values
yaw  +  roll = atan2 (-M12, -M13) correct values

Sorry last time i misleaded the correct files.

Original comment by plbar...@gmail.com on 24 Feb 2010 at 4:41

Attachments:

GoogleCodeExporter commented 9 years ago
Closing issues that we are not fixing anymore, our focus is on Bullet 3.x at 
http://github.com/erwincoumans/bullet3

Thanks for the contribution anyway,
Erwin

Original comment by erwin.coumans on 11 Sep 2013 at 12:12