BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Homogeneous/SphereH3.h
Go to the documentation of this file.
00001 // Copyright (c) 1999  Utrecht University (The Netherlands),
00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
00005 // and Tel-Aviv University (Israel).  All rights reserved.
00006 //
00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License as
00009 // published by the Free Software Foundation; version 2.1 of the License.
00010 // See the file LICENSE.LGPL distributed with CGAL.
00011 //
00012 // Licensees holding a valid commercial license may use this file in
00013 // accordance with the commercial license agreement provided with the software.
00014 //
00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 //
00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Homogeneous_kernel/include/CGAL/Homogeneous/SphereH3.h $
00019 // $Id: SphereH3.h 44446 2008-07-25 15:06:44Z spion $
00020 //
00021 //
00022 // Author(s)     : Stefan Schirra
00023 
00024 #ifndef CGAL_SPHEREH3_H
00025 #define CGAL_SPHEREH3_H
00026 
00027 #include <CGAL/Interval_nt.h>
00028 #include <CGAL/Homogeneous/predicates_on_pointsH3.h>
00029 #include <boost/tuple/tuple.hpp>
00030 
00031 CGAL_BEGIN_NAMESPACE
00032 
00033 template <class R_>
00034 class SphereH3
00035 {
00036    typedef typename R_::RT                   RT;
00037    typedef typename R_::FT                   FT;
00038    typedef typename R_::Point_3              Point_3;
00039 
00040    typedef boost::tuple<Point_3, FT, Orientation>   Rep;
00041    typedef typename R_::template Handle<Rep>::type  Base;
00042 
00043    Base base;
00044 
00045 public:
00046    typedef R_                R;
00047 
00048       SphereH3() {}
00049 
00050       SphereH3(const Point_3& p, const FT& sq_rad,
00051                const Orientation& o = COUNTERCLOCKWISE);
00052 
00053       SphereH3(const Point_3& p, const Point_3& q,
00054                const Point_3& r, const Point_3& u);
00055 
00056       SphereH3(const Point_3& p, const Point_3& q,
00057                const Point_3& r,
00058                const Orientation& o = COUNTERCLOCKWISE);
00059 
00060       SphereH3(const Point_3&  p, const Point_3&  q,
00061                const Orientation& o = COUNTERCLOCKWISE);
00062 
00063       SphereH3(const Point_3&  p,
00064                const Orientation& o = COUNTERCLOCKWISE);
00065 
00066       bool
00067       operator==(const SphereH3<R>&) const;
00068 
00069       bool
00070       operator!=(const SphereH3<R>& s) const
00071       { return !(*this == s); }
00072 
00073       const Point_3 & center() const;
00074 
00075       const FT & squared_radius() const;
00076 
00077       Orientation orientation() const;
00078 
00079       bool is_degenerate() const;
00080 
00081       SphereH3<R> opposite() const;
00082 
00083       Oriented_side oriented_side(const Point_3& p) const;
00084 
00085       bool
00086       has_on_boundary(const Point_3& p) const
00087       { return oriented_side(p)==ON_ORIENTED_BOUNDARY; }
00088 
00089       bool
00090       has_on_positive_side(const Point_3& p) const
00091       { return oriented_side(p)==ON_POSITIVE_SIDE; }
00092 
00093       bool
00094       has_on_negative_side(const Point_3& p) const
00095       { return oriented_side(p)==ON_NEGATIVE_SIDE; }
00096 
00097       Bounded_side
00098       bounded_side(const Point_3& p) const;
00099 
00100       bool
00101       has_on_bounded_side(const Point_3& p) const
00102       { return bounded_side(p)==ON_BOUNDED_SIDE; }
00103 
00104       bool
00105       has_on_unbounded_side(const Point_3& p) const
00106       { return bounded_side(p)==ON_UNBOUNDED_SIDE; }
00107 };
00108 
00109 
00110 template < class R >
00111 CGAL_KERNEL_INLINE
00112 SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& center,
00113                       const FT& squared_radius,
00114                       const Orientation& o)
00115 {
00116   CGAL_kernel_precondition( !( squared_radius < FT(0))
00117                           &&( o != COLLINEAR) );
00118   base = Rep(center, squared_radius, o);
00119 }
00120 
00121 template <class R>
00122 CGAL_KERNEL_INLINE
00123 SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& center,
00124                       const Orientation& o)
00125 {
00126   CGAL_kernel_precondition( ( o != COLLINEAR) );
00127   base = Rep(center, FT(0), o);
00128 }
00129 
00130 template <class R>
00131 CGAL_KERNEL_MEDIUM_INLINE
00132 SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& p,
00133                       const typename SphereH3<R>::Point_3& q,
00134                       const Orientation& o)
00135 {
00136   CGAL_kernel_precondition( o != COLLINEAR);
00137   Point_3 center = midpoint(p,q);
00138   FT     squared_radius = squared_distance(p,center);
00139   base = Rep(center, squared_radius, o);
00140 }
00141 
00142 template <class R>
00143 CGAL_KERNEL_MEDIUM_INLINE
00144 SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& p,
00145                       const typename SphereH3<R>::Point_3& q,
00146                       const typename SphereH3<R>::Point_3& r,
00147                       const Orientation& o)
00148 {
00149   CGAL_kernel_precondition( o != COLLINEAR);
00150   Point_3 center = circumcenter(p,q,r);
00151   FT     squared_radius = squared_distance(p,center);
00152   base = Rep(center, squared_radius, o);
00153 }
00154 
00155 template <class R>
00156 CGAL_KERNEL_MEDIUM_INLINE
00157 SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& p,
00158                       const typename SphereH3<R>::Point_3& q,
00159                       const typename SphereH3<R>::Point_3& r,
00160                       const typename SphereH3<R>::Point_3& s)
00161 {
00162   Orientation o = CGAL::orientation(p,q,r,s);
00163   CGAL_kernel_precondition( o != COLLINEAR);
00164   Point_3 center = circumcenter(p,q,r,s);
00165   FT     squared_radius = squared_distance(p,center);
00166   base = Rep(center, squared_radius, o);
00167 }
00168 
00169 template <class R>
00170 CGAL_KERNEL_INLINE
00171 bool
00172 SphereH3<R>::operator==(const SphereH3<R>& s) const
00173 {
00174    return    ( orientation() == s.orientation())
00175           && ( center() == s.center())
00176           && ( squared_radius() == s.squared_radius());
00177 }
00178 
00179 template <class R>
00180 inline
00181 const typename SphereH3<R>::Point_3 &
00182 SphereH3<R>::center() const
00183 { return get(base).get<0>(); }
00184 
00185 template <class R>
00186 inline
00187 const typename SphereH3<R>::FT &
00188 SphereH3<R>::squared_radius() const
00189 { return get(base).get<1>(); }
00190 
00191 template <class R>
00192 inline
00193 Orientation
00194 SphereH3<R>::orientation() const
00195 { return get(base).get<2>(); }
00196 
00197 template <class R>
00198 inline
00199 bool
00200 SphereH3<R>::is_degenerate() const
00201 { return squared_radius() <= FT(0) ; }
00202 
00203 template <class R>
00204 CGAL_KERNEL_MEDIUM_INLINE
00205 Oriented_side
00206 SphereH3<R>::oriented_side(const typename SphereH3<R>::Point_3& p) const
00207 { return Oriented_side(bounded_side(p) * orientation()); }
00208 
00209 template <class R>
00210 CGAL_KERNEL_INLINE
00211 Bounded_side
00212 SphereH3<R>::bounded_side(const typename SphereH3<R>::Point_3& p) const
00213 {
00214   return Bounded_side(CGAL_NTS compare(squared_radius(),
00215                                        squared_distance(center(),p)));
00216 }
00217 
00218 template <class R>
00219 inline
00220 SphereH3<R>
00221 SphereH3<R>::opposite() const
00222 {
00223   return SphereH3<R>(center(), squared_radius(),
00224                          CGAL::opposite(orientation()) );
00225 }
00226 
00227 CGAL_END_NAMESPACE
00228 
00229 #endif // CGAL_SPHEREH3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines