视野 PolyRegion2D.Union 具有宽容度

Eyeshot PolyRegion2D.Union with tolerance

我想连接两个几乎相切的多边形。问题是我使用的库不允许指定公差。

我尝试使用的方法是PolyRegion2D.Union。我想获得的结果应该是单个 PolyRegion2D,而不是执行联合。

这是我试过的:

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);

我也尝试将 PolyRegion2D 转换为 Region,指定 Regen 方法的各种偏差,但我得到了相同的结果。

我发现的唯一解决方法是 Offset 在联合之前将区域 Offset 一些,但这似乎势不可挡。

如果我没记错的话,你对 Regen 的推导应该只会影响曲线,所以它不应该影响你的情况,因为你使用了锐利的线条。

偏移量是几何并集的方法。

这就是数学原理。投影矢量,检查交叉点不是魔术。如果没有偏移量,您将不得不发明一种方法来像您想要的那样进行几何联合。