All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Vector3.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
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/math/Helpers.hh"
30 #include "gazebo/util/system.hh"
31 
32 namespace gazebo
33 {
34  namespace math
35  {
38 
44  {
46  public: static const Vector3 Zero;
47 
49  public: static const Vector3 One;
50 
52  public: static const Vector3 UnitX;
53 
55  public: static const Vector3 UnitY;
56 
58  public: static const Vector3 UnitZ;
59 
61  public: Vector3();
62 
67  public: Vector3(const double &_x, const double &_y, const double &_z);
68 
71  public: Vector3(const Vector3 &_v);
72 
74  public: virtual ~Vector3();
75 
78  public: double GetSum() const;
79 
83  public: double Distance(const Vector3 &_pt) const;
84 
90  public: double Distance(double _x, double _y, double _z) const;
91 
94  public: double GetLength() const;
95 
98  public: double GetSquaredLength() const;
99 
102  public: Vector3 Normalize();
103 
106  public: Vector3 Round();
107 
110  public: Vector3 GetRounded() const;
111 
116  public: inline void Set(double _x = 0, double _y = 0 , double _z = 0)
117  {
118  this->x = _x;
119  this->y = _y;
120  this->z = _z;
121  }
122 
125  public: Vector3 Cross(const Vector3 &_pt) const;
126 
129  public: double Dot(const Vector3 &_pt) const;
130 
133  public: Vector3 GetAbs() const;
134 
137  public: Vector3 GetPerpendicular() const;
138 
144  public: static Vector3 GetNormal(const Vector3 &_v1, const Vector3 &_v2,
145  const Vector3 &_v3);
146 
151  public: double GetDistToLine(const Vector3 &_pt1, const Vector3 &_pt2);
152 
156  public: void SetToMax(const Vector3 &_v);
157 
161  public: void SetToMin(const Vector3 &_v);
162 
165  public: double GetMax() const;
166 
169  public: double GetMin() const;
170 
174  public: Vector3 &operator =(const Vector3 &_v);
175 
179  public: Vector3 &operator =(double _value);
180 
184  public: Vector3 operator+(const Vector3 &_v) const;
185 
188  public: const Vector3 &operator+=(const Vector3 &_v);
189 
192  public: inline Vector3 operator-() const
193  {
194  return Vector3(-this->x, -this->y, -this->z);
195  }
196 
200  public: inline Vector3 operator-(const Vector3 &_pt) const
201  {
202  return Vector3(this->x - _pt.x,
203  this->y - _pt.y,
204  this->z - _pt.z);
205  }
206 
209  public: const Vector3 &operator-=(const Vector3 &_pt);
210 
215  public: const Vector3 operator/(const Vector3 &_pt) const;
216 
221  public: const Vector3 &operator/=(const Vector3 &_pt);
222 
226  public: const Vector3 operator/(double _v) const;
227 
231  public: const Vector3 &operator/=(double _v);
232 
236  public: Vector3 operator*(const Vector3 &_p) const;
237 
242  public: const Vector3 &operator*=(const Vector3 &_v);
243 
248  public: friend inline Vector3 operator*(double _s,
249  const Vector3 &_v)
250  { return Vector3(_v.x * _s, _v.y * _s, _v.z * _s); }
251 
255  public: Vector3 operator*(double _v) const;
256 
260  public: const Vector3 &operator*=(double _v);
261 
266  public: bool operator ==(const Vector3 &_pt) const;
267 
272  public: bool operator!=(const Vector3 &_v) const;
273 
275  public: bool IsFinite() const;
276 
278  public: inline void Correct()
279  {
280  if (!std::isfinite(this->x))
281  this->x = 0;
282  if (!std::isfinite(this->y))
283  this->y = 0;
284  if (!std::isfinite(this->z))
285  this->z = 0;
286  }
287 
289  public: double operator[](unsigned int index) const;
290 
293  public: void Round(int _precision);
294 
299  public: bool Equal(const Vector3 &_v) const;
300 
302  public: double x;
303 
305  public: double y;
306 
308  public: double z;
309 
314  public: friend std::ostream &operator<<(std::ostream &_out,
315  const gazebo::math::Vector3 &_pt)
316  {
317  _out << precision(_pt.x, 6) << " " << precision(_pt.y, 6) << " "
318  << precision(_pt.z, 6);
319  return _out;
320  }
321 
326  public: friend std::istream &operator>>(std::istream &_in,
328  {
329  // Skip white spaces
330  _in.setf(std::ios_base::skipws);
331  _in >> _pt.x >> _pt.y >> _pt.z;
332  return _in;
333  }
334  };
336  }
337 }
338 #endif
static const Vector3 UnitZ
math::Vector3(0, 0, 1)
Definition: Vector3.hh:58
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
friend std::istream & operator>>(std::istream &_in, gazebo::math::Vector3 &_pt)
Stream extraction operator.
Definition: Vector3.hh:326
double x
X location.
Definition: Vector3.hh:302
double z
Z location.
Definition: Vector3.hh:308
Vector3 operator-() const
Negation operator.
Definition: Vector3.hh:192
void Correct()
Corrects any nan values.
Definition: Vector3.hh:278
friend std::ostream & operator<<(std::ostream &_out, const gazebo::math::Vector3 &_pt)
Stream insertion operator.
Definition: Vector3.hh:314
static const Vector3 One
math::Vector3(1, 1, 1)
Definition: Vector3.hh:49
static const Vector3 UnitX
math::Vector3(1, 0, 0)
Definition: Vector3.hh:52
void Set(double _x=0, double _y=0, double _z=0)
Set the contents of the vector.
Definition: Vector3.hh:116
Vector3 operator-(const Vector3 &_pt) const
Subtraction operators.
Definition: Vector3.hh:200
static const Vector3 UnitY
math::Vector3(0, 1, 0)
Definition: Vector3.hh:55
static const Vector3 Zero
math::Vector3(0, 0, 0)
Definition: Vector3.hh:46
T precision(const T &_a, const unsigned int &_precision)
get value at a specified precision
Definition: Helpers.hh:179
friend Vector3 operator*(double _s, const Vector3 &_v)
Multiplication operators.
Definition: Vector3.hh:248
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
double y
Y location.
Definition: Vector3.hh:305