Fast algorithm to find all points inside a rectangle

前端 未结 5 742
忘了有多久
忘了有多久 2021-02-14 17:04

Given a set of distinct points in 2D space, and a rectangle (coordinates of all four points, sides parallel with xy axis) how can I quickly find which points are inside the rect

5条回答
  •  难免孤独
    2021-02-14 17:30

    You could group point in sectors. If a sector is completely in or out of given rectangle then all point within it are also in or out. If a sector is partially in then you have to search O(n) for points in that sector to check if they are in the rectangle. Look for k-d tree search.

提交回复
热议问题