BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Triangle_3_Point_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_Point_3_do_intersect.h $
00016 // $Id: Triangle_3_Point_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_POINT_3_DO_INTERSECT_H
00022 #define CGAL_TRIANGLE_3_POINT_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::Point_3    &p,
00031                   const K & k )
00032 {
00033 
00034   CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t));
00035 
00036   typedef typename K::Point_3 Point_3;
00037   
00038   typename K::Construct_vertex_3 vertex_on =
00039     k.construct_vertex_3_object();
00040   
00041   typename K::Orientation_3 orientation = 
00042     k.orientation_3_object();
00043 
00044   typename K::Coplanar_orientation_3 coplanar_orientation = 
00045     k.coplanar_orientation_3_object();
00046 
00047 
00048 
00049   const Point_3 & a = vertex_on(t,0);
00050   const Point_3 & b = vertex_on(t,1);
00051   const Point_3 & c = vertex_on(t,2);
00052   
00053 
00054   if (orientation(a,b,c,p) != COPLANAR)
00055     return false;
00056   
00057 
00058   const Orientation abp = coplanar_orientation(a,b,p);
00059   const Orientation bcp = coplanar_orientation(b,c,p);
00060   
00061   
00062   switch ( abp ) {
00063   case POSITIVE: return  bcp != NEGATIVE 
00064                    &&   coplanar_orientation(c,a,p) != NEGATIVE ;
00065   case NEGATIVE: return  bcp != POSITIVE  
00066                    &&   coplanar_orientation(c,a,p) != POSITIVE ;
00067   case COLLINEAR:
00068     switch ( bcp ) {
00069     case POSITIVE: return  coplanar_orientation(c,a,p) != NEGATIVE ;
00070     case NEGATIVE: return  coplanar_orientation(c,a,p) != POSITIVE ;
00071     case COLLINEAR: return true;
00072     default: // should not happen.
00073       CGAL_kernel_assertion(false);
00074       return false;
00075     }
00076   default: // should not happen.
00077     CGAL_kernel_assertion(false);
00078     return false;
00079   }
00080   
00081 }
00082 
00083 
00084 template <class K>
00085 bool do_intersect(const typename K::Point_3    &p,
00086                   const typename K::Triangle_3 &t, 
00087                   const K & k )
00088 {
00089   return do_intersect(t, p, k);
00090 }
00091 
00092 
00093 } // namespace CGALi
00094 
00095  
00096 template <class K>
00097 inline bool do_intersect(const Point_3<K> &p, 
00098                          const Triangle_3<K> &t)
00099 { 
00100   return typename K::Do_intersect_3()(t,p);
00101 } 
00102 
00103 template <class K>
00104 inline bool do_intersect(const Triangle_3<K> &t, 
00105                          const Point_3<K> &p)
00106 { 
00107   return typename K::Do_intersect_3()(t,p);
00108 } 
00109 
00110 /*
00111 template <class K>
00112 inline bool do_intersect(const Point_3<K> &p, 
00113                          const Triangle_3<K> &t,
00114                          const K & k)
00115 { 
00116   return do_intersect(t,p,k);
00117 } 
00118 */
00119 
00120 CGAL_END_NAMESPACE
00121 
00122 #endif // CGAL_TRIANGLE_3_POINT_3_DO_INTERSECT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines