BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Envelope_3/Env_plane_traits_3_functions.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  Tel-Aviv University (Israel).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Envelope_3/include/CGAL/Envelope_3/Env_plane_traits_3_functions.h $
00015 // $Id: Env_plane_traits_3_functions.h 50370 2009-07-05 13:22:10Z efif $
00016 //
00017 // Author(s)     : Baruch Zukerman     <baruchzu@post.tau.ac.il>
00018 
00019 #ifndef CGAL_ENV_PLANE_TRAITE_3_FUNCTIONS_H
00020 #define CGAL_ENV_PLANE_TRAITE_3_FUNCTIONS_H
00021 
00022 #include <CGAL/basic.h>
00023 #include <CGAL/Object.h>
00024 
00025 CGAL_BEGIN_NAMESPACE
00026 
00027 template <class K>
00028 Object plane_half_plane_proj_intersection(const typename K::Plane_3 &h1, 
00029                                           const typename K::Plane_3 &h2,
00030                                           const typename K::Line_2  &l,
00031                                           const K& k)
00032 {
00033   typedef typename K::Vector_2   Vector_2;
00034   typedef typename K::Point_2    Point_2;
00035   typedef typename K::Ray_2      Ray_2;
00036   typedef typename K::Line_3     Line_3;
00037   typedef typename K::Line_2     Line_2;
00038   typedef typename K::Plane_3    Plane_3;
00039 
00040   // intersect the two planes
00041   Object h_obj = k.intersect_3_object()(h1, h2);
00042   if(h_obj.is_empty())
00043     return Object(); // no intersection at all (paralles planes)
00044 
00045   Plane_3 p;
00046   if(assign(p, h_obj))
00047     return Object();
00048 
00049   // if two planes are not parallel they must intersect at a 3D line
00050   Line_3 l3;
00051   CGAL_assertion_code(bool b =)
00052     assign(l3, h_obj);
00053   CGAL_assertion(b);
00054 
00055   const Line_2& proj_inter_line = project_xy(l3, k);
00056 
00057   return line_under_linear_constraint(proj_inter_line, l, k);
00058 }
00059 
00060 template <class K>
00061 Object half_plane_half_plane_proj_intersection(const typename K::Plane_3 &h1,
00062                                                const typename K::Line_2  &l1,
00063                                                const typename K::Plane_3 &h2,
00064                                                const typename K::Line_2  &l2,
00065                                                const K& k)
00066 {
00067   typedef typename K::Ray_2      Ray_2;
00068   typedef typename K::Line_2     Line_2;
00069 
00070   Object obj = plane_half_plane_proj_intersection(h1, h2, l2, k);
00071   if(obj.is_empty())
00072     return Object();
00073 
00074   Line_2 l;
00075   if(assign(l, obj))
00076     return line_under_linear_constraint(l, l1, k);
00077 
00078   Ray_2 ray;
00079   if(assign(ray, obj))
00080     return ray_under_linear_constraint(ray, l1, k);
00081 
00082   CGAL_error(); // doesnt suppose to reach here
00083   return Object();
00084 }
00085 
00086 template <class K>
00087 typename K::Line_2 project_xy(const typename K::Line_3& l,
00088                               const K& k)
00089 {
00090   typedef typename K::Vector_3   Vector_3;
00091   typedef typename K::Vector_2   Vector_2;
00092   typedef typename K::Point_3    Point_3;
00093   typedef typename K::Point_2    Point_2;
00094   typedef typename K::Ray_2      Ray_2;
00095 
00096   Vector_3 vec3 = k.construct_vector_3_object()(l);
00097   Vector_2 vec2(vec3.x(), vec3.y());
00098   Point_3 p3 = k.construct_point_on_3_object()(l, 0);
00099   Point_2 p2(p3.x(), p3.y());
00100   return k.construct_line_2_object()(p2, vec2);
00101 }
00102 
00103 
00104 // l1 is a line, l2 is a linear constraint (determined by the direction
00105 // of the line).
00106 template <class K>
00107 Object line_under_linear_constraint(const typename K::Line_2& l1,
00108                                     const typename K::Line_2& l2,
00109                                     const K& k)
00110 {
00111   typedef typename K::Ray_2         Ray_2;
00112   typedef typename K::Line_2        Line_2;
00113   typedef typename K::Vector_2      Vector_2;
00114   typedef typename K::Point_2       Point_2;
00115 
00116   Object obj = k.intersect_2_object()(l1, l2);
00117   Point_2 p;
00118   if(assign(p, obj))
00119   {
00120     const Vector_2& vec = k.construct_vector_2_object()(l1);
00121     const Point_2& s = k.construct_translated_point_2_object()(p, vec);
00122     const Ray_2& ray = k.construct_ray_2_object()(p, s);
00123     Oriented_side side = k.oriented_side_2_object()(l2, s);
00124     if(side == ON_NEGATIVE_SIDE)
00125     {
00126       return make_object(k.construct_opposite_ray_2_object()(ray));
00127     }
00128 
00129     CGAL_assertion(side == ON_POSITIVE_SIDE); //the two lines are not parallel
00130     return make_object(ray);
00131   }
00132 
00133   if(obj.is_empty()) // the two lines are parallel
00134   {
00135     const Point_2& s = k.construct_point_on_2_object()(l1, 0);
00136     Oriented_side side = k.oriented_side_2_object()(l2, s);
00137 
00138     if(side == ON_NEGATIVE_SIDE)
00139       return Object();
00140 
00141     CGAL_assertion(side == ON_POSITIVE_SIDE); // the two lines are parallel
00142     return make_object(l1);   
00143   }
00144  
00145   // the two lines overlap
00146   CGAL_assertion_code(Line_2 dummy;);
00147   CGAL_assertion_code(bool b =  assign(dummy, obj););
00148   CGAL_assertion(b);
00149   
00150   return make_object(l1);
00151 }
00152 
00153 template <class K>
00154 Object ray_under_linear_constraint(const typename K::Ray_2&  ray,
00155                                    const typename K::Line_2& l,
00156                                    const K& k)
00157 {
00158   typedef typename K::Ray_2         Ray_2;
00159   typedef typename K::Line_2        Line_2;
00160   typedef typename K::Vector_2      Vector_2;
00161   typedef typename K::Point_2       Point_2;
00162   typedef typename K::Segment_2     Segment_2;
00163 
00164   const Point_2& s = k.construct_point_on_2_object()(ray, 0);
00165   Oriented_side side = k.oriented_side_2_object()(l, s);
00166   Object obj = k.intersect_2_object()(ray, l);
00167   if(obj.is_empty())
00168   {
00169     if(side == ON_NEGATIVE_SIDE)
00170       return Object();
00171 
00172     CGAL_assertion(side == ON_POSITIVE_SIDE);
00173     return make_object(ray);
00174   }
00175 
00176   Point_2 p;
00177   if(assign(p, obj))
00178   {
00179     if(side == ON_POSITIVE_SIDE)
00180       return make_object(k.construct_segment_2_object()(s, p));
00181 
00182     Vector_2 vec = k.construct_vector_2_object()(ray);
00183     if(side == ON_NEGATIVE_SIDE)
00184       return make_object(k.construct_ray_2_object()(p, vec));
00185 
00186     CGAL_assertion(side == ON_ORIENTED_BOUNDARY);
00187     const Vector_2& vec_of_l = k.construct_vector_2_object()(l);
00188 
00189     Orientation orient = k.orientation_2_object()(vec_of_l, vec);
00190     if(orient == LEFT_TURN)
00191       return make_object(ray);
00192 
00193     CGAL_assertion(orient == RIGHT_TURN);
00194     return make_object(s);
00195   }
00196 
00197   // the ray and the line overlap
00198   return make_object(ray);
00199 }
00200  
00201 
00202 CGAL_END_NAMESPACE
00203 
00204 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines