Polygon Collision Testing / Polygon Overlap Test in C# - Not Point in Polygon

I am testing to determine if two polygons overlap. I have developed a first version which does a simple point in polygon test (Fig 1). However I am looking to revamp that method to deal with situations where no vertices of polygon A are in polygon B but their line segments overlap (Fig B).

Any help getting started would be greatly appreciated.

Answers


Here is an example with using Region:

  GraphicsPath grp = new GraphicsPath();

  // Create an open figure
  grp.AddLine(10, 10, 10, 50); // a of polygon
  grp.AddLine(10, 50, 50, 50); // b of polygon
  grp.CloseFigure();           // close polygon

  // Create a Region regarding to grp
  Region reg = new Region(grp);

Now you can use the Method Region.IsVisible to determine whether the region is in an Rectangle or Point.


The solution:

I modified some code found here.

private Region FindIntersections(List<PolyRegion> regions)
{
    if (regions.Count < 1) return null;

    Region region = new Region();
    for (int i = 0; i < regions.Count; i++)
    {
        using (GraphicsPath path = new GraphicsPath())
        {
            path.AddPath(regions[i].Path, false);
            region.Intersect(path);
        }
    }

    return region;
}

The result:


Need Your Help

best way to check variable to be a number

php performance numbers

I have a php script that gets a number from administrator and changes associated user. it was fine until I realized is_numeric and intval functions have a funny behavior. here's the code I used:

How to use CompressionCodec in Hadoop

java hadoop compression mapreduce

I am doing following to do compression of o/p files from reducer: