circle3.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: circle3.h,v 1.42 2004/07/05 20:57:28 oliver Exp $
00005 //
00006 
00007 #ifndef BALL_MATHS_CIRCLE3_H
00008 #define BALL_MATHS_CIRCLE3_H
00009 
00010 #ifndef BALL_COMMON_EXCEPTION_H
00011 # include <BALL/COMMON/exception.h>
00012 #endif
00013 
00014 #ifndef BALL_MATHS_VECTOR3_H
00015 # include <BALL/MATHS/vector3.h>
00016 #endif
00017 
00018 
00019 namespace BALL 
00020 {
00026   template <typename T>
00027   class TCircle3;
00028 
00033 
00034   template <typename T>
00035   std::istream& operator >> (std::istream& s, TCircle3<T>& circle);
00036 
00038   template <typename T>
00039   std::ostream& operator << (std::ostream& s, const TCircle3<T>& circle);
00041   
00044   template <typename T>
00045   class TCircle3
00046   {
00047     public:
00048 
00049     BALL_CREATE(TCircle3<T>)
00050 
00051     
00054 
00059     TCircle3()
00060       : p(),
00061         n(),
00062         radius(0)
00063     {
00064     }
00065 
00070     TCircle3(const TCircle3& circle)
00071       : p(circle.p),
00072         n(circle.n),
00073         radius(circle.radius)
00074     {
00075     }
00076 
00083     TCircle3(const TVector3<T>& point, const TVector3<T>& normal, const T& radius)
00084       : p(point),
00085         n(normal),
00086         radius(radius)
00087     {
00088     }
00089 
00094     virtual ~TCircle3()
00095     {
00096     }
00097 
00101     virtual void clear() 
00102     {
00103       p.clear();
00104       n.clear();
00105       radius = (T)0;
00106     }
00107 
00109 
00112 
00116     void swap(TCircle3& circle)
00117     {
00118       TVector3<T> temp_vector(p);
00119       p = circle.p;
00120       circle.p = temp_vector;
00121 
00122       temp_vector = n;
00123       n = circle.n;
00124       circle.n = temp_vector;
00125 
00126       T temp = radius;
00127       radius = circle.radius;
00128       circle.radius = temp;
00129     }
00130 
00134     void set(const TCircle3& circle)
00135     {
00136       p = circle.p;
00137       n = circle.n;
00138       radius = circle.radius;
00139     }
00140 
00146     void set(const TVector3<T>& point, const TVector3<T>& normal, const T& rad)
00147     {
00148       p = point;
00149       n = normal;
00150       radius = rad;
00151     }
00152 
00157     TCircle3& operator = (const TCircle3& circle)
00158     {
00159       p = circle.p;
00160       n = circle.n;
00161       radius = circle.radius;
00162 
00163       return *this;
00164     }
00165 
00170     void get(TCircle3& circle) const
00171     {
00172       circle.p = p;
00173       circle.n = n;
00174       circle.radius = radius;
00175     }
00176 
00182     void get(TVector3<T>& point, TVector3<T>& normal, T& rhs) const
00183 
00184     {
00185       point = p;
00186       normal = n;
00187       rhs = radius;
00188     }
00189 
00191 
00194 
00198     bool operator == (const TCircle3& circle) const
00199     {
00200       return (p == circle.p && n == circle.n && Maths::isEqual(radius, circle.radius));
00201     }
00202 
00206     bool operator != (const TCircle3& circle) const
00207     {
00208       return (p != circle.p || n != circle.n || Maths::isNotEqual(radius, circle.radius));
00209     }
00210 
00217     bool has(const TVector3<T>& point, bool on_surface = false) const
00218     {
00219       if (on_surface)
00220       {
00221         return (Maths::isZero(n * (point - p))
00222                       && Maths::isEqual(p.getDistance(point), radius));
00223       } 
00224       else 
00225       {
00226         return (Maths::isZero(n * (point - p)) 
00227                       && Maths::isLessOrEqual(p.getDistance(point), radius));
00228       }
00229     }
00230 
00232 
00235 
00240     bool isValid() const
00241     {
00242       return true;
00243     }
00244 
00251     void dump(std::ostream& s = std::cout, Size depth = 0) const
00252     {
00253       BALL_DUMP_STREAM_PREFIX(s);
00254   
00255       BALL_DUMP_HEADER(s, this, this);
00256 
00257       BALL_DUMP_DEPTH(s, depth);
00258       s << "  position: " << p << std::endl;
00259 
00260       BALL_DUMP_DEPTH(s, depth);
00261       s << "  normal: " << n << std::endl;
00262 
00263       BALL_DUMP_DEPTH(s, depth);
00264       s << "  radius: " << radius << std::endl;
00265 
00266       BALL_DUMP_STREAM_SUFFIX(s);
00267     }
00268 
00270 
00273 
00277     TVector3<T> p;
00278 
00282     TVector3<T> n;
00283 
00287     T radius;
00288 
00290   };
00292 
00294 #ifdef BALL_COMPILER_MSVC
00295   template class BALL_EXPORT TCircle3<float>;
00296 #endif
00297 
00301   typedef TCircle3<float> Circle3;
00302 
00306   template <typename T>
00307   std::istream& operator >> (std::istream& s, TCircle3<T>& circle)
00308   {
00309       char c;
00310       s >> c;
00311       s >> circle.p >> circle.n >> circle.radius;
00312       s >> c;
00313       return s;
00314   }
00315 
00323   template <typename T>
00324   std::ostream& operator << (std::ostream& s, const TCircle3<T>& circle)
00325   {
00326       return s << '(' << circle.p 
00327                << ' ' << circle.n
00328                << ' ' << circle.radius 
00329                << ')';
00330   }
00331 
00332 } // namespace BALL
00333 
00334 #endif // BALL_MATHS_CIRCLE3_H