BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Circular_kernel_3/internal_function_has_on_spherical_kernel.h
Go to the documentation of this file.
00001 // Copyright (c) 2008  INRIA Sophia-Antipolis (France).
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/Circular_kernel_3/include/CGAL/Circular_kernel_3/internal_function_has_on_spherical_kernel.h $
00015 // $Id: internal_function_has_on_spherical_kernel.h 50731 2009-07-21 09:08:07Z sloriot $
00016 //
00017 // Author(s) : Monique Teillaud, Sylvain Pion, Pedro Machado, 
00018 //             Sebastien Loriot
00019 
00020 // Partially supported by the IST Programme of the EU as a 
00021 // STREP (FET Open) Project under Contract No  IST-006413 
00022 // (ACS -- Algorithms for Complex Shapes)
00023 
00024 #ifndef CGAL_SPHERICAL_KERNEL_PREDICATES_HAS_ON_3_H
00025 #define CGAL_SPHERICAL_KERNEL_PREDICATES_HAS_ON_3_H
00026 
00027 namespace CGAL {
00028   namespace SphericalFunctors {
00029 
00030     template <class SK>
00031     inline
00032     bool
00033     has_on(const typename SK::Sphere_3 &a, 
00034            const typename SK::Circular_arc_point_3 &p)
00035     { 
00036       typedef typename SK::Algebraic_kernel Algebraic_kernel;
00037       typedef typename SK::Polynomial_for_spheres_2_3 Equation;
00038       Equation equation = get_equation<SK>(a);
00039       return (Algebraic_kernel().sign_at_object()(equation,p.rep().coordinates()) == ZERO);
00040     }
00041     
00042     template <class SK>
00043     inline
00044     bool
00045     has_on(const typename SK::Plane_3 &a, 
00046            const typename SK::Circular_arc_point_3 &p)
00047     { 
00048       typedef typename SK::Algebraic_kernel Algebraic_kernel;
00049       typedef typename SK::Polynomial_1_3 Equation;
00050       Equation equation = get_equation<SK>(a);
00051       return (Algebraic_kernel().sign_at_object()(equation,p.rep().coordinates()) == ZERO);
00052     }
00053 
00054     template <class SK>
00055     inline
00056     bool
00057     has_on(const typename SK::Line_3 &a, 
00058            const typename SK::Circular_arc_point_3 &p)
00059     { 
00060       typedef typename SK::Algebraic_kernel Algebraic_kernel;
00061       typedef typename SK::Polynomials_for_line_3 Equation;
00062       Equation equation = get_equation<SK>(a);
00063       return p.rep().coordinates().is_on_line(equation);
00064     }
00065 
00066     template <class SK>
00067     inline
00068     bool
00069     has_on(const typename SK::Circle_3 &a, 
00070            const typename SK::Circular_arc_point_3 &p)
00071     { 
00072       return has_on<SK>(a.diametral_sphere(),p) &&
00073              has_on<SK>(a.supporting_plane(),p);
00074     }
00075 
00076     //duplicated code
00077     template <class SK>
00078     inline
00079     bool
00080     has_on(const typename SK::Circle_on_reference_sphere_3 &a, 
00081            const typename SK::Point_3 &p)
00082     { 
00083       return has_on<SK>(a.diametral_sphere(),p) &&
00084              has_on<SK>(a.supporting_plane(),p);
00085     }
00086 
00087     template <class SK>
00088     inline
00089     bool
00090     has_on(const typename SK::Circle_on_reference_sphere_3 &a, 
00091            const typename SK::Circular_arc_point_on_reference_sphere_3 &p)
00092     { 
00093       return has_on<SK>(a.diametral_sphere(),p) &&
00094              has_on<SK>(a.supporting_plane(),p);
00095     }
00096 
00097     template <class SK>
00098     inline
00099     bool
00100     has_on(const typename SK::Line_arc_3 &l, 
00101            const typename SK::Circular_arc_point_3 &p,
00102            const bool has_on_supporting_line = false)
00103     { 
00104       if(!has_on_supporting_line) {
00105         if(!has_on<SK>(l.supporting_line(), p)) {
00106           return false;
00107         }
00108       }
00109       return SK().compare_xyz_3_object()(l.lower_xyz_extremity(),p) <= ZERO &&
00110              SK().compare_xyz_3_object()(p,l.higher_xyz_extremity()) <= ZERO;
00111     }
00112 
00113     template <class SK>
00114     inline
00115     bool
00116     has_on(const typename SK::Line_arc_3 &l, 
00117            const typename SK::Point_3 &p,
00118            const bool has_on_supporting_line = false)
00119     { 
00120       if(!has_on_supporting_line) {
00121         if(!has_on<SK>(l.supporting_line(), p)) {
00122           return false;
00123         }
00124       }           
00125       return SK().compare_xyz_3_object()(l.lower_xyz_extremity(),p) <= ZERO &&
00126              SK().compare_xyz_3_object()(p,l.higher_xyz_extremity()) <= ZERO;
00127     }
00128 
00129     template <class SK>
00130     inline
00131     bool
00132     has_on(const typename SK::Plane_3 &p,
00133            const typename SK::Line_arc_3 &l)
00134     { 
00135       return SK().has_on_3_object()(p, l.supporting_line());
00136     }
00137 
00138     template <class SK>
00139     inline
00140     bool
00141     has_on(const typename SK::Line_3 &l,
00142            const typename SK::Line_arc_3 &la)
00143     { 
00144       return non_oriented_equal<SK>(l, la.supporting_line());
00145     }
00146 
00147     template< class SK>
00148     inline Sign element_cross_product_sign(const typename SK::Root_of_2 & y1,
00149                                            const typename SK::Root_of_2 &z2,
00150                                            const typename SK::Root_of_2 &z1,
00151                                            const typename SK::Root_of_2 &y2)
00152     {
00153       int s1=CGAL_NTS sign(z1);
00154       int s2=CGAL_NTS sign(z2);
00155       if (s1==0){
00156         if (s2==0)
00157           return CGAL_NTS sign(0);
00158         else
00159           return CGAL_NTS sign(y1) * CGAL_NTS sign(z2);
00160       }
00161       else{
00162         if (s2==0)
00163           return CGAL_NTS sign(- z1) * CGAL_NTS sign(y2);
00164         else
00165           return CGAL_NTS sign((s1*s2)*compare(y1/z1,y2/z2));
00166       }    
00167     }
00168 
00169     template< class SK>
00170     inline
00171     Sign
00172     compute_sign_of_cross_product(const typename SK::Root_of_2 &x1, 
00173                                   const typename SK::Root_of_2 &y1,
00174                                   const typename SK::Root_of_2 &z1,
00175                                   const typename SK::Root_of_2 &x2, 
00176                                   const typename SK::Root_of_2 &y2,
00177                                   const typename SK::Root_of_2 &z2) 
00178     {
00179       Sign s = element_cross_product_sign<SK>(y1,z2,z1,y2);
00180       if(s!=0) return s;
00181       s = element_cross_product_sign<SK>(z1,x2,x1,z2);
00182       if(s!=0) return s;
00183       s = element_cross_product_sign<SK>(x1,y2,y1,x2);
00184       return s;        
00185     }
00186 
00187     template< class SK>
00188     inline
00189     Sign
00190     compute_sign_of_cross_product(const typename SK::Circular_arc_point_3 &p1, 
00191                                   const typename SK::Circular_arc_point_3 &p2,
00192                                   const typename SK::Circular_arc_point_3 &c) {
00193       return compute_sign_of_cross_product<SK>(p1.x()-c.x(),
00194                                                p1.y()-c.y(),
00195                                                p1.z()-c.z(),
00196                                                p2.x()-c.x(),
00197                                                p2.y()-c.y(),
00198                                                p2.z()-c.z());
00199     }
00200 
00201     template <class SK>
00202     inline
00203     bool
00204     has_on(const typename SK::Circular_arc_3 &a, 
00205            const typename SK::Point_3 &p,
00206            const bool has_on_supporting_circle = false)
00207     { 
00208       if(!has_on_supporting_circle) {
00209         if(!SK().has_on_3_object()(a.supporting_circle(),p)) 
00210           return false;
00211       }
00212       if(a.rep().is_full()) return true;
00213       const Sign s_x_t = a.sign_cross_product();
00214       const Sign s_x_p = 
00215         compute_sign_of_cross_product<SK>(a.source(),p,a.center());
00216       const Sign p_x_t = 
00217         compute_sign_of_cross_product<SK>(p,a.target(),a.center());
00218       if(s_x_t == ZERO) return (s_x_p != NEGATIVE);
00219       if(a.source() == p) return true;
00220       if(a.target() == p) return true;
00221       if(s_x_t == POSITIVE) {
00222         if(s_x_p == POSITIVE) return p_x_t == POSITIVE;
00223         else return false;
00224       } else {
00225         if(s_x_p == NEGATIVE) return p_x_t == POSITIVE;
00226         else return true;
00227       }
00228     }
00229 
00230     template <class SK>
00231     inline
00232     bool
00233     has_on(const typename SK::Circular_arc_3 &a, 
00234            const typename SK::Circular_arc_point_3 &p,
00235            const bool has_on_supporting_circle = false)
00236     {
00237       if(!has_on_supporting_circle) {
00238         if(!has_on<SK>(a.supporting_circle(),p)) 
00239           return false;
00240       }
00241       if(a.rep().is_full()) return true;
00242       const Sign s_x_t = a.sign_cross_product();
00243       const Sign s_x_p = 
00244         compute_sign_of_cross_product<SK>(a.source(),p,a.center());
00245       const Sign p_x_t = 
00246         compute_sign_of_cross_product<SK>(p,a.target(),a.center());
00247       if(s_x_t == ZERO) return (s_x_p != NEGATIVE);
00248       if(a.source() == p) return true;
00249       if(p == a.target()) return true;
00250       if(s_x_t == POSITIVE) {
00251         if(s_x_p == POSITIVE) return p_x_t == POSITIVE;
00252         else return false;
00253       } else {
00254         if(s_x_p == NEGATIVE) return p_x_t == POSITIVE;
00255         else return true;
00256       }
00257     }
00258 
00259     template <class SK>
00260     inline
00261     bool
00262     has_on(const typename SK::Sphere_3 &a, 
00263            const typename SK::Circular_arc_3 &p)
00264     { 
00265       return a.has_on(p.supporting_circle());
00266     }
00267 
00268     template <class SK>
00269     inline
00270     bool
00271     has_on(const typename SK::Plane_3 &a, 
00272            const typename SK::Circular_arc_3 &p)
00273     { 
00274       return a.has_on(p.supporting_circle());
00275     }
00276 
00277     template <class SK>
00278     inline
00279     bool
00280     has_on(const typename SK::Circle_3 &c, 
00281            const typename SK::Circular_arc_3 &ca)
00282     { 
00283       return non_oriented_equal<SK>(c,ca.supporting_circle());
00284     }
00285 
00286     template <class SK>
00287     inline
00288     bool
00289     has_on(const typename SK::Circular_arc_3 &ca,
00290            const typename SK::Circle_3 &c)
00291     { 
00292        if(!non_oriented_equal<SK>(c,ca.supporting_circle())) return false;
00293        return ca.rep().is_full();
00294     }
00295    
00296     
00297 
00298   }//SphericalFunctors
00299 }//CGAL
00300 
00301 #endif //CGAL_SPHERICAL_KERNEL_PREDICATES_HAS_ON_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines