## 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 operation bool assign(T& t, Object o). 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)
    {
      Point_d<R> ipnt; Segment_d<R> iseg;
      Object result = intersection(seg, lin);
      if ( assign(ipnt, result) ) {
        // handle the point intersection case.
      } else if ( assign(iseg, result) ) {
        // handle the segment intersection case.
      } else {
        // handle the no intersection case.
      }
    }

### See Also

do_intersect, Kernel::Intersect_d