使用boost::geometry::union_ 合并边界(内、外):方案二
typedef boost::geometry::model::d2::point_xy<double> boost_point;
typedef boost::geometry::model::polygon<boost_point> boost_Polygon;
struct Point
{
float x;
float y;
Point(float _x,float _y)
{
x = _x;
y = _y;
}
Point(const boost_point & pt)
{
x = pt.x();
y = pt.y();
}
operator boost_point()
{
return boost_point(x, y);
}
};
bool TestClientTrafficEvent::TestBorderCombine()
{
//str_points_of_cur_frame_data = "POLYGON((1.500000 1.500000,1.500000 2.500000,2.500000 2.500000,2.500000 1.500000,1.500000 1.500000))".
std::vector<Point> lhs;
{
Point lhs_p1(1.5, 1.5);
Point lhs_p2(1.5,2.5); //remain
Point lhs_p3(2.5, 2.5); //remain
Point lhs_p4(2.5, 1.5);
Point lhs_p5(1.5, 1.5);
lhs.push_back(lhs_p1);
lhs.push_back(lhs_p2);
lhs.push_back(lhs_p3);
lhs.push_back(lhs_p4);
lhs.push_back(lhs_p5);
}
//str_points_of_compared_frame_data = "POLYGON((1.000000 1.000000,1.000000 2.000000,2.000000 2.000000,2.000000 1.000000,1.000000 1.000000))";
std::vector<Point> rhs;
{
Point rhs_p1(1.0, 1.0);
Point rhs_p2(1.0, 2.0);
Point rhs_p3(2.0, 2.0);
Point rhs_p4(2.0, 1.0);
Point rhs_p5(1.0, 1.0);
}
boost_Polygon lhs_lt, rhs_lt;
for (auto & pt : lhs)
{
boost::geometry::append(lhs_lt, (boost_point)pt);
}
for (auto & pt : rhs)
{
boost::geometry::append(rhs_lt, (boost_point)pt);
}
//进行并集计算
std::vector<boost_Polygon> r;
boost::geometry::union_(lhs_lt, rhs_lt, r);
//通过验证:与传入的顺序无关,均返回相同的结果。
std::vector<Point> vctr_combined ;
if (!r.empty())//有结果返回
{
for (auto & pt : r[0].outer())
{
vctr_combined.push_back(pt);
}
}
std::cout << "vctr_combined.size() = " << vctr_combined.size() << std::endl;
for(auto iter : vctr_combined)
{
std::cout << "iter.x = " << iter.x << ", iter.y = " << iter.y << std::endl;
}
return true;
}
-
P1、P5 为新增自动生成的交叉点
-
P1为首位重合点
-
P1 ~ P8 ~ P8 为顺时针顺序文章来源:https://www.toymoban.com/news/detail-691748.html
文章来源地址https://www.toymoban.com/news/detail-691748.html
到了这里,关于使用boost::geometry::union_ 合并边界(内、外):方案二的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!