BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Nef_S2/Sphere_direction.h
Go to the documentation of this file.
00001 // Copyright (c) 1997-2002  Max-Planck-Institute Saarbruecken (Germany).
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/Nef_S2/include/CGAL/Nef_S2/Sphere_direction.h $
00015 // $Id: Sphere_direction.h 35146 2006-11-13 13:43:37Z hachenb $
00016 // 
00017 //
00018 // Author(s)     : Michael Seel  <seel@mpi-sb.mpg.de>
00019 
00020 #ifndef CGAL_SPHERE_DIRECTION_H
00021 #define CGAL_SPHERE_DIRECTION_H
00022 
00023 #include <CGAL/basic.h>
00024 
00025 CGAL_BEGIN_NAMESPACE
00026 
00027 /*{\Manpage{Sphere_direction}{R}{Directions on the unit sphere}{c}}*/
00028 
00029 template <class R_> class Sphere_direction : public R_::Plane_3 {
00030 
00031 /*{\Mdefinition An object |\Mvar| of type |\Mname| is a direction
00032 on the surface of the unit sphere.  Such directions can be used to
00033 describe walks that are part of great circles.}*/
00034 
00035 public:
00036 
00037 /*{\Mtypes 5}*/
00038 typedef R_ R;
00039 /*{\Mtypemember representation class.}*/
00040 typedef typename R::RT RT;
00041 /*{\Mtypemember ring type.}*/
00042 
00043 typedef typename R_::Point_3 Point_3;
00044 typedef typename R_::Plane_3 Plane_3;
00045 typedef typename R_::Plane_3 Base;
00046 typedef Sphere_direction<R_> Self;
00047 
00048 /*{\Mcreation 5}*/
00049 Sphere_direction() : Base() {}
00050 /*{\Mcreate creates some direction.}*/
00051 
00052 Sphere_direction(const Sphere_circle<R>& c) 
00053 /*{\Mcreate creates the direction corresponding to the circle |c|.}*/
00054   : Base(c) {} 
00055 
00056 Sphere_direction(const Sphere_point<R>& p, const Sphere_point<R>&q) 
00057   : Base(Point_3(0,0,0),p,q) 
00058 /*{\Mcreate creates a direction that describes the orientation of
00059 the great circle through $p$ and $q$ (oriented such that the segment
00060 $pq$ is the shorter one of the two possible ones. \precond $p$ and $q$
00061 are not opposite on $S_2$.}*/ 
00062 { CGAL_assertion(p!=q.opposite()); 
00063   Point_3 p1(0,0,0), p4 = CGAL::ORIGIN + ((Base*) this)->orthogonal_vector();
00064   if ( CGAL::orientation(p1,p,q,p4) != CGAL::POSITIVE )
00065     *this = Sphere_direction(opposite());
00066 }
00067 
00068 Sphere_direction(const typename R::Plane_3& h) 
00069 /*{\Xcreate creates the direction corresponding to the plane |h|.
00070 \precond |h| contains the origin.}*/
00071  : Base(h) { CGAL_assertion(h.d() == 0); } 
00072 
00073 /*{\Moperations 4 2}*/
00074 
00075 Sphere_direction<R> opposite() const 
00076 /*{\Mop returns the opposite of |\Mvar|.}*/
00077 { return Base::opposite(); }
00078 
00079 Plane_3 plane() const { return Base(*this); }
00080 /*{\Xop returns the plane supporting |\Mvar|.}*/
00081 
00082 }; // Sphere_direction<R>
00083 
00084 
00085 /* We have:
00086    1) all directions fixed at p 
00087    2) d1==d3 possible
00088    return true iff d1,d2,d3 are stricly ccw ordered around p
00089    Note: Sphere_directions are Plane_3
00090          we therefore compare the normal vectors of the planes
00091          that underly the directions d1,d2,d3 in the plane 
00092          through 0 and orthogonal to the vector p-0
00093  */
00094 
00095 template <typename R>
00096 bool strictly_ordered_ccw_at(const Sphere_point<R>& p,
00097   const Sphere_direction<R>& d1,
00098   const Sphere_direction<R>& d2,
00099   const Sphere_direction<R>& d3)
00100 { CGAL_assertion(d1.has_on(p) && d2.has_on(p) && d3.has_on(p));
00101   typename R::Point_3 p0(0,0,0); 
00102   typename R::Point_3 p1(CGAL::ORIGIN + d1.orthogonal_vector()); 
00103   typename R::Point_3 p2(CGAL::ORIGIN + d2.orthogonal_vector()); 
00104   typename R::Point_3 p3(CGAL::ORIGIN + d3.orthogonal_vector()); 
00105 
00106   if ( d1 == d3 ) return false;
00107   if ( CGAL::orientation(p0,p,p1,p3) == CGAL::POSITIVE ) {
00108     return CGAL::orientation(p0,p,p1,p2) == CGAL::POSITIVE &&
00109            CGAL::orientation(p0,p,p3,p2) == CGAL::NEGATIVE;
00110   } else {
00111     return CGAL::orientation(p0,p,p1,p2) == CGAL::POSITIVE ||
00112            CGAL::orientation(p0,p,p3,p2) == CGAL::NEGATIVE;
00113   }
00114 }
00115 
00116 
00117 CGAL_END_NAMESPACE
00118 #endif //CGAL_SPHERE_DIRECTION_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines