Unioning Regions

How can I union a number of regions represented by a set of pints. The union is also represted by a set of points. Is there an algorithm for doing that. If there is, Please advice.

Thank you.
Who is Participating?
JaccoConnect With a Mentor Commented:
I presume you do 2D region unions.
And that the regions are closed paths.
The combined region is one region.
The drawing order of the point of all united regions is in the
same direction (i.e. clockwise or counterclockwise)

First you need a algoritm for PointInRegion (Windows supplies it PtInRegion). This algoritm will help you identifying point that do not ly within other regions (these points will not become part of the new region).

PointInRegion algoritm:

- Draw a line from X,Y to outside the region (MinX-1,MinY-1)
- Count the number of times you cross the region lines
  (Iterate all line parts of the region and detect crossing)
  (be aware of the fact that your line might be parrallel to
   one of the lines in the region, prevent that)
Result = Even means the point is outside the region
Result = Odd means the point is inside the region

Union algorithm:

- Mark all points that are in none of the other regions for deletion
  (some regions might be deleted completely)
- Choose a starting point from the non-deleted points
  (choose the first non-deleted point from a non-deleted region)
- Follow the points of the choosen region around and add them
  to your new region if the line added this way doesn't intersect
  with a line of the other regions.
  - if you end at the starting point this region is a stand alone
    and you should rechoose a start to continue
  - if a line crossing is detected create this cross point as a
    point of the new region step over to the region the crossing
    occured with at the point after the crossing

All Courses

From novice to tech pro — start learning today.