在索引处提升几何多边形插入点

时间:2017-01-28 15:01:38

标签: c++ boost polygon boost-geometry

如何在多边形索引处添加点? 以正确的索引插入点(2.5,7.5)。

输出:

((0,0),(0,5),(5,5),(5,0),(0,0),(2.5,7.5)))

-------------------▼

((0,0),(0,5),(2.5,7.5),(5,5),(5,0),(0,0)))

#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

int main()
{
    typedef boost::geometry::model::d2::point_xy<double> point;
    typedef boost::geometry::model::polygon<point> polygon;


    polygon poly;

    boost::geometry::append ( poly, point(0, 0) );
    boost::geometry::append ( poly, point(0, 5) );
    boost::geometry::append ( poly, point(5, 5) );
    boost::geometry::append ( poly, point(5, 0) );
    boost::geometry::append ( poly, point(0, 0) );

    poly.outer().push_back( point(2.5, 7.5) );

    std::cout << boost::geometry::dsv(poly) << std::endl;


    return 0;
}

1 个答案:

答案 0 :(得分:0)

根据我的理解,poly.outer只是一个std :: vector,所以你应该可以使用insert方法将值放在所需的索引处:

poly.outer().insert( poly.outer().begin()+2, point(2.5, 7.5) );

live demo