...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

Checks if a geometry has at least one intersection (crossing or self-tangency)

template<typename Geometry> bool intersects(Geometry const & geometry)

Type |
Concept |
Name |
Description |
---|---|---|---|

Geometry const & |
Any type fulfilling a Geometry Concept |
geometry |
A model of the specified concept |

Returns true if the geometry is self-intersecting

Either

`#include <boost/geometry.hpp>`

Or

`#include <boost/geometry/algorithms/intersects.hpp>`

The function intersects implements function Intersects from the OGC Simple Feature Specification.

The version with one parameter is additional and not described in the OGC standard

Check if two linestrings intersect each other

#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/linestring.hpp> #include <boost/geometry/geometries/point_xy.hpp> int main() { // Calculate the intersects of a cartesian polygon typedef boost::geometry::model::d2::point_xy<double> P; boost::geometry::model::linestring<P> line1, line2; boost::geometry::read_wkt("linestring(1 1,2 2,3 3)", line1); boost::geometry::read_wkt("linestring(2 1,1 2,4 0)", line2); bool b = boost::geometry::intersects(line1, line2); std::cout << "Intersects: " << (b ? "YES" : "NO") << std::endl; return 0; }

Output:

Intersects: YES