17 #ifndef _IGNITION_VECTOR3_HH_
18 #define _IGNITION_VECTOR3_HH_
66 public:
Vector3(
const T &_x,
const T &_y,
const T &_z)
77 this->data[0] = _v[0];
78 this->data[1] = _v[1];
79 this->data[2] = _v[2];
89 return this->data[0] + this->data[1] + this->data[2];
97 return sqrt((this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
98 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]) +
99 (this->data[2]-_pt[2])*(this->data[2]-_pt[2]));
123 return std::pow(this->data[0], 2)
124 + std::pow(this->data[1], 2)
125 + std::pow(this->data[2], 2);
134 if (!equal<T>(d, static_cast<T>(0.0)))
148 this->data[0] = nearbyint(this->data[0]);
149 this->data[1] = nearbyint(this->data[1]);
150 this->data[2] = nearbyint(this->data[2]);
167 public:
inline void Set(T _x = 0, T _y = 0, T _z = 0)
179 return Vector3(this->data[1] * _v[2] - this->data[2] * _v[1],
180 this->data[2] * _v[0] - this->data[0] * _v[2],
181 this->data[0] * _v[1] - this->data[1] * _v[0]);
189 return this->data[0] * _v[0] +
190 this->data[1] * _v[1] +
191 this->data[2] * _v[2];
204 return std::abs(this->data[0] * _v[0]) +
205 std::abs(this->data[1] * _v[1]) +
206 std::abs(this->data[2] * _v[2]);
213 return Vector3(std::abs(this->data[0]),
214 std::abs(this->data[1]),
215 std::abs(this->data[2]));
222 static const T sqrZero = 1e-06 * 1e-06;
255 T d = ((*this) - _pt1).
Cross((*
this) - _pt2).
Length();
256 d = d / (_pt2 - _pt1).
Length();
265 if (_v[0] > this->data[0])
266 this->data[0] = _v[0];
267 if (_v[1] > this->data[1])
268 this->data[1] = _v[1];
269 if (_v[2] > this->data[2])
270 this->data[2] = _v[2];
278 if (_v[0] < this->data[0])
279 this->data[0] = _v[0];
280 if (_v[1] < this->data[1])
281 this->data[1] = _v[1];
282 if (_v[2] < this->data[2])
283 this->data[2] = _v[2];
305 this->data[0] = _v[0];
306 this->data[1] = _v[1];
307 this->data[2] = _v[2];
329 return Vector3(this->data[0] + _v[0],
330 this->data[1] + _v[1],
331 this->data[2] + _v[2]);
339 this->data[0] += _v[0];
340 this->data[1] += _v[1];
341 this->data[2] += _v[2];
382 return Vector3(-this->data[0], -this->data[1], -this->data[2]);
390 return Vector3(this->data[0] - _pt[0],
391 this->data[1] - _pt[1],
392 this->data[2] - _pt[2]);
400 this->data[0] -= _pt[0];
401 this->data[1] -= _pt[1];
402 this->data[2] -= _pt[2];
445 return Vector3(this->data[0] / _pt[0],
446 this->data[1] / _pt[1],
447 this->data[2] / _pt[2]);
456 this->data[0] /= _pt[0];
457 this->data[1] /= _pt[1];
458 this->data[2] /= _pt[2];
469 return Vector3(this->data[0] / _v,
493 return Vector3(this->data[0] * _p[0],
494 this->data[1] * _p[1],
495 this->data[2] * _p[2]);
504 this->data[0] *= _v[0];
505 this->data[1] *= _v[1];
506 this->data[2] *= _v[2];
549 return equal<T>(this->data[0], _v[0], _tol)
550 && equal<T>(this->data[1], _v[1], _tol)
551 && equal<T>(this->data[2], _v[2], _tol);
560 return this->
Equal(_v, static_cast<T>(1e-3));
569 return !(*
this == _v);
578 return std::isfinite(static_cast<double>(this->data[0])) &&
579 std::isfinite(static_cast<double>(this->data[1])) &&
580 std::isfinite(static_cast<double>(this->data[2]));
588 if (!std::isfinite(static_cast<double>(this->data[0])))
590 if (!std::isfinite(static_cast<double>(this->data[1])))
592 if (!std::isfinite(static_cast<double>(this->data[2])))
605 return this->data[_index];
612 this->data[0] =
precision(this->data[0], _precision);
613 this->data[1] =
precision(this->data[1], _precision);
614 this->data[2] =
precision(this->data[2], _precision);
623 return equal<T>(this->data[0], _v[0]) &&
624 equal<T>(this->data[1], _v[1]) &&
625 equal<T>(this->data[2], _v[2]);
630 public:
inline T
X()
const
632 return this->data[0];
637 public:
inline T
Y()
const
639 return this->data[1];
644 public:
inline T
Z()
const
646 return this->data[2];
651 public:
inline T &
X()
653 return this->data[0];
658 public:
inline T &
Y()
660 return this->data[1];
665 public:
inline T &
Z()
667 return this->data[2];
672 public:
inline void X(
const T &_v)
679 public:
inline void Y(
const T &_v)
686 public:
inline void Z(
const T &_v)
695 public:
bool operator<(const Vector3<T> &_pt)
const
697 return this->data[0] < _pt[0] || this->data[1] < _pt[1] ||
698 this->data[2] < _pt[2];
721 _in.setf(std::ios_base::skipws);
static const Vector3 Zero
math::Vector3(0, 0, 0)
Definition: Vector3.hh:40
T & Y()
Get a mutable reference to the y value.
Definition: Vector3.hh:658
static const Vector3 UnitY
math::Vector3(0, 1, 0)
Definition: Vector3.hh:49
virtual ~Vector3()
Destructor.
Definition: Vector3.hh:83
T Length() const
Returns the length (magnitude) of the vector.
Definition: Vector3.hh:114
T AbsDot(const Vector3< T > &_v) const
Return the absolute dot product of this vector and another vector.
Definition: Vector3.hh:202
void Set(T _x=0, T _y=0, T _z=0)
Set the contents of the vector.
Definition: Vector3.hh:167
bool IsFinite() const
See if a point is finite (e.g., not nan)
Definition: Vector3.hh:574
T Sum() const
Return the sum of the values.
Definition: Vector3.hh:87
friend Vector3< T > operator-(const T _s, const Vector3< T > &_v)
Subtraction operators.
Definition: Vector3.hh:421
T precision(const T &_a, const unsigned int &_precision)
get value at a specified precision
Definition: Helpers.hh:269
Vector3 operator-() const
Negation operator.
Definition: Vector3.hh:380
T Distance(const Vector3< T > &_pt) const
Calc distance to the given point.
Definition: Vector3.hh:95
Vector3 operator+(const Vector3< T > &_v) const
Addition operator.
Definition: Vector3.hh:327
T max(const std::vector< T > &_values)
get the maximum value of vector of values
Definition: Helpers.hh:230
bool Equal(const Vector3< T > &_v) const
Equality test.
Definition: Vector3.hh:621
T & Z()
Get a mutable reference to the z value.
Definition: Vector3.hh:665
Vector3< double > Vector3d
Definition: Vector3.hh:739
Vector3()
Constructor.
Definition: Vector3.hh:55
const Vector3< T > & operator/=(T _v)
Division assignment operator.
Definition: Vector3.hh:478
T X() const
Get the x value.
Definition: Vector3.hh:630
void Correct()
Corrects any nan values.
Definition: Vector3.hh:584
Vector3 Abs() const
Get the absolute value of the vector.
Definition: Vector3.hh:211
void Z(const T &_v)
Set the z value.
Definition: Vector3.hh:686
Vector3 Normalize()
Normalize the vector length.
Definition: Vector3.hh:130
Vector3(const T &_x, const T &_y, const T &_z)
Constructor.
Definition: Vector3.hh:66
T Dot(const Vector3< T > &_v) const
Return the dot product of this vector and another vector.
Definition: Vector3.hh:187
bool operator==(const Vector3< T > &_v) const
Equal to operator.
Definition: Vector3.hh:558
Vector3 Perpendicular() const
Return a vector that is perpendicular to this one.
Definition: Vector3.hh:220
T operator[](size_t _index) const
Array subscript operator.
Definition: Vector3.hh:601
const Vector3< T > & operator/=(const Vector3< T > &_pt)
Division assignment operator.
Definition: Vector3.hh:454
Vector3 Cross(const Vector3< T > &_v) const
Return the cross product of this vector with another vector.
Definition: Vector3.hh:177
T & X()
Get a mutable reference to the x value.
Definition: Vector3.hh:651
T Y() const
Get the y value.
Definition: Vector3.hh:637
T Min() const
Get the minimum value in the vector.
Definition: Vector3.hh:295
void Round(int _precision)
Round all values to _precision decimal places.
Definition: Vector3.hh:610
Vector3 Rounded() const
Get a rounded version of this vector.
Definition: Vector3.hh:156
const Vector3< T > operator/(T _v) const
Division operator.
Definition: Vector3.hh:467
Vector3 & operator=(const Vector3< T > &_v)
Assignment operator.
Definition: Vector3.hh:303
static const Vector3 One
math::Vector3(1, 1, 1)
Definition: Vector3.hh:43
void Min(const Vector3< T > &_v)
Set this vector's components to the minimum of itself and the passed in vector.
Definition: Vector3.hh:276
const Vector3< T > & operator*=(const Vector3< T > &_v)
Multiplication assignment operators.
Definition: Vector3.hh:502
void Y(const T &_v)
Set the y value.
Definition: Vector3.hh:679
Vector3< T > operator+(const T _s) const
Addition operators.
Definition: Vector3.hh:349
friend Vector3< T > operator+(const T _s, const Vector3< T > &_v)
Addition operators.
Definition: Vector3.hh:360
Vector3< T > operator*(T _s) const
Multiplication operators.
Definition: Vector3.hh:514
const Vector3 & operator+=(const Vector3< T > &_v)
Addition assignment operator.
Definition: Vector3.hh:337
void Max(const Vector3< T > &_v)
Set this vector's components to the maximum of itself and the passed in vector.
Definition: Vector3.hh:263
T Z() const
Get the z value.
Definition: Vector3.hh:644
Exception that is thrown when an out-of-bounds index is encountered.
Definition: IndexException.hh:37
Vector3< float > Vector3f
Definition: Vector3.hh:740
const Vector3< T > & operator-=(const T _s)
Subtraction assignment operator.
Definition: Vector3.hh:430
T DistToLine(const Vector3< T > &_pt1, const Vector3 &_pt2)
Get distance to a line.
Definition: Vector3.hh:253
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:37
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Vector3< T > &_pt)
Stream insertion operator.
Definition: Vector3.hh:705
const Vector3< T > & operator+=(const T _s)
Addition assignment operator.
Definition: Vector3.hh:369
Vector3(const Vector3< T > &_v)
Copy constructor.
Definition: Vector3.hh:75
static Vector3 Normal(const Vector3< T > &_v1, const Vector3< T > &_v2, const Vector3< T > &_v3)
Get a normal vector to a triangle.
Definition: Vector3.hh:240
void X(const T &_v)
Set the x value.
Definition: Vector3.hh:672
T Distance(T _x, T _y, T _z) const
Calc distance to the given point.
Definition: Vector3.hh:107
bool Equal(const Vector3 &_v, const T &_tol) const
Equality test with tolerance.
Definition: Vector3.hh:547
const Vector3< T > & operator-=(const Vector3< T > &_pt)
Subtraction assignment operators.
Definition: Vector3.hh:398
Vector3< T > operator*(const Vector3< T > &_p) const
Multiplication operator.
Definition: Vector3.hh:491
T SquaredLength() const
Return the square of the length (magnitude) of the vector.
Definition: Vector3.hh:121
bool operator!=(const Vector3< T > &_v) const
Not equal to operator.
Definition: Vector3.hh:567
static const Vector3 UnitX
math::Vector3(1, 0, 0)
Definition: Vector3.hh:46
const Vector3< T > & operator*=(T _v)
Multiplication operator.
Definition: Vector3.hh:533
Vector3 Round()
Round to near whole number, return the result.
Definition: Vector3.hh:146
Definition: AffineException.hh:30
Vector3 & operator=(T _v)
Assignment operator.
Definition: Vector3.hh:315
Vector3< T > operator-(const T _s) const
Subtraction operators.
Definition: Vector3.hh:410
static const Vector3 UnitZ
math::Vector3(0, 0, 1)
Definition: Vector3.hh:52
Vector3< int > Vector3i
Definition: Vector3.hh:738
T min(const std::vector< T > &_values)
get the minimum value of vector of values
Definition: Helpers.hh:243
const Vector3< T > operator/(const Vector3< T > &_pt) const
Division operator.
Definition: Vector3.hh:443
T Max() const
Get the maximum value in the vector.
Definition: Vector3.hh:288
friend std::istream & operator>>(std::istream &_in, ignition::math::Vector3< T > &_pt)
Stream extraction operator.
Definition: Vector3.hh:717
friend Vector3< T > operator*(T _s, const Vector3< T > &_v)
Multiplication operators.
Definition: Vector3.hh:525
Vector3< T > operator-(const Vector3< T > &_pt) const
Subtraction operators.
Definition: Vector3.hh:388