using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Diff : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Quaternion rot1 = Quaternion.AngleAxis(60, Vector3.up);
Quaternion rot2 = Quaternion.AngleAxis(30, Vector3.up);
// 四元数的差的计算
Quaternion diff = Quaternion.Inverse(rot1) * rot2;
Debug.Log(rot1);
Debug.Log(rot2);
Debug.Log(diff);
// 轴角表示
float angle = 0f;
Vector3 axis;
rot1.ToAngleAxis(out angle, out axis);
Debug.Log("rot1:");
Debug.Log(angle);
Debug.Log(axis);
rot2.ToAngleAxis(out angle, out axis);
Debug.Log("rot2:");
Debug.Log(angle);
Debug.Log(axis);
diff.ToAngleAxis(out angle, out axis);
Debug.Log("diff:");
Debug.Log(angle);
Debug.Log(axis);
}
// Update is called once per frame
void Update()
{
}
}
原理:d=a−1b
rot1绕Y轴旋转60度,rot2绕Y轴旋转30度,差是绕负Y轴旋转30度,也可以理解为绕Y轴旋转负30度。