BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Triangle_3_Line_3_do_intersect.h
Go to the documentation of this file.
00001 // Copyright (c) 2003  INRIA Sophia-Antipolis (France).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Intersections_3/include/CGAL/Triangle_3_Line_3_do_intersect.h $
00016 // $Id: Triangle_3_Line_3_do_intersect.h 39776 2007-08-08 15:15:20Z spion $
00017 // 
00018 //
00019 // Author(s)     : Philippe Guigue
00020 
00021 #ifndef CGAL_TRIANGLE_3_LINE_3_DO_INTERSECT_H
00022 #define CGAL_TRIANGLE_3_LINE_3_DO_INTERSECT_H
00023 
00024 CGAL_BEGIN_NAMESPACE
00025 
00026 namespace CGALi {
00027 
00028 template <class K>
00029 bool do_intersect(const typename K::Triangle_3 &t, 
00030                   const typename K::Line_3     &l,
00031                   const K & k )
00032 {
00033   
00034   CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ;
00035   CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ;
00036   
00037   typedef typename K::Point_3 Point_3;
00038   
00039 
00040   typename K::Construct_point_on_3 point_on = 
00041     k.construct_point_on_3_object();
00042   
00043   typename K::Construct_vertex_3 vertex_on =
00044     k.construct_vertex_3_object();
00045   
00046   typename K::Orientation_3 orientation = 
00047     k.orientation_3_object();
00048 
00049   typename K::Coplanar_orientation_3 coplanar_orientation = 
00050     k.coplanar_orientation_3_object();
00051 
00052 
00053 
00054   const Point_3 & a = vertex_on(t,0);
00055   const Point_3 & b = vertex_on(t,1);
00056   const Point_3 & c = vertex_on(t,2);
00057   const Point_3 & p = point_on(l,0);
00058   const Point_3 & q = point_on(l,1);
00059 
00060 
00061   
00062   if ( ( orientation(a,b,c,p) != COPLANAR ) || 
00063        ( orientation(a,b,c,q) != COPLANAR ) )
00064     {
00065 
00066       const Orientation pqab = orientation(p,q,a,b);
00067       const Orientation pqbc = orientation(p,q,b,c);
00068 
00069       
00070       switch ( pqab ) {
00071       case POSITIVE: return  pqbc != NEGATIVE  &&  
00072                        orientation(p,q,c,a) != NEGATIVE ;
00073       case NEGATIVE: return  pqbc != POSITIVE  &&  
00074                        orientation(p,q,c,a) != POSITIVE ;
00075       case COLLINEAR:
00076         switch ( pqbc ) {
00077         case POSITIVE: return  orientation(p,q,c,a) != NEGATIVE ;
00078         case NEGATIVE: return  orientation(p,q,c,a) != POSITIVE ;
00079         case COLLINEAR: return true;
00080         default: // should not happen.
00081           CGAL_kernel_assertion(false);
00082           return false;
00083         }
00084       default: // should not happen.
00085         CGAL_kernel_assertion(false);
00086         return false;
00087       }
00088     }
00089   
00090   // Coplanar case
00091     
00092   const Orientation pqa = coplanar_orientation(p,q,a);
00093   
00094   return  coplanar_orientation(p,q,b) != pqa 
00095     ||  coplanar_orientation(p,q,c) != pqa ;  
00096 }
00097 
00098 
00099 template <class K>
00100 inline
00101 bool do_intersect(const typename K::Line_3     &l,
00102                   const typename K::Triangle_3 &t, 
00103                   const K & k )
00104 {
00105   return do_intersect(t, l, k);
00106 }
00107 
00108 
00109 } // namespace CGALi
00110 
00111 
00112 template <class K>
00113 bool do_intersect(const Triangle_3<K> &t, 
00114                   const Line_3<K>     &l)
00115 {
00116   return typename K::Do_intersect_3()(t,l);
00117 }
00118 
00119 
00120 template <class K>
00121 inline bool do_intersect(const Line_3<K> &l, 
00122                          const Triangle_3<K> &t)
00123 {
00124   return typename K::Do_intersect_3()(t,l);
00125 }
00126 
00127 /*
00128 template <class K>
00129 inline bool do_intersect(const Line_3<K> &l, 
00130                          const Triangle_3<K> &t,
00131                          const K  & k )
00132 {
00133   return do_intersect(t,l,k);
00134 }
00135 */
00136 
00137 CGAL_END_NAMESPACE
00138 
00139 #endif //CGAL_TRIANGLE_3_LINE_3_DO_INTERSECT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines