CGAL::intersection
Depending on which Cgal
kernel
is used,
different versions of this global function are available. This is
described below.
With the basic 2D and 3D Kernel
(see Chapter 11)
#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 |
|
Segment_2 |
Line_2 |
|
Segment_2 |
Segment_2 |
|
Ray_2 |
Line_2 |
|
Ray_2 |
Segment_2 |
|
Ray_2 |
Ray_2 |
|
Triangle_2 |
Line_2 |
|
Triangle_2 |
Segment_2 |
|
Triangle_2 |
Ray_2 |
|
Triangle_2 |
Triangle_2 |
Point_2 |
Segment_2 |
Triangle_2 |
std::vector<Point_2> |
|
Iso_rectangle_2 |
Line_2 |
|
Iso_rectangle_2 |
Segment_2 |
|
Iso_rectangle_2 |
Ray_2 |
|
Iso_rectangle_2 |
Iso_rectangle_2 |
|
Line_3 |
Line_3 |
|
Line_3 |
Plane_3 |
|
Line_3 |
Ray_3 |
|
Line_3 |
Segment_3 |
|
Line_3 |
Triangle_3 |
|
Plane_3 |
Plane_3 |
|
Plane_3 |
Ray_3 |
|
Plane_3 |
Segment_3 |
|
Plane_3 |
Sphere_3 |
|
Plane_3 |
Triangle_3 |
Point_3 |
Segment_3 |
Triangle_3 |
|
Ray_3 |
Ray_3 |
|
Ray_3 |
Segment_3 |
|
Ray_3 |
Triangle_3 |
|
Segment_3 |
Segment_3 |
|
Segment_3 |
Triangle_3 |
|
Sphere_3 |
Sphere_3 |
Point_3 |
Circle_3 |
Sphere_3 |
|
Triangle_3 |
Triangle_3 |
Point_3 |
Segment_3 |
std::vector < Point_3 > |
|
There is also an intersection function between 3 planes.
With the 2D Circular Kernel
(see Chapter 13)
#include <CGAL/Circular_kernel_intersections.h>
If this kernel is used, in addition to the function and the
combination of 2D types described above, another version of the function
is provided.
Since both the number of intersections, if any, and their type,
depend on the arguments, the function returns an output
iterator on Object's, as presented below.
template < class OutputIterator >
|
OutputIterator
|
intersection ( Type1 obj1, Type2 obj2, OutputIterator intersections)
|
| |
Copies in the output iterator the intersection elements between the
two objects. intersections iterates on
elements of type CGAL::Object, in lexicographic order,
|
where Type1 and Type2 can both be either
Depending on the types Type1 and Type2, these
elements can be assigned to
With the 3D Spherical Kernel
(see Chapter 14)
#include <CGAL/Spherical_kernel_intersections.h>
If this kernel is used, in addition to the function and the
combination of 3D types described above, two other versions of the function
are provided.
Since both the number of intersections, if any, and their type,
depend on the arguments, the functions return an output
iterator on Object's, as presented below.
The first function is:
template < class OutputIterator >
|
OutputIterator
|
intersection ( Type1 obj1, Type2 obj2, OutputIterator intersections)
|
| |
Copies in the output iterator the intersection elements between the
two objects. intersections iterates on
elements of type CGAL::Object, in lexicographic order,
when this ordering is defined on the computed objects,
|
where Type1 and Type2 can both be either:
and depending on the types Type1 and Type2, the computed
CGAL::Objects can be assigned to
The second function is:
template < class OutputIterator >
|
OutputIterator
|
intersection ( Type1 obj1, Type2 obj2, Type3 obj3, OutputIterator intersections)
|
| |
Copies in the output iterator the intersection elements between the
three objects. intersections iterates on
elements of type CGAL::Object, in lexicographic order
when this ordering is defined on the computed objects
|
where Type1, Type2 and Type3
can be either
and depending of these types, the computed CGAL::Objects can be
assigned to
Example
The following example demonstrates the most common use of
intersection routines with the basic 2D and 3D Kernels.
#include <CGAL/intersections.h>
void foo(CGAL::Segment_2<Kernel> seg, CGAL::Line_2<Kernel> line)
{
CGAL::Object result = CGAL::intersection(seg, line);
if (const CGAL::Point_2<Kernel> *ipoint = CGAL::object_cast<CGAL::Point_2<Kernel> >(&result)) {
// handle the point intersection case with *ipoint.
} else
if (const CGAL::Segment_2<Kernel> *iseg = CGAL::object_cast<CGAL::Segment_2<Kernel> >(&result)) {
// handle the segment intersection case with *iseg.
} else {
// handle the no intersection case.
}
}
Examples illustrating the use of this function in the case of the 2D
Circular Kernel and the 3D Spherical Kernel are presented respectively
in Chapters 13
and 14.
See Also
CGAL::do_intersect
CGAL::Object