Fast algorithm to find all points inside a rectangle

前端 未结 5 751
忘了有多久
忘了有多久 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:33

    I think you should store your points in a quadtree. I have not worked out the details, but it should allow to basically do something similar to a binary search that directly yields the points that are inside an rectangle.

    If your points are clustered, i.e. there exist clusters that contain many points in a small area and other areas that contain no, or very few points an R-tree might be even better.

    Runtime complexity should be O(logN) I think.

提交回复
热议问题