获取两个向量a,b之间的夹角的几种方法
方法1:
通过两个向量的法向量的点乘的反余弦获取弧度,然后通过弧度获取角度
rad = Mathf.Acos(Vector3.Dot(a.normal,b.normal))
ang = rad * Mathf.Rad2Deg
方法2:
通过两个向量的法向量的叉乘的模长的反正弦获取弧度,然后通过弧度获取角度
rad = Mathf.Asin(Vector3.Distance(Vector3.zero,Vector3.Cross(a.normal,b.normal)))
ang = rad * Mathf.Rad2Deg
方法3:
先获取a,b向量的角度大小,然后这个角度可能是正的角度,也可能是负的角度。
再获取a到b之间夹角的符号,符号为(ab叉乘的法线)和(ab法线的叉乘)的点乘的Mathf.Sign值,即为符号
符号 = Vector3.Dot(Vector3.Cross(a,b).normal,Vector3.Cross(a.normal,b.normal))
ang = Vector3.Angle(a,b)
ang = ang * 符号
转自:
https://www.cnblogs.com/vsirWaiter/p/8348035.html