【转】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(, );
DPoint pt1(, );
DSegment sg0(pt0, pt1); double dDistance = ; //1、点到点的距离
dDistance = bg::distance(pt0, pt1);
//2、点到线段的距离,如果点到直线的垂足不在线段上,所计算的距离为(点到直线的距离、线段到垂足延长的距离之和)
dDistance = bg::distance(DPoint(, ), sg0);
dDistance = bg::distance(DPoint(, ), sg0); //3、判断线段是否相交
DSegment sg1(DPoint(, ), DPoint(, ));
DSegment sg2(DPoint(, ), DPoint(, ));
bool bIntersect = false;
bIntersect = bg::intersects(sg0, sg1);
bIntersect = bg::intersects(sg0, sg2); //4、求线段与线段的交点
std::list<DPoint> lstPoints;
bg::intersection(sg0, sg1, lstPoints);
lstPoints.clear();
bg::intersection(sg0, sg2, lstPoints); DBox rc2(DPoint(, ), DPoint(, )); //5、判断box是否相交
DBox rc(DPoint(, ), DPoint(, ));
DBox rc0(DPoint(, ), DPoint(, ));
DBox rc1(DPoint(, ), DPoint(, )); bIntersect = bg::intersects(rc, rc0);
bIntersect = bg::intersects(rc, rc1);
//bg::intersection(rc, rc0, container);//error //6、判断box是否与LineString相交
DLineString line0; line0.push_back(DPoint(, ));
line0.push_back(DPoint(, ));
line0.push_back(DPoint(, -));
line0.push_back(DPoint(, ));
bIntersect = bg::intersects(rc, line0);
bIntersect = bg::intersects(rc0, line0); //7、求box与linestring的交点
std::list<DLineString> lstLines;
bg::intersection(rc, line0, lstLines); //8、点是否在box内
DBox rc7(DPoint(, ), DPoint(, ));
bool bInside = false;
bInside = bg::within(DPoint(, ), rc7);
bInside = bg::within(DPoint(, ), rc7); //9、判断LineString与LineString是否相交
DLineString line1, line2, line3; line1.push_back(DPoint(, ));
line1.push_back(DPoint(, ));
line1.push_back(DPoint(, ));
line1.push_back(DPoint(, ));
line2.push_back(DPoint(, ));
line2.push_back(DPoint(, ));
line2.push_back(DPoint(, ));
line3.push_back(DPoint(, ));
line3.push_back(DPoint(, )); bIntersect = bg::intersects(line1, line2);
bIntersect = bg::intersects(line1, line3); //10、求LineString与LineString的交点
lstPoints.clear();
bg::intersection(line1, line2, lstPoints);
lstPoints.clear();
bg::intersection(line1, line3, lstPoints); //11、判断ring与ring是否相交
DPoint arDPoint0[] = {DPoint(, ), DPoint(, ), DPoint(, ), DPoint(, ), DPoint(, ), DPoint(, )};
DPoint arDPoint1[] = {DPoint(, ), DPoint(, ), DPoint(, ), DPoint(, ), DPoint(, ), DPoint(, )};
DRing r0(arDPoint0, arDPoint0 + );
DRing r1(arDPoint1, arDPoint1 + );
bIntersect = bg::intersects(r0, r1); //12、求ring与ring的交点
lstPoints.clear();
bg::intersection(r0, r1, lstPoints); DPolygon poly1;
DPolygon poly2;
DPolygon poly3; auto lstOf = boost::assign::list_of(DPoint(, ))(DPoint(, ))(DPoint(, ))(DPoint(, ))(DPoint(, ));
poly1.outer().assign(lstOf.begin(), lstOf.end());
lstOf = boost::assign::list_of(DPoint(, ))(DPoint(, ))(DPoint(, ))(DPoint(, ))(DPoint(, ));
poly1.inners().push_back(lstOf);
lstOf = boost::assign::list_of(DPoint(, ))(DPoint(, ))(DPoint(, ))(DPoint(, ))(DPoint(, ));
poly2.outer().assign(lstOf.begin(), lstOf.end());
lstOf = boost::assign::list_of(DPoint(, ))(DPoint(, ))(DPoint(, ))(DPoint(, ))(DPoint(, ));
poly3.outer().assign(lstOf.begin(), lstOf.end()); //13、判断polygon与polygon是否相交
bIntersect = bg::intersects(poly1, poly2);
bIntersect = bg::intersects(poly1, poly3); //14、求polygon与polygon相交的区域
std::list<DPolygon> lstPolygon; bg::intersection(poly1, poly2, lstPolygon);
lstPolygon.clear();
bg::intersection(poly1, poly3, lstPolygon); //15、判断点是否在polygon内
bInside = bg::within(DPoint(, ), poly1);
bInside = bg::within(DPoint(, ), poly1); return ;
}
转自:http://blog.csdn.net/dc2010_/article/details/23132521
【转】boost库之geometry的更多相关文章
- boost库之geometry<二>
#include <boost/assign.hpp> #include <boost/geometry/core/point_type.hpp> #include <b ...
- boost库之geometry
环境:win732位旗舰版.VS2010旗舰版.boost 1.55.0版本.坐标系为MM_TEXT Geometry是一个开源的几何计算库,包含了几何图形最基本的操作(也支持复杂的操作),下面我们看 ...
- boost库的安装,使用,介绍,库分类
1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...
- C++ Boost库分类总结
c# 程序员写c++,各种不适应.尤其是被内存操作和几十种字符串类型的转换,简直疯了,大小写转换竟然要手动写代码实现. Boost看介绍不错,也不知道能不能跨平台.过几天要上linux写c++, 也不 ...
- 新手,Visual Studio 2015 配置Boost库,如何编译和选择,遇到无法打开文件“libboost_thread-vc140-mt-gd-1_63.lib“的解决办法
1,到官网下载最新的boost,www.boost.org 这里我下载的1-63版本. 2,安装,解压后运行bootstrap.bat文件.稍等一小会就OK. 3,编译boost库.注意一定要使用VS ...
- vs2013给项目统一配置boost库
1.打开项目,然后点击菜单中的 视图->其他窗口->属性管理器 2. 打开属性管理器,点击项目前的箭头,展开项目,找到debug或者release下面的Microsoft.Cpp.Win3 ...
- [C/C++] C/C++延伸学习系列之STL及Boost库概述
想要彻底搞懂C++是很难的,或许是不太现实的.但是不积硅步,无以至千里,所以抽时间来坚持学习一点,总结一点,多多锻炼几次,相信总有一天我们会变得"了解"C++. 1. C++标准库 ...
- dev c++ Boost库的安装
dev c++ 的boost库的安装步骤 然后点击“check for updates”按钮 最后点击“Download selected”按钮,下载完成后安装.... 给dev添加boost库文件, ...
- vs配置boost库
步骤: 1.在boost官网下载boost版本,以1.59.0为例. 2.解压,解压后可看到文件夹下有个bootstrap.bat文件. 注意: 如果有以下error: 'cl' 不是内部或外部命令, ...
随机推荐
- bower 和 npm 的区别
前端技术和工程实践真的是突飞猛进啊,想当年,我这个半业余前端吭哧吭哧做页面的时候,哪有这么多东西可以用啊,现在先进到我都完全看不懂了.本文主要讲一下同是包管理器的bower和npm的差别. 主要也是在 ...
- mysql索引总结(4)-MySQL索引失效的几种情况
mysql索引总结(1)-mysql 索引类型以及创建 mysql索引总结(2)-MySQL聚簇索引和非聚簇索引 mysql索引总结(3)-MySQL聚簇索引和非聚簇索引 mysql索引总结(4)-M ...
- ffplay源码分析1-概述
本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10301215.html ffplay是一个很简单的播放器,但是初次接触仍会感到概念和细节 ...
- UIKit 框架之UIControl
前面的UIWebView.UIImageView这些都是视图,显示为主,与用户交互较少,最多也就是通过UIResponder与用户交互.但这样会很麻烦,还要判断点击次数等等问题,那问题就来了:OC中怎 ...
- Mouse点击之后,复制GridView控件的数据行
本篇是实现用mouse点击GridView控件任意一行,把所点击的数据复制至另一个GridView控件上. 实现大概思路,把所点击的数据行的记录主键找出来,再去过滤数据源. 点击功能,已经实现,可以参 ...
- MVC用非Entity Framework将数据显示于视图
学习此篇之前,先看看<DataTable数据显示于MVC应用程序>http://www.cnblogs.com/insus/p/3361182.html 那是将DataTable显示于MV ...
- C# 文本转语音,在语音播放过程中停止语音
1,运用SpVoice播放语音 在VS2013创建Windows窗体应用程序项目,添加引用COM组件Microsoft Speech Object Library: using SpeechLib; ...
- 批量导出VBA工程中的Source
在做Excel宏相关项目的开发和维护过程中,我们经常需要导出VBA中的Source,但是Excel提供的宏编辑器中只能一个文件一个文件地导出,很不方便. 下面介绍2种批量导出的方法: 1.Source ...
- 了解java虚拟机—垃圾回收算法(5)
引用计数器法(Reference Counting) 引用计数器的实现很简单,对于一个对象A,只要有任何一个对象引用了A,则A的引用计数器就加1,当引用失效时,引用计数器减1.只要对象A的引用计数器的 ...
- 设计模式——适配器模式(type-c转3.5mm耳机口)
本文首发于cdream的个人博客,点击获得更好的阅读体验! 欢迎转载,转载请注明出处. 本文简述适配器模式,考虑到java中没有多继承就只写了对象适配器模式,然后例子是怎么用转接口把3.5mm耳机插在 ...