[英]Lines intersection using Boost Geometry
How line can be represented using Boost Geometry?如何使用 Boost Geometry 表示线?
I don't need finite segment, but I need infinite lines (maybe Segment or Linestring can be extended?)我不需要有限段,但我需要无限线(也许可以扩展段或线串?)
As I understand I can use boost::geometry::intersects
, but I don't know how to define infinite line.据我所知,我可以使用
boost::geometry::intersects
,但我不知道如何定义无限线。
If you want to test whether an infinite line A
intersects a line segment B
, this can be done using boost::geometry::strategy::side::side_by_triangle
:如果要测试无限线
A
是否与线段B
相交,可以使用boost::geometry::strategy::side::side_by_triangle
:
template <typename Point>
struct line
{
boost::geometry::model::segment<Point> segment;
};
template <typename Point>
bool intersects(line<Point> const& A, boost::geometry::model::segment<Point> const& B)
{
using side = boost::geometry::strategy::side::side_by_triangle<>;
auto const firstSide = side::apply(A.segment.first, A.segment.second, B.first);
auto const secondSide = side::apply(A.segment.first, A.segment.second, B.second);
return firstSide == 0 || secondSide == 0 || (firstSide < 0) != (secondSide < 0);
}
The line
type simply represents a line using a segment that is part of that line, but as a separate type so it can be distinguished from a segment by the type system, for the purposes of overloading. line
类型简单地使用作为该线一部分的线段来表示线,但作为单独的类型,因此可以通过类型系统将其与线段区分开,以实现重载。
It first queries on which side of A
the two endpoints ( first
and second
) of B
lie.它首先查询其上的侧
A
两个端点( first
和second
)的B
谎言。 Then, if either of firstSide
or secondSide
are zero, this means the corresponding endpoint is touching A
, so intersects
is true.然后,如果
firstSide
或secondSide
中的任何一个为零,这意味着相应的端点正在接触A
,因此intersects
为真。 Otherwise, intersects
is true iff the endpoints are on opposite sides of A
.否则,如果端点位于
A
两侧,则intersects
为真。
Maybe it will helps, function intersection_point calculates intersection point of two infinite lines.也许它会有所帮助,函数intersection_point计算两条无限长线的交点。 https://www.boost.org/doc/libs/1_72_0/boost/geometry/geometries/infinite_line.hpp https://www.boost.org/doc/libs/1_72_0/boost/geometry/arithmetic/infinite_line_functions.hpp
https://www.boost.org/doc/libs/1_72_0/boost/geometry/geometries/infinite_line.hpp https://www.boost.org/doc/libs/1_72_0/boost/geometry/arithmetic/infinite_line_functions.hpp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.