求两个向量的夹角

求两个向量的夹角

方法一:

Vector3 d1 = transform.forward;
Vector3 d2 = new Vector3(0,3,0);
float angle = Vector3.Angle(d1, d2);

方法二

Vector3 d1 = transform.forward;
Vector3 d2 = new Vector3(0,3,0);
float dot = Vector3.Dot(d1, d2.normalized);     //d2.normalized向量归一化
float angle = Mathf.Acos(dot) * Mathf.Rad2Deg;

方法三

Vector3 d1 = transform.forward;
Vector3 d2 = new Vector3(0,3,0);
Vector3 cross = Vector3.Cross(d1, d2.normalized);
float angle = Mathf.Asin(Vector3.Distance(Vector3.zero, cross)) * Mathf.Rad2Deg;

  

posted @ 2023-06-19 20:10  gatran  阅读(91)  评论(0编辑  收藏  举报