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
sphere3.h
Go to the documentation of this file.
1
// -*- Mode: C++; tab-width: 2; -*-
2
// vi: set ts=2:
3
//
4
5
#ifndef BALL_MATHS_SPHERE3_H
6
#define BALL_MATHS_SPHERE3_H
7
8
#ifdef BALL_HAS_IEEEFP_H
9
# include <ieeefp.h>
10
#endif
11
12
#include <iostream>
13
14
#ifndef BALL_MATHS_PLANE3_H
15
# include <
BALL/MATHS/plane3.h
>
16
#endif
17
18
#ifndef BALL_MATHS_VECTOR3_H
19
# include <
BALL/MATHS/vector3.h
>
20
#endif
21
22
namespace
BALL
23
{
28
31
template
<
typename
T>
32
class
TSphere3
33
{
34
public
:
35
36
BALL_CREATE
(
TSphere3
)
37
38
41
46
TSphere3
()
47
:
p
(),
48
radius
(0)
49
{
50
}
51
56
TSphere3
(
const
TSphere3
& sphere)
57
:
p
(sphere.
p
),
58
radius
(sphere.
radius
)
59
{
60
}
61
67
TSphere3
(
const
TVector3<T>
& point,
const
T&
radius
)
68
:
p
(point),
69
radius(radius)
70
{
71
}
72
76
virtual
~TSphere3
()
77
{
78
}
79
82
virtual
void
clear
()
83
{
84
p
.clear();
85
radius
= (T) 0;
86
}
88
92
96
void
swap
(
TSphere3
& sphere)
97
{
98
TVector3<T>
temp_point(
p
);
99
p
= sphere.
p
;
100
sphere.
p
= temp_point;
101
102
T temp =
radius
;
103
radius
= sphere.
radius
;
104
sphere.
radius
= temp;
105
}
106
110
void
set
(
const
TSphere3
& sphere)
111
{
112
p
= sphere.p;
113
radius
= sphere.radius;
114
}
115
121
void
set
(
const
TVector3<T>
& point,
const
T& r)
122
{
123
p
= point;
124
radius
= r;
125
}
126
131
TSphere3
&
operator =
(
const
TSphere3
& sphere)
132
{
133
p
= sphere.
p
;
134
radius
= sphere.
radius
;
135
return
*
this
;
136
}
137
142
void
get
(
TSphere3
& sphere)
const
143
{
144
sphere.p =
p
;
145
sphere.radius =
radius
;
146
}
147
152
void
get
(
TVector3<T>
& point, T& r)
const
153
{
154
point =
p
;
155
r =
radius
;
156
}
157
159
162
166
bool
operator ==
(
const
TSphere3
& sphere)
const
167
{
168
return
(
p
== sphere.
p
&&
Maths::isEqual
(
radius
, sphere.
radius
));
169
}
170
174
bool
operator !=
(
const
TSphere3
& sphere)
const
175
{
176
return
(
p
!= sphere.
p
||
Maths::isNotEqual
(
radius
, sphere.
radius
));
177
}
178
185
bool
has
(
const
TVector3<T>
& point,
bool
on_surface =
false
)
const
186
{
187
if
(on_surface)
188
{
189
return
Maths::isEqual
(
p
.getDistance(point),
radius
);
190
}
191
else
192
{
193
return
Maths::isLessOrEqual
(
p
.getDistance(point),
radius
);
194
}
195
}
196
200
bool
isEmpty
()
const
201
202
{
203
return
Maths::isZero
(
radius
);
204
}
205
207
210
215
bool
isValid
()
const
216
217
{
218
return
true
;
219
}
220
227
void
dump
(std::ostream& s = std::cout,
Size
depth = 0)
const
228
229
{
230
BALL_DUMP_STREAM_PREFIX
(s);
231
232
BALL_DUMP_HEADER
(s,
this
,
this
);
233
234
BALL_DUMP_DEPTH
(s, depth);
235
s <<
" position: "
<<
p
<< std::endl;
236
237
BALL_DUMP_DEPTH
(s, depth);
238
s <<
" radius: "
<<
radius
<< std::endl;
239
240
BALL_DUMP_STREAM_SUFFIX
(s);
241
}
242
244
247
250
TVector3<T>
p
;
251
254
T
radius
;
255
257
};
259
266
270
template
<
typename
T>
271
std::istream&
operator >>
(std::istream& s,
TSphere3<T>
& sphere)
272
273
{
274
char
c
;
275
s >> c >> sphere.
p
>> sphere.
radius
>>
c
;
276
return
s;
277
}
278
285
template
<
typename
T>
286
std::ostream& operator << (std::ostream& s, const TSphere3<T>& sphere)
287
288
{
289
s <<
'('
<< sphere.p <<
' '
<< sphere.radius <<
')'
;
290
return
s;
291
}
293
299
typedef
TSphere3<float>
Sphere3
;
300
301
}
// namespace BALL
302
303
#endif // BALL_MATHS_SPHERE3_H
Generated by
1.8.3.1