将欧拉角转换为四元数

将欧拉角转换为四元数:

public Quaternion EularToQuaternion(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;
    }

猜你喜欢

转载自blog.csdn.net/mine0928/article/details/85035384