c++ - Boost.Geometry polygon point assignment -


i trying use boost geometry , having trouble assigning points polygon. lets assume create static vector of points

boost::geometry::model::d2::point_xy<double> >* a;  

and create polygon:

boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon; 

assuming have defined values of points of a.

how can assign points p?

the boost::geometry::assign_points() algorithm can used assign range of points polygon.

if a range of points , p polygon, 1 use:

boost::geometry::assign_points(p, a); 

here complete example demonstrating usage of assign_points:

#include <iostream> #include <vector> #include <boost/assign/std/vector.hpp> #include <boost/geometry.hpp> #include <boost/geometry/algorithms/area.hpp> #include <boost/geometry/algorithms/assign.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> #include <boost/geometry/io/dsv/write.hpp>  int main() {     using namespace boost::assign;     typedef boost::geometry::model::d2::point_xy<double> point_xy;      // create points represent 5x5 closed polygon.     std::vector<point_xy> points;     points +=       point_xy(0,0),       point_xy(0,5),       point_xy(5,5),       point_xy(5,0),       point_xy(0,0)       ;      // create polygon object , assign points it.     boost::geometry::model::polygon<point_xy> polygon;       boost::geometry::assign_points(polygon, points);      std::cout << "polygon " << boost::geometry::dsv(polygon) <<        " has area of " << boost::geometry::area(polygon) << std::endl; } 

which produces following output:

polygon (((0, 0), (0, 5), (5, 5), (5, 0), (0, 0))) has area of 25 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -