Euler problems

JamesH
Posts: 19
Joined: Mon Oct 16, 2006 6:19 pm

Euler problems

Post by JamesH »

I'm working on an integration with a 3D package that stores its rotations as degrees and as such I cannot pass a 3x3 matrix to it for the rotation. To retrieve the rotation I'm using

Code: Select all

	myMotionState->m_graphicsWorldTrans.getBasis().getEulerZYX(z, y, x);
And then converting it to degrees before passing it to the 3D package. It all is working pretty well until.....

The problem I have is when the rotation is around 180 degrees, the value just switches between -180 and 180. As can be seen from some debugging info I'm recording for a mesh - the rotation x, y and z values are the three values after the rotation id.

Code: Select all

mesh016,4.74,rotation018,-179.999,58.1703, 179.999,translation019,-2.88586,0.500995,-0.94595
mesh016,4.76,rotation018,-180.000,58.1704, 180.000,translation019,-2.88586,0.500997,-0.945943
mesh016,4.78,rotation018,-180.000,58.1704, 180.000,translation019,-2.88586,0.500998,-0.945935
mesh016,4.80,rotation018, 180.000,58.1704, 180.000,translation019,-2.88586,0.500998,-0.945928
mesh016,4.82,rotation018, 180.000,58.1703, 180.000,translation019,-2.88586,0.500999,-0.945931
mesh016,4.84,rotation018, 180.000,58.1703, 180.000,translation019,-2.88586,0.500999,-0.945929
mesh016,4.86,rotation018,-179.989,58.1705,-179.993,translation019,-2.88584,0.501003,-0.945927
mesh016,4.88,rotation018,-179.996,58.1705,-179.997,translation019,-2.88583,0.501001,-0.945917
mesh016,4.90,rotation018,-179.997,58.1705,-179.998,translation019,-2.88584,0.501001,-0.945909
mesh016,4.92,rotation018,-179.997,58.1705,-179.998,translation019,-2.88584,0.501001,-0.945907
mesh016,4.94,rotation018,-179.998,58.1705,-179.998,translation019,-2.88584,0.501,-0.945899
mesh016,4.96,rotation018,-179.998,58.1705,-179.999,translation019,-2.88585,0.501,-0.945892
mesh016,4.98,rotation018,-179.999,58.1705,-179.999,translation019,-2.88585,0.501,-0.945884
mesh016,5.00,rotation018,-179.999,58.1705,-179.999,translation019,-2.88585,0.501,-0.945877
I'm having to pass these values back to the package, so, is there any other way I calculate the angles ?

Many thanks

James.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Euler problems

Post by Erwin Coumans »

We have some experience with 3d angle exchange between Bullet and Irrlicht, and Blender, but in general euler angles are a bag of hurt: everyone uses their own order, XYZ, XZY, ZYX etc, and conventions.

What kind of 3D package is it? Doesn't the vendor provide and code to/from a 3x3 rotation matrix and their euler angle flavour?
If not, could you figure out what order is used to go from Euler angles to 3x3 matrix?
Thanks,
Erwin
JamesH
Posts: 19
Joined: Mon Oct 16, 2006 6:19 pm

Re: Euler problems

Post by JamesH »

The package is Modo, I'm having to wrap Bullet into a dll with an interface that can be called by perl - one of Modo's scripting languages (which was fun !). Modo supports ZXY as default, but also can use XYZ, XZY, YXZ, YZX and ZYX.

Unfortunately maths is not a strong suit of mine and googling just seems to give me too much generic info.

A pointer or two would be much appreciated.

Cheers.
ryan0618
Posts: 9
Joined: Sun Mar 29, 2009 10:27 pm

Re: Euler problems

Post by ryan0618 »

I had a similar problem with Euler angles. I was using the formulas found here http://www.euclideanspace.com/maths/geo ... /index.htm. Using DarkGDK, the shapes would spaz out when they reached a certain point. I eventually found a function in DarkGDK that would allow you to set an object's position from a D3DXMatrix, and I used that. However, maybe the formulas will work for you. You would use

Code: Select all

btQuaternion q = myMotionState->getWorldTransform()->getRotation()]
to get the quaternion, and use

Code: Select all

q.getX()
and so on the to get the values.

Note:
Heading = rotation around y axis
Attitude = rotation around z axis
Bank = rotation around x axis
Rotation Order: YZX

The fourm topic for my problem here: http://www.bulletphysics.com/Bullet/php ... =18&t=3404

Unless, your main problem is that modo uses 0 - 360 degrees and your getting -180 - 180. In that case, use this (I think :mrgreen: )

Code: Select all

if (rotation < 0)
{
rotation = rotation + 360;
}
for all the angles. That should convert the negative values to positive.

Good luck, hope this helps!
ryan0618
jimt
Posts: 7
Joined: Sat Apr 18, 2009 10:36 am

Re: Euler problems

Post by jimt »

I dealt with this problem on my own at one point. The conclusion was: Never use Euler angles.

I was using the conversion technique mentioned previously (Matrix to Euler) with varying results. This is due to the inaccuracy of the transformation process. The math isn't perfect.

I'm very skeptical that Modo, a relatively solid 3D modeling package, exclusively uses Euler angles. My suggestion is to keep digging. There has to be a way to use the transformation matrix directly.

-Jim
JamesH
Posts: 19
Joined: Mon Oct 16, 2006 6:19 pm

Re: Euler problems

Post by JamesH »

Thanks for teh answers guys.

I've read up quite a lot now about euler angles and understand the difficulties involved, and it would be great not to have to use them.

I've a question open on the Modo forums that hopefully someone will answer, but at the moment it looks like adding channel rotation data via the scripting language doesn't include a handy 3x3 matrix.