2017-02-02 58 views
1

我想通过一条线使用Clipper库拆分多边形。剪切执行后,它返回空路径。有人可以建议正确的方法来做同样的事情吗?线和多边形裁剪返回空使用Clipper库的路径(C++)


Paths clip(2),soln; 
clip[0] << IntPoint(-264,-210) << IntPoint(650,-209); 
Path sub = clip[0]; 
Path poly << IntPoint(531,49) << IntPoint(-21,49) << IntPoint(-970,-961) << IntPoint(-945,-1019) << IntPoint(1045,-1071) ; 
Clipper c; 
c.AddPath(poly,ptSubject,true); 
    c.AddPath(sub,ptClip,true); 
    c.Execute(ctIntersection,soln,pftNonZero, pftNonZero); 
    std::cout << soln.size() << "soln size"; 

的SOLN尺寸是零。

回答

3

Clipper不允许线(开放路径)剪辑多边形(封闭路径)。但它确实允许线条被多边形裁剪。 (More info here.)

此外,在您的代码中,两个路径(主题和剪辑)看起来都被添加为封闭路径,并且由于主题没有区域,因此与剪辑多边形的交集也将没有区域,因此空解决方案。