Detect if line segment intersects square

前端 未结 3 737
面向向阳花
面向向阳花 2020-12-21 04:25

Anyone have a simple algorithm for this? No need for rotation or anything. Just finding if a line segment made from two points intersects a square

3条回答
  •  伪装坚强ぢ
    2020-12-21 05:21

    You can do this by casting a vector and counting the number of edges it crosses.

    If the edges it crosses are even, it is outside the object, if the edges it crosses are odd, it is inside.

    This works for all closed polygons.

提交回复
热议问题