Find rectangles that contain point – Efficient Algorithm

前端 未结 5 1116
自闭症患者
自闭症患者 2020-12-31 08:50

Good afternoon.

My situation:

  • In two-dimensional space.
  • Input: a set of rectangles (ov
5条回答
  •  情书的邮戳
    2020-12-31 09:47

    Here is a simple solution.

    1. Define a grid on your plane.
    2. Each cell maintains two lists: the rectangles that completely cover this cell and the rectangles that partially cover this cell.
    3. On each insertion, put the ID of the target rectangle into all the involved cell lists.
    4. On each query, locate the cell that contains the target point, output the completely cover list and run a scan on the partially cover list.

提交回复
热议问题