public static bool AlmostOnLine(Vector3 lineP1, Vector3 lineP2, float width, Vector3 toCheck) { Vector3 _lineDir = (lineP2 - lineP1).normalized; lineP1 += _lineDir * 99; lineP2 -= _lineDir * 99; Quaternion q = QuaternionUtility.Euler(0, 90, 0); Vector3 _rightDir = (q * _lineDir).normalized; Vector3 lp1Right = lineP1 + _rightDir * 0.5f * width - _lineDir * 0.5f * width; Vector3 lp1Left = lineP1 - _rightDir * 0.5f * width - _lineDir * 0.5f * width; Vector3 lp2Right = lineP2 + _rightDir * 0.5f * width + _lineDir * 0.5f * width; Vector3 lp2Left = lineP2 - _rightDir * 0.5f * width + _lineDir * 0.5f * width; return(Geometric.IsPointInArea(new[] { lp1Right, lp2Right, lp2Left, lp1Left }, toCheck)); }
public static bool IsPointAlmostOnSegment(Vector3 lineP1, Vector3 lineP2, float width, Vector3 toCheck) { Vector3 _lineDir = (lineP2 - lineP1).normalized; Quaternion q = QuaternionUtility.Euler(0, 90, 0); Vector3 _rightDir = (q * _lineDir).normalized; Vector3 diff = _rightDir * width - _lineDir * width; Vector3 lp1Right = lineP1 + diff; Vector3 lp1Left = lineP1 - diff; Vector3 lp2Right = lineP2 + diff; Vector3 lp2Left = lineP2 - diff; var res = Geometric.IsPointInArea(new[] { lp1Right, lp2Right, lp2Left, lp1Left }, toCheck); return(res); }