【转】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' 不是内部或外部命令, ...
随机推荐
- ubuntu安转QTcreator出现The default mkspec symlink is broken
QT Creator安装:https://blog.csdn.net/arackethis/article/details/42326967 QT SDK安装:https://blog.csdn.ne ...
- spring 后处理器
Bean后处理器 新建maven项目并添加spring依赖,目录结构如下 Axe public interface Axe { public String chop(); } Person publi ...
- screen 实战后台命令执行备份
一.安装 [root@vmware ~]# yum install -y screen 二.直接在命令行键入 screen 命令 [root@vmware ~]# screen 三.暂时终端会话 那么 ...
- Linux 上SSH 服务的配置和管理
0.前期准备:清空防火墙,关闭SELinux. [root@localhost ~]# iptables -F #清空防火墙 [root@localhost ~]# /etc/init.d/iptab ...
- Linux-(inotify-tools&rsync)
inotifywait命令 mac中的是:fswatch,fsevents-tools. 1.命令格式: inotifywait [参数] [events] [targetDir] 2.命令功能: 平 ...
- Android so文件进阶 <一>
0x00 前言 最近一段时间在弄android方面的东西,今天有人发了张截图,问:在要dump多大的内存? 一时之间我竟然想不起来ELF文件的哪个字段表示的是文件大小,虽然最后给出了解决方法,I ...
- vue的路由懒加载
路由懒加载官方介绍 非懒加载写法: import Login from '@/components/Login' 所有路由涉及到的文件会被打包到 app.xxx.js 中 懒加载写法: const L ...
- C编程基础
1. Hello World! 依照惯例首先Hello World镇楼: 1 #include<stdio.h> 2 3 int main(void) { 4 printf("H ...
- [AHOI 2013]差异
Description 题库链接 给定一个长度为 \(n\) 的字符串 \(S\) ,令 \(T_i\) 表示它从第 \(i\) 个字符开始的后缀.求 \[\sum_{1\leqslant i< ...
- 【angular5项目积累总结】avatar组件
View Code import { Component, HostListener, ElementRef } from '@angular/core'; import { Adal4Service ...