Count points in a rectangle

前端 未结 9 1439
失恋的感觉
失恋的感觉 2020-12-29 23:53

I have lots (billions) of points in 2D which I can preprocess and I would like to answer queries which are of the following form:

Given all four corners of a rectang

9条回答
  •  生来不讨喜
    2020-12-30 00:25

    What you need is some sort of binary space partitioning data structure. That'll get you a list of candidates for which you could do the real "point in polygon" test.

    I'd advise you to make sure that this is something you really ought to be coding on your own. For example, many DBs have this sort of functionality built in. Does your data actually reside in a DB? Could it? (no sense in reinventing wheels...)

    You can see a great answer for the Point in Polygon problem here: How can I determine whether a 2D Point is within a Polygon?

提交回复
热议问题