我是个新来的boost,所有我尝试的结果都是满屏的编译器错误。 这是我最新的尝试。
#include <boost/geometry/algorithm/convex_hull.hpp>
#include <boost/geometry/algorithm/area.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/multi_point.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
namespace bg = boost::geometry
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
double getHullArea(std::vector<double> x, std::vector<double> y) {
typedef boost::tuple<double,double> point;
typedef bg::model::multi_point<point> points;
points p;
for (size_t i=0; i<x.size(); i++) {
bg::append(p, point(x[i],y[i]));
}
bg::model::polygon hull;
bg::convex_hull(p, hull);
return bg::area(hull);
}
我知道有一些聪明的方法可以避开多点 但我想知道我的这种基本方法有什么问题 错误出现在 convex_hull
调用,可能与我如何定义 船体.
EDIT: 添加了我在得到错误时使用的包含。
问题出在包括上。 <boost/geometry.hhp>
必须包含。 这个工作。
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/multi_point.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
namespace bg = boost::geometry
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
double getHullArea(std::vector<double> x, std::vector<double> y) {
typedef boost::tuple<double,double> point;
typedef bg::model::multi_point<point> points;
points p;
for (size_t i=0; i<x.size(); i++) {
bg::append(p, point(x[i],y[i]));
}
bg::model::polygon hull;
bg::convex_hull(p, hull);
return bg::area(hull);
}