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
Oktalist
source share