BALL
1.4.2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
include
BALL
MATHS
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
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
namespace
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
50
BALL_CREATE
(
TLine3<T>
)
51
52
55
60
enum
Form
61
{
62
FORM__PARAMETER
= 0,
63
FORM__TWO_POINTS
= 1
64
};
66
70
73
TLine3
()
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
185
TLine3
&
operator =
(
const
TLine3
& line)
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
237
void
normalize
()
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
{
326
BALL_DUMP_STREAM_PREFIX
(s);
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
336
BALL_DUMP_STREAM_SUFFIX
(s);
337
}
339
340
344
347
TVector3<T>
p
;
348
351
TVector3<T>
d
;
353
};
355
359
typedef
TLine3<float>
Line3
;
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
Generated by
1.8.3.1