#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的更多相关文章

  1. boost库之geometry<二>

    #include <boost/assign.hpp> #include <boost/geometry/core/point_type.hpp> #include <b ...

  2. boost库之geometry

    环境:win732位旗舰版.VS2010旗舰版.boost 1.55.0版本.坐标系为MM_TEXT Geometry是一个开源的几何计算库,包含了几何图形最基本的操作(也支持复杂的操作),下面我们看 ...

  3. boost库的安装,使用,介绍,库分类

    1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...

  4. C++ Boost库分类总结

    c# 程序员写c++,各种不适应.尤其是被内存操作和几十种字符串类型的转换,简直疯了,大小写转换竟然要手动写代码实现. Boost看介绍不错,也不知道能不能跨平台.过几天要上linux写c++, 也不 ...

  5. 新手,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 ...

  6. vs2013给项目统一配置boost库

    1.打开项目,然后点击菜单中的 视图->其他窗口->属性管理器 2. 打开属性管理器,点击项目前的箭头,展开项目,找到debug或者release下面的Microsoft.Cpp.Win3 ...

  7. [C/C++] C/C++延伸学习系列之STL及Boost库概述

    想要彻底搞懂C++是很难的,或许是不太现实的.但是不积硅步,无以至千里,所以抽时间来坚持学习一点,总结一点,多多锻炼几次,相信总有一天我们会变得"了解"C++. 1. C++标准库 ...

  8. dev c++ Boost库的安装

    dev c++ 的boost库的安装步骤 然后点击“check for updates”按钮 最后点击“Download selected”按钮,下载完成后安装.... 给dev添加boost库文件, ...

  9. vs配置boost库

    步骤: 1.在boost官网下载boost版本,以1.59.0为例. 2.解压,解压后可看到文件夹下有个bootstrap.bat文件. 注意: 如果有以下error: 'cl' 不是内部或外部命令, ...

随机推荐

  1. jsp链接orcl

    自己整的!好用滴!!希望能帮到一些初学者! package lobsterwwww; import java.sql.Connection; import java.sql.DriverManager ...

  2. dhcp服务器(一)

    DHCP服务概述: 名称:DHCP -Dynamic Host Configuration Protocol动态主机配置协议. 功能:DHCP(Dynamic Host Configuration P ...

  3. Dubbo剖析-SPI机制

    文章要点: 1.什么是SPi 2.Dubbo为什么要实现自己的SPi 3.Dubbo的IOC和AOP 4.Dubbo的Adaptive机制 5.Dubbo动态编译机制 6.Dubbo与Spring的融 ...

  4. 揭开Future的神秘面纱——结果获取

    前言 在前面的两篇博文中,已经介绍利用FutureTask任务的执行流程,以及利用其实现的cancel方法取消任务的情况.本篇就来介绍下,线程任务的结果获取. 系列目录 揭开Future的神秘面纱—— ...

  5. 常用的oh-my-zsh插件

    每次换电脑,需要重新配置开发环境是件很麻烦的事情,作为一个有洁癖的人又不想用Time Machine.记忆力大不如以前,很多插件又忘了装.正好下个月又需要给团队小伙伴讲讲提升效率这件事要讲到oh-my ...

  6. SQL分区表示例

    -- Create tablecreate table TT_FVP_OCR_ADDRESS( id NUMBER not null, waybill_no VARCHAR2(32) not null ...

  7. POJ 1002 487-3279(map映照容器的使用)

    Description Businesses like to have memorable telephone numbers. One way to make a telephone number ...

  8. zoj Beautiful Number(打表)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2829 题目描述: Mike is very lucky, as ...

  9. Eclipse中使用printf报错 提示参数类型不对

    报错信息: The method printf(String, Object[]) in the type PrintStream is not applicable for the argument ...

  10. Hibernate里面如何使用DetachedCriteriaCriteria 实现多条件分页查询

    WEB层: // 获取分页的请求参数 String start = request.getParameter("start"); String page = request.get ...