0
2つの交差するポリゴンの交差線(最初の交差点から最後の交差点まで)を簡単にどのように取得できますか?明確にするために画像を参照してください、緑色の線は私が望むものです。CGALでポリゴン交差点を取得
現在、私は私が交差ポリゴンを取得し、両方のポリゴンの境界上にあるポイントを見つけ、これらは交点である必要があり、次のアルゴリズムを使用します。ここにコード内にあります:
Polygon_2 P,Q;
Pwh_list_2 intR;
Pwh_list_2::const_iterator it;
CGAL::intersection(P, Q, std::back_inserter(intR));
//Loop through intersection polygons
for (it = intR.begin(); it != intR.end(); ++it) {
boost::numeric::ublas::vector<double> firstIntersectPoint(3), lastIntersectPoint(3);
Polygon_2 Overlap = it->outer_boundary();
typename CGAL::Polygon_2<Kernel>::Vertex_iterator vit;
int pointNr = 1;
//Loop through points of intersection polygon to find first and last intersection point.
for (vit = Overlap.vertices_begin(); vit != Overlap.vertices_end(); ++vit) {
CGAL::Bounded_side bsideThis = P.bounded_side(*vit);
CGAL::Bounded_side bsideArg = Q.bounded_side(*vit);
if (bsideThis == CGAL::ON_BOUNDARY && bsideArg == CGAL::ON_BOUNDARY && pointNr == 1) {
firstIntersectPoint <<= 0, CGAL::to_double(vit->x()), CGAL::to_double(vit->y());
pointNr = 2;
}
else if (bsideThis == CGAL::ON_BOUNDARY && bsideArg == CGAL::ON_BOUNDARY && pointNr == 2) {
lastIntersectPoint <<= 0, CGAL::to_double(vit->x()), CGAL::to_double(vit->y());
pointNr = 2;
}
}
//RESULT
std::cout << firstIntersectPoint << std::endl;
std::cout << lastIntersectPoint << std::endl;
}
これは動作しますが、正しい方法ではないと思います。誰かが私にこれを行う正しい方法であるかどうかを示すことができますか、それをより良くする方法を私の指針に教えてください。
尋ねることは嫌ですが、おそらく少しのコードを提供するのに気をつけることができますか?私はCGALには比較的新しいので、CGAL :: Polygonから2Dアレンジメントに到達してその程度を得ることはできません。 –
各ポリゴンを反復的に挿入するだけでよいのはなぜですか? – BeyelerStudios
この機能はplane-sweepフレームワークに基づいているため、一度にすべてのセグメントを挿入する方が効率的です。 –