Unity 点在线段上的方位

2022-06-29  本文已影响0人  CERI_CHANNEL
public static int PointOnWhichSideOfLineSegment(FixedVector3 fromPos, FixedVector3 toPos, FixedVector3 point)
{
    FixedVector3 rhs = toPos - fromPos;
    FixedVector3 lhs = point - fromPos
    if (FixedVector3.Dot(lhs, rhs) <= FixedNumber.Zero)
    {
        return 1;
    }
    if (rhs.sqrMagnitudeLong <= lhs.sqrMagnitudeLong)
    {
        return 0;
    }
    return 2;
}

返回:0终点外;1起点后;2在线上

参数:

起点 终点 检测点
FixedVector3[1] FixedVector3[1] FixedVector3[1]
fromPos toPos point

  1. FixedVector3 - 定点数

上一篇 下一篇

猜你喜欢

热点阅读