我试图迭代提升多边形中的所有点。 是否有API来处理这个问题。?
答案 0 :(得分:4)
以下是设置和检索BOOST多边形顶点坐标的简单示例:
#include <boost/geometry.hpp>
namespace bg = boost::geometry;
typedef bg::model::d2::point_xy<double> boost_point;
typedef bg::model::polygon<boost_point> boost_polygon;
[...]
//setting vertices
boost_polygon poly;
bg::append(poly.outer(), boost_point(-1, -1));
bg::append(poly.outer(), boost_point(-1, 1));
bg::append(poly.outer(), boost_point( 1, 1));
bg::append(poly.outer(), boost_point( 1, -1));
bg::append(poly.outer(), boost_point(-1, -1));
//getting the vertices back
for(auto it = boost::begin(boost::geometry::exterior_ring(poly)); it != boost::end(boost::geometry::exterior_ring(poly)); ++it)
{
double x = bg::get<0>(*it);
double y = bg::get<1>(*it);
//use the coordinates...
}
答案 1 :(得分:0)
http://www.boost.org/doc/libs/1_62_0/libs/polygon/doc/gtl_polygon_concept.htm
template <typename T> point_iterator_type begin_points(const T& polygon)
期待多边形模型。返回与多边形顶点对应的点范围内的begin迭代器。
template <typename T> point_iterator_type end_points(const T& polygon)
期待多边形模型。返回与多边形顶点对应的点范围内的结束迭代器。