【转】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' 不是内部或外部命令, ...
随机推荐
- 业余实现一个统计A股数据工具
自己瞎捣鼓了几天 python,数据来源新浪财经,每天收盘启动爬虫抓取一遍,web 端呈现日线与周线数据:实时图表显示上证指数与个股指数等.技术点:scrapy apscheduler sqlalch ...
- C#控件事件属性大全
C#控件及常用设计整 1.窗体... 1 2.Label 控件... 3 3.TextBox 控件... 4 4.RichTextBox控件... 5 5.NumericUpDown 控件... 7 ...
- CCF 201509-3 模版生成系统
试题编号: 201509-3 试题名称: 模板生成系统 时间限制: 1.0s 内存限制: 256.0MB 问题描述 成成最近在搭建一个网站,其中一些页面的部分内容来自数据库中不同的数据记录,但是页面的 ...
- JavaScript创建对象的方法汇总
JavaScript中的对象 ECMA-262把对象定义为:“无序属性的集合,其属性可以包含基本值.对象或者函数.”严格来讲,这就相当于说对象是一组没有特性顺序的值.对象的每一个属性或方法都有一个名字 ...
- js实现生成中间带图片的二维码
之前需要实现生成中间带图片的二维码,所以找了半天终于找到一个可以用的.于是在这里记录一下. 下面是需要注意的几点: 1.使用的js为jquery-qrcode 但是已经经过别人的修改,和网上原来的那些 ...
- js便签笔记(7)——style、currentStyle、getComputedStyle区别介绍【转载】
转者语: 今天看jQuery源码CSS部分,里面用到了currentStyle和getComputedStyle来获取外部样式. 因为elem.style.width只能获取elem的style属性里 ...
- 用Javascript开发网页截屏插件
实现思路用html2canvas.js将元素转换成canvas,在将canvas转成图片. html2canvas(document.body, { onrendered: function(canv ...
- Tomcat学习总结(9)——Apache Tomcat 8新特性
一.Apache Tomcat 8介绍 Apache Tomcat 8RC1版于2013年8月份发布.它 经过了2年的开发,引入了很多新特征,由于目前还只是Alpha版,故不推荐在产品中使用.但是我们 ...
- linux firefox 快捷方式
.输入:cd /usr/share/applications .输入:vi firefox.desktop 在vi里面输入以下内容,然后保存并退出: [Desktop Entry] Name=Fire ...
- 第2章:MapReduce
MapReduce是一个数据处理的编程模型.这个模型很简单,但也不是简单到不能够支持一些有用的语言.Hadoop能够运行以多种语言写成的MapReduce程序.在这一章中,我们将看看怎样用Java,R ...