Comments and answers for "Verifying Euler to Quaternion calculations"
http://answers.unity.com/questions/1163599/verifying-euler-to-quaternion-calculations.html
The latest comments and answers for the question "Verifying Euler to Quaternion calculations"Comment by lgbeno on lgbeno's answer
http://answers.unity.com/comments/1164052/view.html
Thanks! For the first cut of code, I wanted to write something as loyal to the reference as possible, not thinking about efficiency. Once it has proven itself, I'll go in and optimize and validate against the first version of inefficient code.
It would be excellent to distill the Sin & Cos combinations for the Unity style rotations so that I did not need to multiply Quaternions at all. That might take a few sheets of paper :)Fri, 01 Apr 2016 12:57:42 GMTlgbenoAnswer 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 GMTBunny83Comment by Eno-Khaon
http://answers.unity.com/comments/1163804/view.html
Ahh, yep. Looks like you did find what you were looking for. As an additional resource for others who may come across this:
> The x, y, and z angles represent a
> rotation z degrees around the z axis,
> x degrees around the x axis, and y
> degrees around the y axis (in that
> order).
http://docs.unity3d.com/ScriptReference/Transform-eulerAngles.htmlThu, 31 Mar 2016 22:35:42 GMTEno-Khaon