00001 #ifndef CEP_INTERSECTION_HALFPLANE_3_H // -*- C++ -*-
00002 #define CEP_INTERSECTION_HALFPLANE_3_H
00003
00004 #include <CGAL/Object.h>
00005 #include <CGAL/Point_3.h>
00006 #include <CGAL/Segment_3.h>
00007 #include <CGAL/predicates_on_points_3.h>
00008
00009 #include <CEP/intersection/Line_3_Line_3.h>
00010
00011
00012 namespace CEP { namespace intersection {
00013
00014 using CGAL::Point_3;
00015 using CGAL::Segment_3;
00016
00017 using CGAL::assign;
00018 using CGAL::make_object;
00019
00020
00021 namespace Halfplane_3_Segment_3 {
00022
00024
00032 template <class R_>
00033 CGAL::Object coplanar_intersection( const Point_3<R_>& p,
00034 const Point_3<R_>& q,
00035 const Point_3<R_>& r,
00036 const Segment_3<R_>& segment )
00037 {
00038 CGAL_exactness_precondition( ! CGAL::collinear(p,q,r) );
00039 CGAL_exactness_precondition( CGAL::coplanar(p,q,r, segment.source()) );
00040 CGAL_exactness_precondition( CGAL::coplanar(p,q,r, segment.target()) );
00041
00042 bool source_on_halfplane
00043 = CGAL::coplanar_orientation(p,q,r, segment.source() ) != CGAL::NEGATIVE;
00044 bool target_on_halfplane
00045 = CGAL::coplanar_orientation(p,q,r, segment.target() ) != CGAL::NEGATIVE;
00046
00047 if ( source_on_halfplane ) {
00048 if ( target_on_halfplane ) {
00049 return make_object(segment);
00050 } else {
00051 CGAL::Object i = CEP::intersection::Line_3_Line_3::coplanar_nonparallel_intersection
00052 ( p,q, segment.source(),segment.target() );
00053 Point_3<R_> pi;
00054 bool intersection_is_point = assign( pi, i );
00055 CGAL_assertion( intersection_is_point );
00056 return make_object(Segment_3<R_>(pi,segment.source()));
00057 }
00058 } else if ( target_on_halfplane ) {
00059 CGAL::Object i = CEP::intersection::Line_3_Line_3::coplanar_nonparallel_intersection
00060 ( p,q, segment.source(),segment.target() );
00061 Point_3<R_> pi;
00062 bool intersection_is_point = assign( pi, i );
00063 CGAL_assertion( intersection_is_point );
00064 return make_object(Segment_3<R_>(pi,segment.target()));
00065 }
00066
00067 return CGAL::Object();
00068 }
00069
00070 }
00071 }
00072 }
00073
00074
00075
00076
00077
00078 #endif