Bootstrap

点乘 叉乘在Unity中的应用

Vector3.Dot  点乘

Vector3.Dot(a,b)返回-1 到1,代表两条向量的方向相识度。1 = 方向相同的平行, 0代表 b垂直于a, -1 = 方向相反的平行。

常使用方式

1、判断位置

Vector3.dot(tranform.forward,target.transform - tramform.position)大于0 = target在transform前面,小于0target在transform后面

Vector3.dot(tranform.right,target.transform - tramform.position)大于0 = target在transform右面 ,小于0target在transform左面

2、求角度

 float angle=Mathf.Acos( Vector3.Dot(a.normalized,b.normalized))*Mathf.Rad2Deg(acos后得到的是弧度,我们将其*Mathf.Rad2Deg转换为角度 ); 

 

Vector.Cross 叉乘

Vector3 VecCross = Vector3.Cross(ImageMoveUI.transform.up, Vector3point);

//我们判断叉乘得到的向量的Z轴正负,来让图片是否是逆时针转还是顺时针转

 

 

                    

;