### How to change Eulerian angle yzx

Posted:

**Thu Jul 23, 2020 6:23 am**In the bullet, his Euler angle seems to be YXZ. What should I do to change him into YZX,thank you very much

https://pybullet.org/Bullet/phpBB3/

https://pybullet.org/Bullet/phpBB3/viewtopic.php?f=9&t=13040

Page **1** of **1**

Posted: **Thu Jul 23, 2020 6:23 am**

In the bullet, his Euler angle seems to be YXZ. What should I do to change him into YZX,thank you very much

Posted: **Thu Jul 23, 2020 4:18 pm**

I don't know how to do what you asked off the top of my head. It sounds... possible, but complicated. There are many different varieties of "Euler angles" and you'd have to define exactly what you mean. For example... are the axes of your Y, then Z, then X rotations in the world-frame or the object local-frame? As I recall Euler himself used a strategy which was: local+world-frame (they are the same at the start), then local-frame, then world-frame. But no one in the games industry uses his formulation and instead use "yaw, pitch, roll" about local-frame axes and call it "Euler angles".

All of that ^^^ just to say: Euler angles are complicated and you haven't clearly defined your system. Any solution would have to know**exactly** what you mean.

Unless you're doing something very special where Euler angles are a natural coordinate system for your mechanism/application I would advise: don't use them and instead use Quaternions and do "rotation math". It may sound intimidating, but from my experience its implementation is simpler than an Eulerian approach. In particular: there are no gimbal-lock singularities to worry about.

So I would ask:**What do you really want to do?**

**(1)** Are you trying to rotate an object in some fashion? (e.g. you know where you're going and want rotate toward it) Or...

**(2)** Are you trying to "measure" the rotation of an object? (e.g. you know where you are but want to know it in a different coordinate space)

If**(1)** then you **definitely** should be using rotation math and should avoid Euler angles. If **(2)** then **(a)** Really? Why? and **(b)** you **probably** should use rotation math to compute your Eulerian decomposition. The only alternative methodology I can think of would be to do a bunch of geometry/trigonometry.

All of that ^^^ just to say: Euler angles are complicated and you haven't clearly defined your system. Any solution would have to know

Unless you're doing something very special where Euler angles are a natural coordinate system for your mechanism/application I would advise: don't use them and instead use Quaternions and do "rotation math". It may sound intimidating, but from my experience its implementation is simpler than an Eulerian approach. In particular: there are no gimbal-lock singularities to worry about.

So I would ask:

If

Posted: **Tue Jul 28, 2020 3:34 am**

Thank you very much for your reply. I think I didn't express it clearly, but now I have found a solution.I changed the order of rotation to achieve the effect I wanted

//zxy

void setEulerZXY(const btScalar& yaw, const btScalar& pitch, const btScalar& roll)

{

btScalar halfYaw = btScalar(yaw) * btScalar(0.5);

btScalar halfPitch = btScalar(pitch) * btScalar(0.5);

btScalar halfRoll = btScalar(roll) * btScalar(0.5);

btScalar cosy = btCos(halfYaw);

btScalar siny = btSin(halfYaw);

btScalar cosx = btCos(halfPitch);

btScalar sinx = btSin(halfPitch);

btScalar cosz = btCos(halfRoll);

btScalar sinz = btSin(halfRoll);

/* setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,

cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,

sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,

cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);*/

setValue(cosz * sinx * cosy - sinz * cosx * siny,

cosz * cosx * siny + sinz * sinx * cosy,

sinz * cosx * cosy + cosz * sinx * siny,

cosz * cosx * cosy - sinz * sinx * siny);

}

[/code]

//zxy

void setEulerZXY(const btScalar& yaw, const btScalar& pitch, const btScalar& roll)

{

btScalar halfYaw = btScalar(yaw) * btScalar(0.5);

btScalar halfPitch = btScalar(pitch) * btScalar(0.5);

btScalar halfRoll = btScalar(roll) * btScalar(0.5);

btScalar cosy = btCos(halfYaw);

btScalar siny = btSin(halfYaw);

btScalar cosx = btCos(halfPitch);

btScalar sinx = btSin(halfPitch);

btScalar cosz = btCos(halfRoll);

btScalar sinz = btSin(halfRoll);

/* setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,

cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,

sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,

cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);*/

setValue(cosz * sinx * cosy - sinz * cosx * siny,

cosz * cosx * siny + sinz * sinx * cosy,

sinz * cosx * cosy + cosz * sinx * siny,

cosz * cosx * cosy - sinz * sinx * siny);

}

[/code]