Boost.Geometry介绍_love code, love life.-优快云博客_boost geometry
#include <boost/assign.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
namespace bg = boost::geometry;
typedef bg::model::d2::point_xy<double> DPoint;
typedef bg::model::segment<DPoint> DSegment;
typedef bg::model::linestring<DPoint> DLineString;
typedef bg::model::box<DPoint> DBox;
//这里的ring就是我们通常说的多边形闭合区域(内部不存在缕空),模板参数为true,表示顺时针存储点,为false,表示逆时针存储点,由于MM_TEXT坐标系与传统上的坐标系的Y轴方向是相反的,所以最后为false,将TopLeft、TopRight、BottomRight、BottomLeft、TopLeft以此存储到ring中,以便能正确计算
typedef bg::model::ring<DPoint, false> DRing;
//polygon模板参数false,也是由上面相同的原因得出来的
typedef bg::model::polygon<DPoint, false> DPolygon;
int _tmain(int argc, _TCHAR* argv[])
{
DPoint pt0(100, 100);
DPoint pt1(200, 200);
DSegment sg0(pt0, pt1);
double dDistance = 0;

本文介绍了Boost.Geometry库在C++中的使用,包括点、线段、多边形等几何对象的基本操作,如距离计算、相交判断、交点获取等,并通过示例代码详细展示了其用法。
最低0.47元/天 解锁文章
542

被折叠的 条评论
为什么被折叠?



