CGAL::intersection

#include <CGAL/intersections.h>

Object intersection ( Type1<Kernel> obj1, Type2<Kernel> obj2)
Two objects obj1 and obj2 intersect if there is a point p that is part of both obj1 and obj2. The intersection region of those two objects is defined as the set of all points p that are part of both obj1 and obj2. Note that for objects like triangles and polygons that enclose a bounded region, this region is considered part of the object. If a segment lies completely inside a triangle, then those two objects intersect and the intersection region is the complete segment.

The possible value for types Type1 and Type2 and the possible return values wrapped in Object are the following:

type A type B return type
Line_2 Line_2
Point_2
Line_2
Segment_2 Line_2
Point_2
Segment_2
Segment_2 Segment_2
Point_2
Segment_2
Ray_2 Line_2
Point_2
Ray_2
Ray_2 Segment_2
Point_2
Segment_2
Ray_2 Ray_2
Point_2
Segment_2
Ray_2
Triangle_2 Line_2
Point_2
Segment_2
Triangle_2 Segment_2
Point_2
Segment_2
Triangle_2 Ray_2
Point_2
Segment_2
Triangle_2 Triangle_2
Point_2
Segment_2
Triangle_2
std::vector<Point_2>
Iso_rectangle_2 Line_2
Point_2
Segment_2
Iso_rectangle_2 Segment_2
Point_2
Segment_2
Iso_rectangle_2 Ray_2
Point_2
Segment_2
Iso_rectangle_2 Iso_rectangle_2
Iso_rectangle_2
Plane_3 Line_3
Point_3
Line_3
Plane_3 Ray_3
Point_3
Ray_3
Plane_3 Segment_3
Point_3
Segment_3
Plane_3 Plane_3
Line_3
Plane_3

There is also an intersection function between 3 planes.

Object intersection ( Plane_3<Kernel> pl1, Plane_3<Kernel> pl2, Plane_3<Kernel> pl3)
returns the intersection of 3 planes, which can be either a point, a line, a plane, or empty.

Example

The following example demonstrates the most common use of intersection routines.

#include <CGAL/intersections.h>

void foo(CGAL::Segment_2<Kernel> seg, CGAL::Line_2<Kernel> line)
{
    CGAL::Object result;
    CGAL::Point_2<Kernel> ipoint;
    CGAL::Segment_2<Kernel> iseg;

    result = CGAL::intersection(seg, line);
    if (CGAL::assign(ipoint, result)) {
        // handle the point intersection case.
    } else
        if (CGAL::assign(iseg, result)) {
            // handle the segment intersection case.
        } else {
            // handle the no intersection case.
        }
}

See Also

CGAL::do_intersect
CGAL::Object