Circle-Rectangle collision detection (intersection)

前端 未结 24 1410
无人共我
无人共我 2020-11-22 02:55

How can I tell whether a circle and a rectangle intersect in 2D Euclidean space? (i.e. classic 2D geometry)

24条回答
  •  死守一世寂寞
    2020-11-22 03:02

    Actually, this is much more simple. You need only two things.

    First, you need to find four orthogonal distances from the circle centre to each line of the rectangle. Then your circle will not intersect the rectangle if any three of them are larger than the circle radius.

    Second, you need to find the distance between the circle centre and the rectangle centre, then you circle will not be inside of the rectangle if the distance is larger than a half of the rectangle diagonal length.

    Good luck!

提交回复
热议问题