简体   繁体   中英

Partition of graph to locate a point

I have an area which was already partitioned into tens of sub-areas (think like a country divided into states).

Now I have a point coordinate, what is the best algorithm to tell me which state the point in?

Of course I can match sub-area by sub-area but that's stupid because I have to search through half of them in average right?

Is there an algorithm to determine how to group several adjacent sub-area together to facilitate search, so as to optimize the number of search?

I would start by eliminating all areas that cannot have the point inside of them.

Let's assume that you have a 2D Cartesian coordinate system, you have a point as a 2D-vector and the areas are described as a collection of their boundary points.

Then you can sort the areas by their smallest and largest x and y coordinate (in total 4 ways of sorting). You can eliminate all areas which have their smallest x coordinate bigger than the x coordinate of your point etc.

After that, you can check the remaining polygons with a simple ray-casting algorithm and you should be good.

This is very efficient if you have a structure which keeps the areas sorted in all the different directions because you can eliminate the areas in logarithmic time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM