CGAL::intersection

#include <CGAL/intersections_d.h>

Object intersection ( Type1<R> f1, Type2<R> f2)
returns the intersection result of f1 and f2 by means of the polymorphic wrapper type Object. The returned object can be tested for the intersection result and assigned by means of the object_cast function.
Precondition: The objects are of the same dimension.

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

Type1 Type2 Return Type
Line_d Line_d
Point_d
Line_d
Segment_d Line_d
Point_d
Segment_d
Segment_d Segment_d
Point_d
Segment_d
Ray_d Line_d
Point_d
Ray_d
Ray_d Segment_d
Point_d
Segment_d
Ray_d Ray_d
Point_d
Segment_d
Ray_d
Hyperplane_d Line_d
Point_d
Line_d
Hyperplane_d Ray_d
Point_d
Ray_d
Hyperplane_d Segment_d
Point_d
Segment_d

Example

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

#include <CGAL/intersections_d.h>

template <class R>
void foo(Segment_d<R> seg, Line_d<R> lin)
{
  Object result = intersection(seg, lin);
  if (const Point_d<R> *ipnt = object_cast<Point_d<R> >(&result) ) {
    // handle the point intersection case with *ipnt.
  } else if (const Segment_d<R> *iseg = object_cast<Segment_d<R> >(&result) ) {
    // handle the segment intersection case with *iseg.
  } else {
    // handle the no intersection case.
  }
}

See Also

do_intersect, Kernel::Intersect_d