![]() |
|
| |
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:
The following example demonstrates the most common use of intersection routines.
#include <CGAL/Segment_2_Line_2_intersection.h> /* or #include <CGAL/intersections.h> */ template <class R> void foo(Segment_2<R> seg, Line_2<R> line) { Object result; Point_2<R> ipoint; Segment_2<R> iseg; result = intersection(seg, line); if (assign(ipoint, result)) {
// handle the point intersection case.
} else if (assign(iseg, result)) {
// handle the segment intersection case.
} else {
// handle the no intersection case. } }
1 | The drawback of <CGAL/intersections.h> is that a lot is included, which results in long compilation times. It is also possible to include only the intersections that are of interest. The naming scheme of the header files is as follows. Intersections of types Type1<R> and Type2<R> are declared in header file CGAL/Type1_Type2_intersection.h. So, intersection routines of segments and lines in 2D are declared in <CGAL/Segment_2_Line_2_intersection.h>. The order of the type names does not matter. It is also possible to include <CGAL/Line_2_Segment_2_intersection.h>. For intersections of two objects of the same type, the type name should be mentioned twice: <CGAL/Segment_2_Segment_2_intersection.h> |