vtf-logo

CircularArc3.h

00001 // -*- C++ -*-
00002 
00003 #if !defined(__geom_kernel_CircularArc3_h__)
00004 #define __geom_kernel_CircularArc3_h__
00005 
00006 // If we are debugging the whole geom namespace.
00007 #if defined(DEBUG_geom) && !defined(DEBUG_CircularArc3)
00008 #define DEBUG_CircularArc3
00009 #endif
00010 
00011 #ifdef DEBUG_CircularArc3
00012 #ifndef DEBUG_Point
00013 #define DEBUG_Point
00014 #endif
00015 #endif
00016 
00017 #include "Circle3.h"
00018 
00019 #include "../../numerical/constants.h"
00020 
00021 BEGIN_NAMESPACE_GEOM
00022 
00024 
00038 template<typename T = double>
00039 class CircularArc3 {
00040   //
00041   // Types
00042   //
00043 
00044 public:
00045     
00047   typedef T Number;
00049   typedef ads::FixedArray<3,Number> Point;
00050 
00051 private:
00052 
00054   typedef Circle3<Number> Circle;
00055 
00056   //
00057   // Data
00058   //
00059 
00060 private:
00061     
00062   Circle _circle;
00063   Point _axis0, _axis1;
00064   Number _angle;
00065 
00066 public:
00067     
00068   //--------------------------------------------------------------------------
00070   // @{
00071 
00073   CircularArc3() 
00074   {}
00075 
00077   CircularArc3(const Point& center, const Point& source, 
00078                const Point& target) : 
00079     _circle(),
00080     _axis0(),
00081     _axis1(),
00082     _angle() {
00083     make(center, source, target);
00084   }
00085 
00087   CircularArc3(const CircularArc3& other) :
00088     _circle(other._circle),
00089     _axis0(other._axis0),
00090     _axis1(other._axis1),
00091     _angle(other._angle)
00092   {}
00093 
00095   CircularArc3& 
00096   operator=(const CircularArc3& other);
00097 
00099   ~CircularArc3() 
00100   {}
00101 
00103   void 
00104   make(const Point& center, const Point& source, const Point& target);
00105 
00106   // @}
00107   //--------------------------------------------------------------------------
00109   // @{
00110 
00112   const Circle&
00113   getCircle() const { 
00114     return _circle; 
00115   }
00116 
00118   const Point&
00119   getCenter() const { 
00120     return _circle.getCenter(); 
00121   }
00122 
00124   Number
00125   getRadius() const { 
00126     return _circle.getRadius(); 
00127   }
00128 
00130   const Point&
00131   getFirstAxis() const { 
00132     return _axis0; 
00133   }
00134 
00136   const Point&
00137   getSecondAxis() const { 
00138     return _axis1; 
00139   }
00140 
00142   Number
00143   getAngle() const { 
00144     return _angle; 
00145   }
00146     
00147   // @}
00148   //--------------------------------------------------------------------------
00150   // @{
00151 
00153 
00156   Point
00157   operator()(const Number t) const {
00158     Point x = getCenter() + getRadius() * (std::cos(_angle * t) * _axis0 + 
00159                                            std::sin(_angle * t) * _axis1);
00160     return x;
00161   }
00162 
00163   // @}
00164   //--------------------------------------------------------------------------
00166   // @{
00167 
00169   CircularArc3& 
00170   operator+=(const Point& x) {
00171     _circle += x;
00172     return (*this);
00173   }
00174 
00176   CircularArc3& 
00177   operator-=(const Point& x) {
00178     _circle -= x;
00179     return (*this);
00180   }
00181 
00182   // @}
00183   //--------------------------------------------------------------------------
00185 
00186   
00188   bool
00189   isValid() const;
00190   
00192 };
00193 
00194 
00195 //
00196 // Mathematical functions.
00197 //
00198 
00199 
00201 template<typename T>
00202 void 
00203 computeClosestPoint(const CircularArc3<T>& circularArc, 
00204                     typename CircularArc3<T>::Point x,
00205                     typename CircularArc3<T>::Point* closestPoint);
00206 
00207 
00209 template<typename T>
00210 void 
00211 computeClosestPoint(const Circle3<T>& circle,
00212                     const CircularArc3<T>& circularArc,
00213                     typename CircularArc3<T>::Point* closestPoint,
00214                     T tolerance = std::sqrt(std::numeric_limits<T>::epsilon()),
00215                     int maximumSteps = 10);
00216 
00217 
00218 //
00219 // Equality Operators.
00220 //
00221 
00222 
00224 
00225 template<typename T>
00226 inline
00227 bool 
00228 operator==(const CircularArc3<T>& x, const CircularArc3<T>& y) {
00229   return (x.getCircle() == y.getCircle() && 
00230           x.getFirstAxis() == y.getFirstAxis() && 
00231           x.getSecondAxis() == y.getSecondAxis() && 
00232           x.getAngle() == y.getAngle());
00233 }
00234 
00235 
00237 
00238 template<typename T>
00239 inline
00240 bool 
00241 operator!=(const CircularArc3<T>& x, const CircularArc3<T>& y) {
00242   return !(x == y);
00243 }
00244 
00245 
00246 //
00247 // Binary Operators.
00248 //
00249 
00251 
00252 template<typename T>
00253 inline
00254 CircularArc3<T> 
00255 operator+(const CircularArc3<T>& circularArc, 
00256           const typename CircularArc3<T>::Point& vector) {
00257   CircularArc3<T> x(circularArc);
00258   x += vector;
00259   return x;
00260 }
00261 
00262 
00264 
00265 template<typename T>
00266 inline
00267 CircularArc3<T> 
00268 operator-(const CircularArc3<T>& circularArc, 
00269           const typename CircularArc3<T>::Point& vector) {
00270   CircularArc3<T> x(circularArc);
00271   x -= vector;
00272   return x;
00273 }
00274 
00275 
00276 //
00277 // File I/O Operators.
00278 //
00279 
00280 
00282 
00283 template<typename T>
00284 std::istream& 
00285 operator>>(std::istream& in, CircularArc3<T>& x);
00286 
00287 
00289 
00290 template<typename T>
00291 inline
00292 std::ostream& 
00293 operator<<(std::ostream& out, const CircularArc3<T>& x) {
00294   return out << x.getCenter() << " " << x(0.0) << " " << x(1.0);
00295 }
00296 
00297 
00298 END_NAMESPACE_GEOM
00299 
00300 #define __geom_kernel_CircularArc3_ipp__
00301 #include "CircularArc3.ipp"
00302 #undef __geom_kernel_CircularArc3_ipp__
00303   
00304 #endif

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