<p abp="590"> 原理:通过向量之间的对比,利用点乘和差乘实现判断一个点是否在三角形里面。</p><p abp="591"> 叉乘: 叉乘结果用右手判断法则。</p><p abp="637">
public static bool InTrigon(Vector3 _target,Vector3 _center,Vector3 _left,Vector3 _right){
Vector3 Ctl=_left-_center;
Vector3 Ctr=_right -_center;
Vector3 Ctt=_target-_center;
Vector3 Ltr=_right-_left;
Vector3 Ltc=_right-_center;
Vector3 Ltt=_left-_target;
Vector3 Rtl=_left-_right;
Vector3 Rtc=_center-_right;
Vector3 Rtt=_target-_right;
if(
Vector3.Dot(Vector3.Cross(Ctl,Ctr).normalized,Vector3.Cross(Ctl,Ctt).normalized)==1&&
Vector3.Dot(Vector3.Cross(Ltr,Ltc).normalized,Vector3.Cross(Ltr,Ltt).normalized)==1&&
Vector3.Dot(Vector3.Cross(Rtc,Rtl).normalized,Vector3.Cross(Rtc,Rtt).normalized)==1
)
return true;
else
return false;
}<br abp="595" /></p>