Answers for "Verifying Euler to Quaternion calculations"
http://answers.unity.com/questions/1163599/verifying-euler-to-quaternion-calculations.html
The latest answers for the question "Verifying Euler to Quaternion calculations"Answer by Bunny83
http://answers.unity.com/answers/1163849/view.html
Well, as you figured out yourself the order in which you apply the rotations matters. There is not just one valid [euler angles representation][1]. Unity uses the order Z-X-Y around worldspace axes. To express this combination by rotations around localspace axes you just need to reverse the order. So it's the same as Y-X-Z around the localspace axes.
I haven't looked at the conversion used on the wikipedia page, but i guess it's X-Y-Z or Z-Y-X so you need a different order of your rotations. That means the combination of all those sin / cos will look different.
You shouldn't use your "euler_to_quaternion" method inside your "unity_euler_to_quaternion" method. You do way to many calculations that way. You should first implement the [AngleAxis method][2]. I don't really know python so here's a C# example:
public static Quaternion AngleAxis(float aAngle, float aX, float aY, float aZ)
{
float s = Mathf.Sin(aAngle/2f);
return new Quaternion(Mathf.Cos(aAngle/2f), aX*s, aY*s, aZ*s);
}
This method should create a quaternion rotation of "aAngle" radians around the normalized axis defined by (aX,aY,aZ)
To create your 3 rotations you would simply use:
AngleAxis(x, 1f,0, 0 );
AngleAxis(y, 0, 1f,0 );
AngleAxis(z, 0, 0, 1f);
Finally multiply them in the right order. Keep in mind that you can calculate the combined result in one go just like the example on the wikipedia page. However i would recommend to cache each sin / cos value in a local variable. At the moment inside your "euler_to_quaternion" method you calculate each sin and cos value 4 times.
[1]: https://en.wikipedia.org/wiki/Euler_angles
[2]: http://docs.unity3d.com/ScriptReference/Quaternion.AngleAxis.htmlThu, 31 Mar 2016 23:47:57 GMTBunny83