Line and Polygon clipping returns empty Paths using Clipper library (c++)

北城以北 提交于 2019-12-24 08:27:20

问题


I am trying to split a polygon by a line using the Clipper library. After the execution of clipping, it returns empty path. Can someone suggest the right way to do the same.


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

The soln size is zero.


回答1:


Clipper does not allow lines (open paths) to clip polygons (closed paths). However it does allow lines to be clipped by polygons. (More info here.)

Also, in your code, both paths (subject and clip) appear to be added as closed paths, and since the subject has no area, the intersection of this with the clip polygon will also have no area, hence the empty solution.



来源:https://stackoverflow.com/questions/41999919/line-and-polygon-clipping-returns-empty-paths-using-clipper-library-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!