Geometry 多边形之间的交点作为直线裁剪器
我尝试使用clippC++库来实现<代码> iSbBuriels函数,如下所示。Geometry 多边形之间的交点作为直线裁剪器,geometry,clipperlib,Geometry,Clipperlib,我尝试使用clippC++库来实现 iSbBuriels函数,如下所示。 bool is_bordering(Path p1, Path p2) { Paths solutions; Clipper c; // execute intersection on paths c.AddPath(p1, ptSubject, true); c.AddPath(p2, ptClip, true); c.Execute(ctIntersection, s
bool is_bordering(Path p1, Path p2) {
Paths solutions;
Clipper c;
// execute intersection on paths
c.AddPath(p1, ptSubject, true);
c.AddPath(p2, ptClip, true);
c.Execute(ctIntersection, solutions, pftNonZero);
return (solutions.size() > 0); // the paths share edges
}
int main() {
Path p1, p2;
p1 << IntPoint(0,0) << IntPoint(1,0) << IntPoint(0,1) << IntPoint(0,0);
p2 << IntPoint(1,0) << IntPoint(1,1) << IntPoint(0,1) << IntPoint(1,0);
cout << is_bordering(p1, p2) << endl;
}
bool是_边界(路径p1,路径p2){
路径解决方案;
克利伯c;
//在路径上执行交叉
c、 AddPath(p1,ptSubject,true);
c、 AddPath(p2,ptClip,true);
c、 执行(ctIntersection、solutions、pftNonZero);
return(solutions.size()>0);//路径共享边
}
int main(){
路径p1、p2;
p1示例中的多边形不相交,因此函数is_bordering()按预期返回0。相邻多边形的并集将是单个多边形,因此您也可以测试:
#include "clipper.hpp"
#include <iostream>
using namespace std;
using namespace ClipperLib;
bool is_bordering(Path p1, Path p2) {
Paths _intersection, _union;
Clipper c;
c.AddPath(p1, ptSubject, true);
c.AddPath(p2, ptClip, true);
c.Execute(ctIntersection, _intersection, pftNonZero );
c.Execute(ctUnion, _union, pftNonZero);
return (_intersection.size() > 0 || _union.size() < 2);
}
int main() {
Path p1, p2;
cInt I = 10;
p1 << IntPoint(0, 0) << IntPoint(I, 0) << IntPoint(0, I) << IntPoint(0, 0);
p2 << IntPoint(I, 0) << IntPoint(I, I) << IntPoint(0, I) << IntPoint(I, 0);
cout << is_bordering(p1, p2) << endl;
}
#包括“clipper.hpp”
#包括
使用名称空间std;
使用名称空间ClipperLib;
布尔边界(路径p1、路径p2){
路径_相交_并集;
克利伯c;
c、 AddPath(p1,ptSubject,true);
c、 AddPath(p2,ptClip,true);
c、 执行(ctIntersection,_intersection,pftNonZero);
c、 执行(ctUnion、union、pftNonZero);
返回(_intersection.size()>0 | | | union.size()<2);
}
int main(){
路径p1、p2;
cInt I=10;
p1建议:对我来说,你的路径看起来像是开放的多段线。如果你将路径闭合为多边形,会有任何变化吗?闭合后,不会有任何变化。不幸的是,这对我不起作用,因为一个多边形可以完全位于另一个多边形内部,并且有0个边界并返回真值。是的,你是对的。我们应该如何检查这种情况?(我们可以测试并集或交集是否等于任何多边形,并且两个多边形不相同。)我尝试了类似的操作,检查了并集
,看它是否是单个多边形,但最后检查了异或
,看它是否在结果中创建了孔(这意味着一个完全在另一个里面)。遗憾的是,这在一些边缘情况下不起作用,我只能通过一张图纸来解释,并且它对Clipper进行了两次调用,这是我想要避免的(因为大多边形和速度).是的,的确如此。我发现如果一个多边形完全位于另一个多边形内部,就无法区分它们何时边界和何时边界。我认为需要为此添加一个新的算法,成对检查顶点。xor
技巧确实能区分这些,因为如果它们边界,它不会形成洞,但是t在某些情况下它会失败,其中一个不在另一个的外面,并且它们的边界,但是它们的xor
仍然会产生一个洞