Intersecting Lines Using Boost Geometry

How can a line be represented using Boost Geometry?

I do not need a final segment, but I need infinite lines (maybe Segment or Linestring can be expanded?)

As I understand it, I can use boost::geometry::intersects , but I don't know how to define an infinite line.

+2
c ++ boost line boost-geometry
source share
1 answer

If you want to check if an infinite line A intersects a segment of line B , this can be done using 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 string using a segment that is part of this string, but as a separate type, so it can be distinguished from a segment by a type system for overload purposes.

First he asks which side of A are two endpoints ( first and second ) of B Then, if either of the firstSide or secondSide is zero, this means that the corresponding endpoint is tangent to A , so intersects true. Otherwise, intersects true if the endpoints are on opposite sides of A

0
source share

All Articles