BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
circle3.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 // $Id: circle3.h,v 1.42 2004/07/05 20:57:28 oliver Exp $
5 //
6 
7 #ifndef BALL_MATHS_CIRCLE3_H
8 #define BALL_MATHS_CIRCLE3_H
9 
10 #ifndef BALL_COMMON_EXCEPTION_H
11 # include <BALL/COMMON/exception.h>
12 #endif
13 
14 #ifndef BALL_MATHS_VECTOR3_H
15 # include <BALL/MATHS/vector3.h>
16 #endif
17 
18 
19 namespace BALL
20 {
26  template <typename T>
27  class TCircle3;
28 
33  template <typename T>
35  std::istream& operator >> (std::istream& s, TCircle3<T>& circle);
36 
38  template <typename T>
39  std::ostream& operator << (std::ostream& s, const TCircle3<T>& circle);
41 
44  template <typename T>
45  class TCircle3
46  {
47  public:
48 
50 
51 
54 
60  : p(),
61  n(),
62  radius(0)
63  {
64  }
65 
70  TCircle3(const TCircle3& circle)
71  : p(circle.p),
72  n(circle.n),
73  radius(circle.radius)
74  {
75  }
76 
83  TCircle3(const TVector3<T>& point, const TVector3<T>& normal, const T& radius)
84  : p(point),
85  n(normal),
86  radius(radius)
87  {
88  }
89 
94  virtual ~TCircle3()
95  {
96  }
97 
101  virtual void clear()
102  {
103  p.clear();
104  n.clear();
105  radius = (T)0;
106  }
107 
109 
112 
116  void swap(TCircle3& circle)
117  {
118  TVector3<T> temp_vector(p);
119  p = circle.p;
120  circle.p = temp_vector;
121 
122  temp_vector = n;
123  n = circle.n;
124  circle.n = temp_vector;
125 
126  T temp = radius;
127  radius = circle.radius;
128  circle.radius = temp;
129  }
130 
134  void set(const TCircle3& circle)
135  {
136  p = circle.p;
137  n = circle.n;
138  radius = circle.radius;
139  }
140 
146  void set(const TVector3<T>& point, const TVector3<T>& normal, const T& rad)
147  {
148  p = point;
149  n = normal;
150  radius = rad;
151  }
152 
157  TCircle3& operator = (const TCircle3& circle)
158  {
159  p = circle.p;
160  n = circle.n;
161  radius = circle.radius;
162 
163  return *this;
164  }
165 
170  void get(TCircle3& circle) const
171  {
172  circle.p = p;
173  circle.n = n;
174  circle.radius = radius;
175  }
176 
182  void get(TVector3<T>& point, TVector3<T>& normal, T& rhs) const
183 
184  {
185  point = p;
186  normal = n;
187  rhs = radius;
188  }
189 
191 
194 
198  bool operator == (const TCircle3& circle) const
199  {
200  return (p == circle.p && n == circle.n && Maths::isEqual(radius, circle.radius));
201  }
202 
206  bool operator != (const TCircle3& circle) const
207  {
208  return (p != circle.p || n != circle.n || Maths::isNotEqual(radius, circle.radius));
209  }
210 
217  bool has(const TVector3<T>& point, bool on_surface = false) const
218  {
219  if (on_surface)
220  {
221  return (Maths::isZero(n * (point - p))
222  && Maths::isEqual(p.getDistance(point), radius));
223  }
224  else
225  {
226  return (Maths::isZero(n * (point - p))
227  && Maths::isLessOrEqual(p.getDistance(point), radius));
228  }
229  }
230 
232 
235 
240  bool isValid() const
241  {
242  return true;
243  }
244 
251  void dump(std::ostream& s = std::cout, Size depth = 0) const
252  {
254 
255  BALL_DUMP_HEADER(s, this, this);
256 
257  BALL_DUMP_DEPTH(s, depth);
258  s << " position: " << p << std::endl;
259 
260  BALL_DUMP_DEPTH(s, depth);
261  s << " normal: " << n << std::endl;
262 
263  BALL_DUMP_DEPTH(s, depth);
264  s << " radius: " << radius << std::endl;
265 
267  }
268 
270 
273 
278 
283 
288 
290  };
292 
294 #ifdef BALL_COMPILER_MSVC
295  template class BALL_EXPORT TCircle3<float>;
296 #endif
297 
302 
306  template <typename T>
307  std::istream& operator >> (std::istream& s, TCircle3<T>& circle)
308  {
309  char c;
310  s >> c;
311  s >> circle.p >> circle.n >> circle.radius;
312  s >> c;
313  return s;
314  }
315 
323  template <typename T>
324  std::ostream& operator << (std::ostream& s, const TCircle3<T>& circle)
325  {
326  return s << '(' << circle.p
327  << ' ' << circle.n
328  << ' ' << circle.radius
329  << ')';
330  }
331 
332 } // namespace BALL
333 
334 #endif // BALL_MATHS_CIRCLE3_H
bool isLessOrEqual(const T1 &a, const T2 &b)
Definition: MATHS/common.h:256
TVector3< T > p
Definition: circle3.h:277
bool isValid() const
Definition: circle3.h:240
TCircle3(const TVector3< T > &point, const TVector3< T > &normal, const T &radius)
Definition: circle3.h:83
virtual void clear()
Definition: circle3.h:101
#define BALL_CREATE(name)
Definition: create.h:62
bool isEqual(const T1 &a, const T2 &b)
Definition: MATHS/common.h:219
bool has(const TVector3< T > &point, bool on_surface=false) const
Definition: circle3.h:217
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
TCircle3(const TCircle3 &circle)
Definition: circle3.h:70
bool isZero(const T &t)
Definition: MATHS/common.h:196
virtual ~TCircle3()
Definition: circle3.h:94
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
void swap(TCircle3 &circle)
Definition: circle3.h:116
TVector3< T > n
Definition: circle3.h:282
#define BALL_DUMP_HEADER(os, cl, ob)
Definition: macros.h:86
TCircle3< float > Circle3
Definition: circle3.h:301
TCircle3 & operator=(const TCircle3 &circle)
Definition: circle3.h:157
bool operator!=(const TCircle3 &circle) const
Definition: circle3.h:206
bool isNotEqual(const T1 &a, const T2 &b)
Definition: MATHS/common.h:231
bool operator==(const TCircle3 &circle) const
Definition: circle3.h:198
void set(const TVector3< T > &point, const TVector3< T > &normal, const T &rad)
Definition: circle3.h:146
#define BALL_DUMP_STREAM_PREFIX(os)
Definition: macros.h:84
void set(const TCircle3 &circle)
Definition: circle3.h:134
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition: circle3.h:251
#define BALL_DUMP_STREAM_SUFFIX(os)
Definition: macros.h:88
#define BALL_DUMP_DEPTH(os, depth)
Definition: macros.h:83
#define BALL_EXPORT
Definition: COMMON/global.h:50