Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit 1d266c8cd4.
PrevUpHomeNext
intersects (with strategy)

Checks if two geometries have at least one intersection.

Synopsis

template<typename Geometry1, typename Geometry2, typename Strategy>
bool intersects(Geometry1 const & geometry1, Geometry2 const & geometry2, Strategy const & strategy)

Parameters

Type

Concept

Name

Description

Geometry1 const &

Any type fulfilling a Geometry Concept

geometry1

A model of the specified concept

Geometry2 const &

Any type fulfilling a Geometry Concept

geometry2

A model of the specified concept

Strategy const &

Any type fulfilling a Intersects Strategy Concept

strategy

The strategy which will be used for intersects calculations

Returns

Returns true if two geometries intersect each other

Header

Either

#include <boost/geometry.hpp>

Or

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

Conformance

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

Examples

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
    using P = boost::geometry::model::d2::point_xy<double>;
    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

PrevUpHomeNext