17 #ifndef IGNITION_MATH_VECTOR3_HH_ 18 #define IGNITION_MATH_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)))
157 this->data[0] = nearbyint(this->data[0]);
158 this->data[1] = nearbyint(this->data[1]);
159 this->data[2] = nearbyint(this->data[2]);
176 public:
inline void Set(T _x = 0, T _y = 0, T _z = 0)
188 return Vector3(this->data[1] * _v[2] - this->data[2] * _v[1],
189 this->data[2] * _v[0] - this->data[0] * _v[2],
190 this->data[0] * _v[1] - this->data[1] * _v[0]);
198 return this->data[0] * _v[0] +
199 this->data[1] * _v[1] +
200 this->data[2] * _v[2];
213 return std::abs(this->data[0] * _v[0]) +
214 std::abs(this->data[1] * _v[1]) +
215 std::abs(this->data[2] * _v[2]);
222 return Vector3(std::abs(this->data[0]),
223 std::abs(this->data[1]),
224 std::abs(this->data[2]));
231 static const T sqrZero = 1e-06 * 1e-06;
264 T d = ((*this) - _pt1).
Cross((*
this) - _pt2).
Length();
265 d = d / (_pt2 - _pt1).
Length();
274 if (_v[0] > this->data[0])
275 this->data[0] = _v[0];
276 if (_v[1] > this->data[1])
277 this->data[1] = _v[1];
278 if (_v[2] > this->data[2])
279 this->data[2] = _v[2];
287 if (_v[0] < this->data[0])
288 this->data[0] = _v[0];
289 if (_v[1] < this->data[1])
290 this->data[1] = _v[1];
291 if (_v[2] < this->data[2])
292 this->data[2] = _v[2];
314 this->data[0] = _v[0];
315 this->data[1] = _v[1];
316 this->data[2] = _v[2];
338 return Vector3(this->data[0] + _v[0],
339 this->data[1] + _v[1],
340 this->data[2] + _v[2]);
348 this->data[0] += _v[0];
349 this->data[1] += _v[1];
350 this->data[2] += _v[2];
391 return Vector3(-this->data[0], -this->data[1], -this->data[2]);
399 return Vector3(this->data[0] - _pt[0],
400 this->data[1] - _pt[1],
401 this->data[2] - _pt[2]);
409 this->data[0] -= _pt[0];
410 this->data[1] -= _pt[1];
411 this->data[2] -= _pt[2];
454 return Vector3(this->data[0] / _pt[0],
455 this->data[1] / _pt[1],
456 this->data[2] / _pt[2]);
465 this->data[0] /= _pt[0];
466 this->data[1] /= _pt[1];
467 this->data[2] /= _pt[2];
478 return Vector3(this->data[0] / _v,
502 return Vector3(this->data[0] * _p[0],
503 this->data[1] * _p[1],
504 this->data[2] * _p[2]);
513 this->data[0] *= _v[0];
514 this->data[1] *= _v[1];
515 this->data[2] *= _v[2];
558 return equal<T>(this->data[0], _v[0], _tol)
559 && equal<T>(this->data[1], _v[1], _tol)
560 && equal<T>(this->data[2], _v[2], _tol);
569 return this->
Equal(_v, static_cast<T>(1e-3));
578 return !(*
this == _v);
587 return std::isfinite(static_cast<double>(this->data[0])) &&
588 std::isfinite(static_cast<double>(this->data[1])) &&
589 std::isfinite(static_cast<double>(this->data[2]));
597 if (!std::isfinite(static_cast<double>(this->data[0])))
599 if (!std::isfinite(static_cast<double>(this->data[1])))
601 if (!std::isfinite(static_cast<double>(this->data[2])))
614 return this->data[_index];
621 this->data[0] =
precision(this->data[0], _precision);
622 this->data[1] =
precision(this->data[1], _precision);
623 this->data[2] =
precision(this->data[2], _precision);
632 return equal<T>(this->data[0], _v[0]) &&
633 equal<T>(this->data[1], _v[1]) &&
634 equal<T>(this->data[2], _v[2]);
639 public:
inline T
X()
const 641 return this->data[0];
646 public:
inline T
Y()
const 648 return this->data[1];
653 public:
inline T
Z()
const 655 return this->data[2];
660 public:
inline T &
X()
662 return this->data[0];
667 public:
inline T &
Y()
669 return this->data[1];
674 public:
inline T &
Z()
676 return this->data[2];
681 public:
inline void X(
const T &_v)
688 public:
inline void Y(
const T &_v)
695 public:
inline void Z(
const T &_v)
720 _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:667
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:211
void Set(T _x=0, T _y=0, T _z=0)
Set the contents of the vector.
Definition: Vector3.hh:176
bool IsFinite() const
See if a point is finite (e.g., not nan)
Definition: Vector3.hh:583
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:430
T precision(const T &_a, const unsigned int &_precision)
get value at a specified precision
Definition: Helpers.hh:363
Vector3 operator-() const
Negation operator.
Definition: Vector3.hh:389
T Distance(const Vector3< T > &_pt) const
Calc distance to the given point.
Definition: Vector3.hh:95
Vector3 Normalized() const
Return a normalized vector.
Definition: Vector3.hh:146
Vector3 operator+(const Vector3< T > &_v) const
Addition operator.
Definition: Vector3.hh:336
T max(const std::vector< T > &_values)
get the maximum value of vector of values
Definition: Helpers.hh:324
bool Equal(const Vector3< T > &_v) const
Equality test.
Definition: Vector3.hh:630
T & Z()
Get a mutable reference to the z value.
Definition: Vector3.hh:674
Vector3< double > Vector3d
Definition: Vector3.hh:738
Vector3()
Constructor.
Definition: Vector3.hh:55
const Vector3< T > & operator/=(T _v)
Division assignment operator.
Definition: Vector3.hh:487
T X() const
Get the x value.
Definition: Vector3.hh:639
void Correct()
Corrects any nan values.
Definition: Vector3.hh:593
Vector3 Abs() const
Get the absolute value of the vector.
Definition: Vector3.hh:220
void Z(const T &_v)
Set the z value.
Definition: Vector3.hh:695
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:196
bool operator==(const Vector3< T > &_v) const
Equal to operator.
Definition: Vector3.hh:567
Vector3 Perpendicular() const
Return a vector that is perpendicular to this one.
Definition: Vector3.hh:229
T operator[](size_t _index) const
Array subscript operator.
Definition: Vector3.hh:610
const Vector3< T > & operator/=(const Vector3< T > &_pt)
Division assignment operator.
Definition: Vector3.hh:463
Vector3 Cross(const Vector3< T > &_v) const
Return the cross product of this vector with another vector.
Definition: Vector3.hh:186
T & X()
Get a mutable reference to the x value.
Definition: Vector3.hh:660
T Y() const
Get the y value.
Definition: Vector3.hh:646
T Min() const
Get the minimum value in the vector.
Definition: Vector3.hh:304
void Round(int _precision)
Round all values to _precision decimal places.
Definition: Vector3.hh:619
Vector3 Rounded() const
Get a rounded version of this vector.
Definition: Vector3.hh:165
const Vector3< T > operator/(T _v) const
Division operator.
Definition: Vector3.hh:476
Vector3 & operator=(const Vector3< T > &_v)
Assignment operator.
Definition: Vector3.hh:312
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:285
const Vector3< T > & operator*=(const Vector3< T > &_v)
Multiplication assignment operators.
Definition: Vector3.hh:511
void Y(const T &_v)
Set the y value.
Definition: Vector3.hh:688
Vector3< T > operator+(const T _s) const
Addition operators.
Definition: Vector3.hh:358
friend Vector3< T > operator+(const T _s, const Vector3< T > &_v)
Addition operators.
Definition: Vector3.hh:369
Vector3< T > operator*(T _s) const
Multiplication operators.
Definition: Vector3.hh:523
const Vector3 & operator+=(const Vector3< T > &_v)
Addition assignment operator.
Definition: Vector3.hh:346
void Max(const Vector3< T > &_v)
Set this vector's components to the maximum of itself and the passed in vector.
Definition: Vector3.hh:272
T Z() const
Get the z value.
Definition: Vector3.hh:653
Exception that is thrown when an out-of-bounds index is encountered.
Definition: IndexException.hh:37
Vector3< float > Vector3f
Definition: Vector3.hh:739
const Vector3< T > & operator-=(const T _s)
Subtraction assignment operator.
Definition: Vector3.hh:439
T DistToLine(const Vector3< T > &_pt1, const Vector3 &_pt2)
Get distance to a line.
Definition: Vector3.hh:262
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:704
const Vector3< T > & operator+=(const T _s)
Addition assignment operator.
Definition: Vector3.hh:378
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:249
void X(const T &_v)
Set the x value.
Definition: Vector3.hh:681
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:556
const Vector3< T > & operator-=(const Vector3< T > &_pt)
Subtraction assignment operators.
Definition: Vector3.hh:407
Vector3< T > operator*(const Vector3< T > &_p) const
Multiplication operator.
Definition: Vector3.hh:500
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:576
static const Vector3 UnitX
math::Vector3(1, 0, 0)
Definition: Vector3.hh:46
const Vector3< T > & operator*=(T _v)
Multiplication operator.
Definition: Vector3.hh:542
Vector3 Round()
Round to near whole number, return the result.
Definition: Vector3.hh:155
Definition: AffineException.hh:30
Vector3 & operator=(T _v)
Assignment operator.
Definition: Vector3.hh:324
Vector3< T > operator-(const T _s) const
Subtraction operators.
Definition: Vector3.hh:419
static const Vector3 UnitZ
math::Vector3(0, 0, 1)
Definition: Vector3.hh:52
Vector3< int > Vector3i
Definition: Vector3.hh:737
T min(const std::vector< T > &_values)
get the minimum value of vector of values
Definition: Helpers.hh:337
const Vector3< T > operator/(const Vector3< T > &_pt) const
Division operator.
Definition: Vector3.hh:452
T Max() const
Get the maximum value in the vector.
Definition: Vector3.hh:297
friend std::istream & operator>>(std::istream &_in, ignition::math::Vector3< T > &_pt)
Stream extraction operator.
Definition: Vector3.hh:716
friend Vector3< T > operator*(T _s, const Vector3< T > &_v)
Multiplication operators.
Definition: Vector3.hh:534
Vector3< T > operator-(const Vector3< T > &_pt) const
Subtraction operators.
Definition: Vector3.hh:397