【问题标题】:How can we get all the points stored in boost polygon我们如何获得存储在 boost 多边形中的所有点
【发布时间】:2017-04-28 07:01:12
【问题描述】:

我正在尝试遍历增强多边形中的所有点。 有 API 来处理这个吗?

【问题讨论】:

  • Boost.Polygon 多边形还是 Boost.Geometry 多边形?

标签: c++ boost polygon


【解决方案1】:

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)

需要一个多边形模型。返回对应于多边形顶点的点范围内的开始迭代器。

template <typename T> point_iterator_type end_points(const T& polygon)

需要一个多边形模型。返回对应于多边形顶点的点范围内的结束迭代器。

【讨论】:

    【解决方案2】:

    这是一个设置和检索 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...
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-05
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      相关资源
      最近更新 更多