00001
00002
00003 #include <CGAL/intersection_3.h>
00004
00005
00006 namespace CEP { namespace intersection {
00007
00008
00009 using CGAL::Point_3;
00010 using CGAL::Segment_3;
00011 using CGAL::Line_3;
00012 using CGAL::Plane_3;
00013 using CGAL::Object;
00014
00015 using CGAL::assign;
00016 using CGAL::make_object;
00017
00018
00019 namespace Plane_3_Triangle_3 {
00020
00021
00022 template <class R>
00023 inline Object
00024 _seg_in_plane( const Point_3<R>& u,
00025 const Point_3<R>& v )
00026 {
00027 Segment_3<R> seg(u,v);
00028 return make_object(seg);
00029 }
00030
00031
00032
00033
00034 template <class R>
00035 inline Object
00036 _point_and_seg( const Plane_3<R>& plane,
00037 const Point_3<R>& p,
00038 const Point_3<R>& u,
00039 const Point_3<R>& v )
00040 {
00041 Line_3<R> uv(u,v);
00042 Object i = CGAL::intersection(plane,uv);
00043 Point_3<R> x;
00044 bool intersection_is_point = assign(x,i);
00045 CGAL_assertion( intersection_is_point );
00046
00047 Segment_3<R> seg(p,x);
00048 return make_object(seg);
00049 }
00050
00051
00052
00053
00054
00055 template <class R>
00056 inline Object
00057 _2seg_through_plane( const Plane_3<R>& plane,
00058 const Point_3<R>& p,
00059 const Point_3<R>& u,
00060 const Point_3<R>& v )
00061 {
00062 Line_3<R> pu(p,u);
00063 Object i = CGAL::intersection(plane,pu);
00064 Point_3<R> x;
00065 bool intersection_is_point = assign(x,i);
00066 CGAL_assertion( intersection_is_point );
00067
00068 Line_3<R> pv(p,v);
00069 i = CGAL::intersection(plane,pv);
00070 Point_3<R> y;
00071 intersection_is_point = assign(y,i);
00072 CGAL_assertion( intersection_is_point );
00073
00074 Segment_3<R> seg(x,y);
00075 return make_object(seg);
00076 }
00077
00078
00079
00088 template <class R>
00089 CGAL::Object
00090 intersection(const Plane_3<R>& plane,
00091 const Point_3<R>& p,
00092 const Point_3<R>& q,
00093 const Point_3<R>& r )
00094 {
00095 CGAL_exactness_precondition( !collinear(p,q,r) );
00096
00097 CGAL::Oriented_side os0 = plane.oriented_side(p);
00098 CGAL::Oriented_side os1 = plane.oriented_side(q);
00099 CGAL::Oriented_side os2 = plane.oriented_side(r);
00100
00101 switch( os0 ) {
00102 case CGAL::ON_NEGATIVE_SIDE:
00103 switch( os1 ) {
00104 case CGAL::ON_NEGATIVE_SIDE:
00105 switch( os2 ) {
00106 case CGAL::ON_NEGATIVE_SIDE:
00107 return Object();
00108 case CGAL::ON_ORIENTED_BOUNDARY:
00109 return make_object(r);
00110 case CGAL::ON_POSITIVE_SIDE:
00111 return _2seg_through_plane( plane, r,p,q );
00112 }
00113 case CGAL::ON_ORIENTED_BOUNDARY:
00114 switch( os2 ) {
00115 case CGAL::ON_NEGATIVE_SIDE:
00116 return make_object(q);
00117 case CGAL::ON_ORIENTED_BOUNDARY:
00118 return _seg_in_plane( q, r );
00119 case CGAL::ON_POSITIVE_SIDE:
00120 return _point_and_seg( plane, q, p, r );
00121 }
00122 case CGAL::ON_POSITIVE_SIDE:
00123 switch( os2 ) {
00124 case CGAL::ON_NEGATIVE_SIDE:
00125 return _2seg_through_plane( plane, q,p,r );
00126 case CGAL::ON_ORIENTED_BOUNDARY:
00127 return _point_and_seg( plane, r, p, q );
00128 case CGAL::ON_POSITIVE_SIDE:
00129 return _2seg_through_plane( plane, p,q,r );
00130 }
00131 }
00132 case CGAL::ON_ORIENTED_BOUNDARY:
00133 switch( os1 ) {
00134 case CGAL::ON_NEGATIVE_SIDE:
00135 switch( os2 ) {
00136 case CGAL::ON_NEGATIVE_SIDE:
00137 return make_object(p);
00138 case CGAL::ON_ORIENTED_BOUNDARY:
00139 return _seg_in_plane( p, r );
00140 case CGAL::ON_POSITIVE_SIDE:
00141 return _point_and_seg( plane, p, q, r );
00142 }
00143 case CGAL::ON_ORIENTED_BOUNDARY:
00144 switch( os2 ) {
00145 case CGAL::ON_NEGATIVE_SIDE:
00146 return _seg_in_plane( p, q );
00147 case CGAL::ON_ORIENTED_BOUNDARY:
00148 {
00149 Triangle_3<R> T(p,q,r);
00150 return make_object(T);
00151 }
00152 case CGAL::ON_POSITIVE_SIDE:
00153 return _seg_in_plane( p, q );
00154 }
00155 case CGAL::ON_POSITIVE_SIDE:
00156 switch( os2 ) {
00157 case CGAL::ON_NEGATIVE_SIDE:
00158 return _point_and_seg( plane, p, q, r );
00159 case CGAL::ON_ORIENTED_BOUNDARY:
00160 return _seg_in_plane( p, r );
00161 case CGAL::ON_POSITIVE_SIDE:
00162 return make_object(p);
00163 }
00164 }
00165 case CGAL::ON_POSITIVE_SIDE:
00166 switch( os1 ) {
00167 case CGAL::ON_NEGATIVE_SIDE:
00168 switch( os2 ) {
00169 case CGAL::ON_NEGATIVE_SIDE:
00170 return _2seg_through_plane( plane, p,q,r );
00171 case CGAL::ON_ORIENTED_BOUNDARY:
00172 return _point_and_seg( plane, r, p, q );
00173 case CGAL::ON_POSITIVE_SIDE:
00174 return _2seg_through_plane( plane, q,p,r );
00175 }
00176 case CGAL::ON_ORIENTED_BOUNDARY:
00177 switch( os2 ) {
00178 case CGAL::ON_NEGATIVE_SIDE:
00179 return _point_and_seg( plane, q, p, r );
00180 case CGAL::ON_ORIENTED_BOUNDARY:
00181 return _seg_in_plane( q, r );
00182 case CGAL::ON_POSITIVE_SIDE:
00183 return make_object(q);
00184 }
00185 case CGAL::ON_POSITIVE_SIDE:
00186 switch( os2 ) {
00187 case CGAL::ON_NEGATIVE_SIDE:
00188 return _2seg_through_plane( plane, r,p,q );
00189 case CGAL::ON_ORIENTED_BOUNDARY:
00190 return make_object(r);
00191 case CGAL::ON_POSITIVE_SIDE:
00192 return Object();
00193 }
00194 }
00195 }
00196
00197 CGAL_assertion_msg(0,"cannot reach this point");
00198 return Object();
00199 }
00200
00201
00203
00207 static
00208 inline bool
00209 do_intersect_helper( CGAL::Oriented_side os0,
00210 CGAL::Oriented_side os1,
00211 CGAL::Oriented_side os2 )
00212 {
00213
00214
00215 return os0 != os1 || os0 != os2
00216 || os0 == CGAL::ON_ORIENTED_BOUNDARY;
00217 }
00218
00219
00220
00224 template<class R>
00225 bool
00226 do_intersect( const Plane_3<R>& plane,
00227 const Point_3<R>& p,
00228 const Point_3<R>& q,
00229 const Point_3<R>& r )
00230 {
00231 return do_intersect_helper( plane.oriented_side(p),
00232 plane.oriented_side(q),
00233 plane.oriented_side(r) );
00234 }
00235
00236
00237 }
00238 }
00239 }