vtf-logo

Circle3.h

00001 // -*- C++ -*-
00002 
00003 #if !defined(__geom_kernel_Circle3_h__)
00004 #define __geom_kernel_Circle3_h__
00005 
00006 // If we are debugging the whole geom namespace.
00007 #if defined(DEBUG_geom) && !defined(DEBUG_Circle3)
00008 #define DEBUG_Circle3
00009 #endif
00010 
00011 #ifdef DEBUG_Circle3
00012 #ifndef DEBUG_Point
00013 #define DEBUG_Point
00014 #endif
00015 #endif
00016 
00017 #include "Point.h"
00018 #include "SegmentMath.h"
00019 
00020 BEGIN_NAMESPACE_GEOM
00021 
00023 
00028 template<typename T = double>
00029 class Circle3 {
00030   //
00031   // Types
00032   //
00033 
00034 public:
00035     
00037   typedef T Number;
00039   typedef ads::FixedArray<3,Number> Point;
00040 
00041   //
00042   // Data
00043   //
00044 
00045 private:
00046     
00047   Point _center;
00048   Point _normal;
00049   Number _radius;
00050     
00051 public:
00052     
00053   //--------------------------------------------------------------------------
00055   // @{
00056 
00058   Circle3() 
00059   {}
00060 
00062   Circle3(const Point& center, const Point& normal, const Number radius) : 
00063     _center(center),
00064     _normal(normal),
00065     _radius(radius) 
00066   {}
00067 
00069   Circle3(const Circle3& other) :
00070     _center(other._center),
00071     _normal(other._normal),
00072     _radius(other._radius) 
00073   {}
00074 
00076   Circle3& 
00077   operator=(const Circle3& other);
00078 
00080   ~Circle3() 
00081   {}
00082 
00084   void 
00085   make(const Point& center, const Point& normal, const Number radius) { 
00086     _center = center;
00087     _normal = normal;
00088     _radius = radius;
00089   }
00090 
00091   // @}
00092   //--------------------------------------------------------------------------
00094   // @{
00095 
00097   const Point&
00098   getCenter() const { 
00099     return _center; 
00100   }
00101 
00103   const Point&
00104   getNormal() const { 
00105     return _normal; 
00106   }
00107 
00109   Number
00110   getRadius() const { 
00111     return _radius; 
00112   }
00113     
00114   // @}
00115   //--------------------------------------------------------------------------
00117   // @{
00118 
00120   void
00121   setCenter(const Point& center) { 
00122     _center = center;
00123   }
00124 
00126   void
00127   setNormal(const Point& normal) { 
00128     _normal = normal;
00129   }
00130 
00132   void
00133   setRadius(const Number radius) { 
00134     _radius = radius;
00135   }
00136     
00137   // @}
00138   //--------------------------------------------------------------------------
00140   // @{
00141 
00143   Circle3& 
00144   operator+=(const Point& x) {
00145     _center += x;
00146     return (*this);
00147   }
00148 
00150   Circle3& 
00151   operator-=(const Point& x) {
00152     _center -= x;
00153     return (*this);
00154   }
00155 
00156   // @}
00157   //--------------------------------------------------------------------------
00159 
00160   
00162   bool
00163   isValid() const;
00164   
00166 };
00167 
00168 //
00169 // Mathematical functions.
00170 //
00171 
00173 template<typename T>
00174 void 
00175 computeClosestPoint(const Circle3<T>& circle, 
00176                     typename Circle3<T>::Point x,
00177                     typename Circle3<T>::Point* closestPoint);
00178 
00180 template<typename T>
00181 void 
00182 computeClosestPoint(const Circle3<T>& circle, 
00183                     const typename Circle3<T>::Point& source,
00184                     const typename Circle3<T>::Point& target,
00185                     typename Circle3<T>::Point* closestPoint,
00186                     T tolerance = std::sqrt(std::numeric_limits<T>::epsilon()),
00187                     int maximumSteps = 10);
00188 
00189 //
00190 // Equality Operators.
00191 //
00192 
00194 
00195 template<typename T>
00196 inline
00197 bool 
00198 operator==(const Circle3<T>& x, const Circle3<T>& y) {
00199   return (x.getCenter() == y.getCenter() && x.getNormal() == y.getNormal() && 
00200           x.getRadius() == y.getRadius() );
00201 }
00202 
00203 
00205 
00206 template<typename T>
00207 inline
00208 bool 
00209 operator!=(const Circle3<T>& x, const Circle3<T>& y) {
00210   return !(x == y);
00211 }
00212 
00213 
00214 //
00215 // Binary Operators.
00216 //
00217 
00219 
00220 template<typename T>
00221 inline
00222 Circle3<T> 
00223 operator+(const Circle3<T>& circle, const typename Circle3<T>::Point& vector) {
00224   return Circle3<T>(circle.getCenter() + vector, circle.getNormal(),
00225                     circle.getRadius());
00226 }
00227 
00229 
00230 template<typename T>
00231 inline
00232 Circle3<T> 
00233 operator-(const Circle3<T>& circle, const typename Circle3<T>::Point& vector) {
00234   return Circle3<T>(circle.getCenter() - vector, circle.getNormal(),
00235                     circle.getRadius());
00236 }
00237 
00238 
00239 //
00240 // File I/O Operators.
00241 //
00242 
00244 
00245 template<typename T>
00246 std::istream& 
00247 operator>>(std::istream& in, Circle3<T>& x);
00248 
00250 
00251 template<typename T>
00252 inline
00253 std::ostream& 
00254 operator<<(std::ostream& out, const Circle3<T>& x) {
00255   return out << x.getCenter() << " " << x.getNormal() << " " << x.getRadius();
00256 }
00257 
00258 
00259 END_NAMESPACE_GEOM
00260 
00261 #define __geom_kernel_Circle3_ipp__
00262 #include "Circle3.ipp"
00263 #undef __geom_kernel_Circle3_ipp__
00264   
00265 #endif

Generated on Fri Aug 24 12:55:51 2007 for Computational Geometry Package by  doxygen 1.4.7