I have a region of space, 2 dimensions, from (0,0)
to (MAX_X, MAX_Y)
.
Inside this region of space, I draw some lines, they intersect the perimeter of the region and they may intersect one another. In this way, these lines partition my region of space in subregions which, if summed, give the entire region of space.
Inside this region of space, there are some points (x,y)
. I have to determine
- the coordinates of all the vertices composing all the subregions of space created by the lines
- if a given subregion of space contains or not one or more of the points
I'm trying to code this in java, but the language is not really important. I don't have any idea about how to accomplish these two tasks. If anybody can give me an hint I'd really appreciate it.
This is a rather difficult problem of computational geometry. A possible approach could be to represent the resulting regions by a planar subdivision of the original rectangle. The subdivison would be represented by doubly connected edge list (DCEL). This consists of a list of directed half-edges, a list of regions (faces) and a list of vertexes (intersections of the lines). All these data are completely inerconnected, such that finding any data given some other data is very efficient.
The DCEL would be built iteratively, starting with one region which is the original rectangle and adding one line after another. Adding a line means to cut the current DCEL by this line and to obtain a more refined DCEL.
When the final DCEL is constructed, it can be used for finding and marking regions that contain a point. Testing whether a point is in a region can be done efficienly because the regions are convex polygons.
A good book on DCEL is M. de Berg, et.al.: Computational Geometry. You can also find many resources on the Web. You will also find implementations and various software packages.