使用 Clipper(C#) 偏移轮廓时出现错误

问题描述

当我使用 Clipper(C#) 偏移轮廓时出现错误, 下面是路径和代码

List<List<IntPoint>> contours = new List<List<IntPoint>>() {
    new List<IntPoint>()
    {
        new IntPoint(89081288,31121153),new IntPoint(79573289,41300154),new IntPoint(89989888,51429549)
    },new List<IntPoint>()
    {
        new IntPoint(103433436,22509154),new IntPoint(103687434,32572554),new IntPoint(93177234,22454711)
    }
};
List<List<IntPoint>> result = new List<List<IntPoint>>();

ClipperOffset co = new ClipperOffset();
co.Addpaths(contours,JoinType.jtMiter,EndType.etClosedpolygon);
co.Execute(ref result,1 * 1000000);

图片

Offset Error

非常感谢?

解决方法

解决办法: 在 AddPaths 之前,确保轮廓是正确的,比如方向,没有自交叉......要做到这一点,请使用 Clipper.SimplifyPolygons。

co.AddPaths(Clipper.SimplifyPolygons(contours),JoinType.jtMiter,EndType.etClosedPolygon);