Class
List
Heirarchy
Modules
Common
Events
Math
Messages
Physics
Rendering
Sensors
Transport
Links
Gazebo Website
Wiki
Tutorials
Download
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
gazebo
math
Vector3.hh
Go to the documentation of this file.
1
/*
2
* Copyright 2011 Nate Koenig
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
*/
17
/* Desc: The world; all models are collected here
18
* Author: Nate Koenig
19
* Date: 3 Apr 2007
20
*/
21
22
#ifndef VECTOR3_HH
23
#define VECTOR3_HH
24
25
#include <math.h>
26
#include <iostream>
27
#include <fstream>
28
29
#include "
gazebo/common/CommonTypes.hh
"
30
31
namespace
gazebo
32
{
33
namespace
math
34
{
37
41
class
Vector3
42
{
44
public
:
Vector3
();
45
50
public
:
Vector3
(
const
double
&_x,
const
double
&_y,
const
double
&_z);
51
54
public
:
Vector3
(
const
Vector3
&_v);
55
57
public
:
virtual
~Vector3
();
58
61
public
:
double
GetSum
()
const
;
62
66
public
:
double
Distance
(
const
Vector3
&_pt)
const
;
67
73
public
:
double
Distance
(
double
_x,
double
_y,
double
_z)
const
;
74
77
public
:
double
GetLength
()
const
;
78
81
public
:
double
GetSquaredLength
()
const
;
82
85
public
:
Vector3
Normalize
();
86
89
public
:
Vector3
Round
();
90
93
public
:
Vector3
GetRounded
()
const
;
94
99
public
:
inline
void
Set
(
double
_x = 0,
double
_y = 0 ,
double
_z = 0)
100
{
101
this->
x
= _x;
102
this->
y
= _y;
103
this->
z
= _z;
104
}
105
108
public
:
Vector3
Cross
(
const
Vector3
&_pt)
const
;
109
112
public
:
double
Dot
(
const
Vector3
&_pt)
const
;
113
116
public
:
Vector3
GetAbs
()
const
;
117
120
public
:
Vector3
GetPerpendicular
()
const
;
121
127
public
:
static
Vector3
GetNormal
(
const
Vector3
&_v1,
const
Vector3
&_v2,
128
const
Vector3
&_v3);
129
134
public
:
double
GetDistToLine
(
const
Vector3
&_pt1,
const
Vector3
&_pt2);
135
139
public
:
void
SetToMax
(
const
Vector3
&_v);
140
144
public
:
void
SetToMin
(
const
Vector3
&_v);
145
148
public
:
double
GetMax
()
const
;
149
152
public
:
double
GetMin
()
const
;
153
157
public
:
Vector3
&
operator =
(
const
Vector3
&_v);
158
162
public
:
Vector3
&
operator =
(
double
_value);
163
167
public
:
Vector3
operator+
(
const
Vector3
&_v)
const
;
168
171
public
:
const
Vector3
&
operator+=
(
const
Vector3
&_v);
172
176
public
:
inline
Vector3
operator-
(
const
Vector3
&_pt)
const
177
{
178
return
Vector3
(this->
x
- _pt.
x
,
179
this->y - _pt.
y
,
180
this->z - _pt.
z
);
181
}
182
184
public
:
const
Vector3
&
operator-=
(
const
Vector3
&_pt);
185
189
public
:
const
Vector3
operator/
(
const
Vector3
&_pt)
const
;
190
194
public
:
const
Vector3
&
operator/=
(
const
Vector3
&_pt);
195
199
public
:
const
Vector3
operator/
(
double
_v)
const
;
200
204
public
:
const
Vector3
&
operator/=
(
double
_v);
205
209
public
:
Vector3
operator*
(
const
Vector3
&_p)
const
;
210
215
public
:
const
Vector3
&
operator*=
(
const
Vector3
&_v);
216
220
public
:
Vector3
operator*
(
double
_v)
const
;
221
225
public
:
const
Vector3
&
operator*=
(
double
_v);
226
230
public
:
bool
operator ==
(
const
Vector3
&_pt)
const
;
231
236
public
:
bool
operator!=
(
const
Vector3
&_v)
const
;
237
239
public
:
bool
IsFinite
()
const
;
240
242
public
:
inline
void
Correct
()
243
{
244
if
(!finite(this->
x
))
245
this->
x
= 0;
246
if
(!finite(this->
y
))
247
this->
y
= 0;
248
if
(!finite(this->
z
))
249
this->
z
= 0;
250
}
251
253
public
:
double
operator[]
(
unsigned
int
index)
const
;
254
257
public
:
void
Round
(
int
_precision);
258
263
public
:
bool
Equal
(
const
Vector3
&_v)
const
;
264
266
public
:
double
x
;
267
269
public
:
double
y
;
270
272
public
:
double
z
;
273
278
public
:
friend
std::ostream &
operator<<
(std::ostream &_out,
279
const
gazebo::math::Vector3
&_pt)
280
{
281
_out << _pt.
x
<<
" "
<< _pt.
y
<<
" "
<< _pt.
z
;
282
return
_out;
283
}
284
289
public
:
friend
std::istream &
operator>>
(std::istream &_in,
290
gazebo::math::Vector3
&_pt)
291
{
292
// Skip white spaces
293
_in.setf(std::ios_base::skipws);
294
_in >> _pt.
x
>> _pt.
y
>> _pt.
z
;
295
return
_in;
296
}
297
};
299
}
300
}
301
#endif
302