zoukankan      html  css  js  c++  java
  • Unity 四元数与欧拉角的相互转换及推导

    一、四元数与欧拉角的转换

    先说结论:

    具体推到过程参考: https://blog.csdn.net/qq1545372477/article/details/78440806

    将欧拉角转换为四元数:

    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;
        }

    二、关于rotation、localRotation、eulerAngles、localEulerAngles之间的关系

    transform.rotation:物体旋转角度的四元数(受父物体影响)

    transform.localRotation:物体旋转角度的四元数(不受父物体影响)

    transform.eulerAngles:物体旋转角度,(Inspector面板中Rotation显示的数,受父物体影响

    transform.localEulerAngles:物体旋转角度,(Inspector面板中Rotation显示的数,不受父物体影响

  • 相关阅读:
    Codeforces 每日一练 1213G+961E+1282B2
    AtCoder Beginner Contest 161题解
    Codeforces每日一练 495B+55C+1280C
    CF1062E 线段树/LCA
    Codeforces Round #697 (Div. 3) 题解
    Codeforces Round #511 (Div. 2) A~D题解
    Atcoder ABC 189 题解
    CF1093G 高维曼哈顿距离/线段树
    CF1117D Magic Gems 矩阵快速幂 DP
    CF1106E Lunar New Year and Red Envelopes DP
  • 原文地址:https://www.cnblogs.com/YorkZhao/p/9138170.html
Copyright © 2011-2022 走看看