I am dealing with a programming challenge, In that I need to find the region which the given point belongs to. There is some methods here for that problem.
So I decide to use slab decomposition, It is fast enough, easier to implement, and space is not much of a problem for me. However, I am having trouble about where to start. Here is an example of slab decomposition from a pdf file made by UC Santa Barbara.
I store the geometrical shape in a node dictionary like an undirected graph (Using coordinates).
defaultdict(<type 'list'>, {(4.0, 5.0): [(1.0, 2.0), (2.0, 3.0), (3.0, 5.0)],
(1.0, 2.0): [(2.0, 3.0), (2.0, 4.0), (3.0, 5.0), (4.0, 5.0)],
(2.0, 3.0): [(1.0, 2.0), (2.0, 4.0), (4.0, 5.0)],
(2.0, 4.0): [(1.0, 2.0), (2.0, 3.0), (3.0, 5.0)],
(3.0, 5.0): [(1.0, 2.0), (2.0, 4.0), (4.0, 5.0)]})
Like so. (Still don't know if a edges list would be better ?)
Now I know how to solve the problem, however having difficulty deciding which way to implement because the input will be a very complex geometrical shape and finding the point will be expensive in cpu resources.
I decided to store each point (sorted using x coordinates) in a sorted list(using bisect). To acquire slabs. However, I could not find a way to find how the slabs intersect with the region edges, or how to partition the slab as shown in the picture. Actually I did find a way but it did not feel feasible to me. I could check the edges which starts from the left of the slab and end at the right of it. Which means the edge is crossing the slab. This is fine, however to accomplish that I would have to check almost the half of the vertices each time a new node is given and the regions increase. So This method sounded like a failure to me. There is also the problem to knowing which region does the region in the slab belongs to. Given that we are doing all this to avoid checking all the regions one-by-one to improve speed.
If you could give me some ideas on the subject, I don't require any piece of code. I just need advice from experienced users here. I am stuck because I can't be sure how to implement it and I don't want to start it the wrong way and rewrite it whole. (I can assure you this is no homework.)
Note1: I could not be sure about the data structure, should I make a structure for regions?, or for points ? or edges ? Or do I need a structure for a creating a search tree ? What would I have to store in this structure ?
Note2: I know how to find which slabs the point lies. I also know how to find the point with binary search inside the slabs. I am lacking more conseptual knowledge, hence experience. Like how to represent regions in the first place.
Thanks in advance.