Search code examples
eyeshot

Eyeshot PolyRegion2D.Union with tolerance


I would like to join two polygons which are nearly tangent. The problem is that the library that I use does not allow to specify a tolerance.

The method I tried to use is PolyRegion2D.Union. The result I would like to obtain should be a single PolyRegion2D, no union is performed instead.

This is what I tried:

Polygon2D pa = new Polygon2D(new Point2D[] {
    new Point2D(1.15938971595503,-0.199967078272286),
    new Point2D(1.52634922341708,-0.420128484528485),
    new Point2D(1.70641430562392,-0.120000722926738),
    new Point2D(1.17299051700752,0.200032892324767),
    new Point2D(0.561190378505281,0.200032892324767),
    new Point2D(0.561190378505281,-0.199967078272286),
    new Point2D(1.15938971595503,-0.199967078272286)
});
PolyRegion2D a = new PolyRegion2D(new Polygon2D[] { pa });

Polygon2D pb = new Polygon2D(new Point2D[] {
    new Point2D(2.15660570919657,-0.39009846249557),
    new Point2D(1.70641430562392,-0.120000887257862),
    new Point2D(1.52634925853194,-0.420128484528485),
    new Point2D(1.97654066210459,-0.690226059766193),
    new Point2D(2.15660570919657,-0.39009846249557)
});
PolyRegion2D b = new PolyRegion2D(new Polygon2D[] { pb });

PolyRegion2D[] ab = PolyRegion2D.Union(a, b);

Assert.AreEqual(1, ab.Length);

I tried also to convert the PolyRegion2Ds to Region, specifing various deviations on the Regen method, but I obtain the same result.

The only workaround that I've found is to Offset the regions by some amount before the union, but it seems overwhelming.


Solution

  • Your derivation on Regen should only affect curves if i am not mistaken, so it shouldn't affect anything in your case since you use sharp lines.

    Offset is the way to go for the geometry union.

    That's how the maths work. Projecting vectors, checking for intersection doesn't work by magic. Without offset you would have to invent a way to do geometry unions like you would want.