使用boost几何检查,如果两条线有交点 [英] Using boost geometry to check if two lines have an intersection

查看:787
本文介绍了使用boost几何检查,如果两条线有交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用boost ::几何检查两个线段(各两点在2D给出)是否彼此相交?如果这是可能的,确实提振::几何允许还检查特殊情况下,如只有一个点(数字)的其他线路,或者两条线都是平等的?

Is it possible to use boost::geometry to check whether two line segments (each given by two points in 2D) intersect each other? If this is possible, does boost::geometry allow to check also for special cases such as that only one point is (numerically) on the other line, or that both lines are equal?

推荐答案

如果你正Boost.Geometry API专门谈论它,当然是可能的。

If you are talking specifically about Boost.Geometry API to it is, of course, possible.

您code应该大致如下

Your code should look roughly like this

#include <boost/geometry/geometries/segment.hpp> 
#include <boost/geometry/algorithms/intersection.hpp>

typedef boost::geometry::model::segment<Point> Segment;
Segment AB( Point(x1,y1), Point(x2,y2) );
Segment CD; //similar code

bool result = boost::geometry::intersects(AB, CD);

如果您需要交点:

std::vector<Point> output; 
boost::geometry::intersection(AB, CD, output);

现在输出将具有0,1或2个点,这取决于位置。

Now output will have 0, 1 or 2 points, depending on locations.

当然,你点的类型应该是兼容与Boost.Geometry概念。下面code将使QPointF标准:

Of course, your Point type should be "compliant" with Boost.Geometry concepts. The following code will make QPointF compliant:

#include <boost/geometry/geometries/register/point.hpp>
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(QPointF, qreal, cs::cartesian, x, y, setX, setY);

这篇关于使用boost几何检查,如果两条线有交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆