void Start () {
gameObject.transform.rotation = QuaternionToEular(-89.0f,50.0f,100.0f);
}
// Update is called once per frame
void Update () {
}
private Quaternion QuaternionToEular(float XX, float YY,float ZZ)
{
float X = XX /180* Mathf.PI;
float Y = YY / 180 * Mathf.PI;
float Z = ZZ / 180 * Mathf.PI;
float x = Mathf.Cos(Y / 2) * Mathf.Sin(X / 2) * Mathf.Cos(Z/ 2) +Mathf.Sin(Y / 2) * Mathf.Cos(X / 2) * Mathf.Sin(Z/ 2);
float y = Mathf.Sin(Y / 2)*Mathf.Cos(X/ 2)*Mathf.Cos(Z / 2) -Mathf.Cos(Y / 2)*Mathf.Sin(X/ 2)*Mathf.Sin(Z/ 2);
float z= Mathf.Cos(Y / 2) * Mathf.Cos(X/ 2) * Mathf.Sin(Z/ 2)-Mathf.Sin(Y / 2) * Mathf.Sin(X/ 2) * Mathf.Cos(Z / 2);
float w=Mathf.Cos(Y / 2)* Mathf.Cos(X / 2)* Mathf.Cos(Z/ 2) + Mathf.Sin(Y / 2)*Mathf.Sin(X / 2)*Mathf.Sin(Z / 2);
Quaternion quataion = new Quaternion(x, y, z, w);
return quataion;
}
}
通过四元数得到欧拉角,最后结果
计算过程中有一点点误差。但要注意万向锁。