//获取a到b的夹角,b到a的夹角
public void DotAndCross() {
a = CubeA.transform.position;
b = CubeB.transform.position;
Vector3 c = Vector3.Cross(a, b);//通过叉积求的A,B的法向量
float angle = Vector3.Angle(a, b);//求得a,b的夹角(绝对值)
//a到b的夹角
//获取正负号
float sign = Mathf.Sign(Vector3.Dot(c.normalized, Vector3.Cross(a.normalized, b.normalized)));
float sign_angle = sign * angle;
Debug.Log("a到b的夹角是" + sign_angle);
//b到a的夹角
//获取正负号
sign = Mathf.Sign(Vector3.Dot(c.normalized, Vector3.Cross(b.normalized, a.normalized)));
sign_angle = sign * angle;
Debug.Log("b到a的夹角是" + sign_angle);
}
通过Dot和Cross获取a到b的夹角
最新推荐文章于 2024-11-15 15:05:55 发布