BALL 1.5.0
line3.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4// $Id: line3.h,v 1.48 2004/07/05 20:57:28 oliver Exp $
5//
6
7#ifndef BALL_MATHS_LINE3_H
8#define BALL_MATHS_LINE3_H
9
10#ifndef BALL_COMMON_EXCEPTION_H
12#endif
13
14#ifndef BALL_MATHS_VECTOR3_H
15# include <BALL/MATHS/vector3.h>
16#endif
17
18namespace BALL
19{
26
27 template <typename T>
28 class TLine3;
29
34 template <typename T>
35 std::ostream& operator << (std::ostream& s, const TLine3<T>& line)
36 ;
37
38 template <typename T>
39 std::istream& operator >> (std::istream& s, TLine3<T>& line)
40 ;
42
45 template <typename T>
46 class TLine3
47 {
48 public:
49
51
52
55
56
60 enum Form
61 {
64 };
66
70
74
75 : p(),
76 d()
77 {
78 }
79
84 TLine3(const TLine3& line)
85
86 : p(line.p),
87 d(line.d)
88 {
89 }
90
91 // form: PARAMETER (default) or TWO_POINTS
92
102 TLine3(const TVector3<T>& point, const TVector3<T>& vector, Form form = FORM__PARAMETER)
103
104 : p(point),
105 d((form == FORM__PARAMETER)
106 ? vector
107 : vector - point)
108 {
109 }
110
115 virtual ~TLine3()
116
117 {
118 }
119
123 virtual void clear()
124
125 {
126 p.clear();
127 d.clear();
128 }
129
131
135
139 void swap(TLine3& line)
140
141 {
142 TVector3<T> temp_point(p);
143 p = line.p;
144 line.p = temp_point;
145
146 TVector3<T> temp_vector(d);
147 d = line.d;
148 line.d = temp_vector;
149 }
150
154 void set(const TLine3& line)
155
156 {
157 p = line.p;
158 d = line.d;
159 }
160
167 void set(const TVector3<T>& point, const TVector3<T>& vector, Form form = FORM__PARAMETER)
168
169 {
170 p = point;
171 if (form == FORM__PARAMETER)
172 {
173 d = vector;
174 }
175 else
176 {
177 d = vector - point;
178 }
179 }
180
186
187 {
188 p = line.p;
189 d = line.d;
190
191 return *this;
192 }
193
198 void get(TLine3& line) const
199 {
200 line.p = p;
201 line.d = d;
202 }
203
212 void get(TVector3<T>& point,TVector3<T>& vector, Form form = FORM__PARAMETER) const
213
214 {
215 point = p;
216 if (form == FORM__PARAMETER)
217 {
218 vector = d;
219 }
220 else
221 {
222 vector - point = d;
223 }
224 }
225
227
231
238
239 {
240 d.normalize();
241 }
243
247
251 bool operator == (const TLine3& line) const
252
253 {
254 return (p == line.p && d == line.d);
255 }
256
260 bool operator != (const TLine3& line) const
261
262 {
263 return (p != line.p || d != line.d);
264 }
265
269 bool has(const TVector3<T>& point) const
270
271 {
272 if (Maths::isNotZero(d.x))
273 {
274 T c = (point.x - p.x) / d.x;
275
276 return (Maths::isEqual(p.y + c * d.y, point.y) && Maths::isEqual(p.z + c * d.z, point.z));
277 }
278 else
279 {
280 if (Maths::isNotZero(d.y))
281 {
282 T c = (point.y - p.y) / d.y;
283
284 return (Maths::isEqual(p.x, point.x) // invariant: d.x == 0
285 && Maths::isEqual(p.z + c * d.z, point.z));
286 }
287 else
288 {
289 if (Maths::isNotZero(d.z))
290 {
291 return (Maths::isEqual(p.x, point.x) // invariant: d.x == 0
292 && Maths::isEqual(p.y, point.y)); // invariant: d.y == 0
293 }
294 else
295 {
296 return false;
297 }
298 }
299 }
300 }
301
303
306
311 bool isValid() const
312
313 {
314 return true;
315 }
316
323 void dump(std::ostream& s = std::cout, Size depth = 0) const
324
325 {
327
328 BALL_DUMP_HEADER(s, this, this);
329
330 BALL_DUMP_DEPTH(s, depth);
331 s << " position: " << p << std::endl;
332
333 BALL_DUMP_DEPTH(s, depth);
334 s << " direction: " << d << std::endl;
335
337 }
339
340
344
348
353 };
355
360
365 template <typename T>
366 std::istream& operator >> (std::istream& s, TLine3<T>& line)
367
368 {
369 char c;
370 s >> c >> line.p >> line.d >> c;
371 return s;
372 }
373
381 template <typename T>
382 std::ostream& operator << (std::ostream& s, const TLine3<T>& line)
383
384 {
385 s << '(' << line.p << ' ' << line.d << ')';
386 return s;
387 }
388} // namespace BALL
389
390#endif // BALL_MATHS_LINE3_H
#define BALL_CREATE(name)
Definition: create.h:62
#define BALL_DUMP_STREAM_PREFIX(os)
Definition: macros.h:391
#define BALL_DUMP_STREAM_SUFFIX(os)
Definition: macros.h:395
#define BALL_DUMP_DEPTH(os, depth)
Definition: macros.h:390
#define BALL_DUMP_HEADER(os, cl, ob)
Definition: macros.h:393
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
TLine3< float > Line3
Definition: line3.h:359
Definition: constants.h:13
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
bool isNotZero(const T &t)
Definition: MATHS/common.h:200
bool isEqual(const T1 &a, const T2 &b)
Definition: MATHS/common.h:212
TLine3(const TLine3 &line)
Definition: line3.h:84
TVector3< T > p
Definition: line3.h:347
void set(const TVector3< T > &point, const TVector3< T > &vector, Form form=FORM__PARAMETER)
Definition: line3.h:167
void get(TLine3 &line) const
Definition: line3.h:198
void set(const TLine3 &line)
Definition: line3.h:154
TLine3(const TVector3< T > &point, const TVector3< T > &vector, Form form=FORM__PARAMETER)
Definition: line3.h:102
bool operator!=(const TLine3 &line) const
Definition: line3.h:260
TLine3()
Definition: line3.h:73
bool operator==(const TLine3 &line) const
Definition: line3.h:251
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition: line3.h:323
@ FORM__PARAMETER
Definition: line3.h:62
@ FORM__TWO_POINTS
Definition: line3.h:63
bool has(const TVector3< T > &point) const
Definition: line3.h:269
virtual ~TLine3()
Definition: line3.h:115
TVector3< T > d
Definition: line3.h:351
void swap(TLine3 &line)
Definition: line3.h:139
bool isValid() const
Definition: line3.h:311
void normalize()
Definition: line3.h:237
void get(TVector3< T > &point, TVector3< T > &vector, Form form=FORM__PARAMETER) const
Definition: line3.h:212
virtual void clear()
Definition: line3.h:123
TLine3 & operator=(const TLine3 &line)
Definition: line3.h:185