17#ifndef IGNITION_MATH_VECTOR4_HH_
18#define IGNITION_MATH_VECTOR4_HH_
22#include <ignition/math/config.hh>
28 inline namespace IGNITION_MATH_VERSION_NAMESPACE
44 this->data[0] = this->data[1] = this->data[2] = this->data[3] = 0;
52 public:
Vector4(
const T &_x,
const T &_y,
const T &_z,
const T &_w)
64 this->data[0] = _v[0];
65 this->data[1] = _v[1];
66 this->data[2] = _v[2];
67 this->data[3] = _v[3];
78 return sqrt((this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
79 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]) +
80 (this->data[2]-_pt[2])*(this->data[2]-_pt[2]) +
81 (this->data[3]-_pt[3])*(this->data[3]-_pt[3]));
95 return std::pow(this->data[0], 2)
96 + std::pow(this->data[1], 2)
97 + std::pow(this->data[2], 2)
98 + std::pow(this->data[3], 2);
106 if (!
equal<T>(d,
static_cast<T
>(0.0)))
120 public:
void Set(T _x = 0, T _y = 0, T _z = 0, T _w = 0)
133 this->data[0] = _v[0];
134 this->data[1] = _v[1];
135 this->data[2] = _v[2];
136 this->data[3] = _v[3];
145 this->data[0] = _value;
146 this->data[1] = _value;
147 this->data[2] = _value;
148 this->data[3] = _value;
159 this->data[1] + _v[1],
160 this->data[2] + _v[2],
161 this->data[3] + _v[3]);
169 this->data[0] += _v[0];
170 this->data[1] += _v[1];
171 this->data[2] += _v[2];
172 this->data[3] += _v[3];
215 return Vector4(-this->data[0], -this->data[1],
216 -this->data[2], -this->data[3]);
225 this->data[1] - _v[1],
226 this->data[2] - _v[2],
227 this->data[3] - _v[3]);
235 this->data[0] -= _v[0];
236 this->data[1] -= _v[1];
237 this->data[2] -= _v[2];
238 this->data[3] -= _v[3];
261 return {_s - _v.
X(), _s - _v.
Y(), _s - _v.
Z(), _s - _v.
W()};
285 this->data[1] / _v[1],
286 this->data[2] / _v[2],
287 this->data[3] / _v[3]);
297 this->data[0] /= _v[0];
298 this->data[1] /= _v[1];
299 this->data[2] /= _v[2];
300 this->data[3] /= _v[3];
312 return Vector4<T>(this->data[0] / _v, this->data[1] / _v,
313 this->data[2] / _v, this->data[3] / _v);
337 this->data[1] * _pt[1],
338 this->data[2] * _pt[2],
339 this->data[3] * _pt[3]);
348 this->data[0]*_m(0, 0) + this->data[1]*_m(1, 0) +
349 this->data[2]*_m(2, 0) + this->data[3]*_m(3, 0),
350 this->data[0]*_m(0, 1) + this->data[1]*_m(1, 1) +
351 this->data[2]*_m(2, 1) + this->data[3]*_m(3, 1),
352 this->data[0]*_m(0, 2) + this->data[1]*_m(1, 2) +
353 this->data[2]*_m(2, 2) + this->data[3]*_m(3, 2),
354 this->data[0]*_m(0, 3) + this->data[1]*_m(1, 3) +
355 this->data[2]*_m(2, 3) + this->data[3]*_m(3, 3));
365 this->data[0] *= _pt[0];
366 this->data[1] *= _pt[1];
367 this->data[2] *= _pt[2];
368 this->data[3] *= _pt[3];
378 return Vector4<T>(this->data[0] * _v, this->data[1] * _v,
379 this->data[2] * _v, this->data[3] * _v);
412 return equal<T>(this->data[0], _v[0], _tol)
413 &&
equal<T>(this->data[1], _v[1], _tol)
414 &&
equal<T>(this->data[2], _v[2], _tol)
415 &&
equal<T>(this->data[3], _v[3], _tol);
424 return this->
Equal(_v,
static_cast<T
>(1e-6));
433 return !(*
this == _pt);
442 return std::isfinite(
static_cast<double>(this->data[0])) &&
443 std::isfinite(
static_cast<double>(this->data[1])) &&
444 std::isfinite(
static_cast<double>(this->data[2])) &&
445 std::isfinite(
static_cast<double>(this->data[3]));
470 return this->data[0];
477 return this->data[1];
484 return this->data[2];
491 return this->data[3];
498 return this->data[0];
505 return this->data[1];
512 return this->data[2];
519 return this->data[3];
524 public:
inline void X(
const T &_v)
531 public:
inline void Y(
const T &_v)
538 public:
inline void Z(
const T &_v)
545 public:
inline void W(
const T &_v)
557 _out << _pt[0] <<
" " << _pt[1] <<
" " << _pt[2] <<
" " << _pt[3];
571 _in.setf(std::ios_base::skipws);
572 _in >> x >> y >> z >> w;
A 4x4 matrix class.
Definition Matrix4.hh:37
T Generic x, y, z, w vector.
Definition Vector4.hh:34
T SquaredLength() const
Return the square of the length (magnitude) of the vector.
Definition Vector4.hh:93
void Normalize()
Normalize the vector length.
Definition Vector4.hh:102
bool IsFinite() const
See if a point is finite (e.g., not nan)
Definition Vector4.hh:438
const Vector4< T > & operator/=(T _v)
Division operator.
Definition Vector4.hh:319
T W() const
Get the w value.
Definition Vector4.hh:517
Vector4< T > operator+(const T _s) const
Addition operators.
Definition Vector4.hh:180
const Vector4< T > & operator-=(const T _s)
Subtraction assignment operator.
Definition Vector4.hh:267
bool operator!=(const Vector4< T > &_pt) const
Not equal to operator.
Definition Vector4.hh:431
const Vector4< T > operator*(const Vector4< T > &_pt) const
Multiplication operator.
Definition Vector4.hh:334
Vector4(const Vector4< T > &_v)
Copy constructor.
Definition Vector4.hh:62
const Vector4< T > operator*(const Matrix4< T > &_m) const
Matrix multiplication operator.
Definition Vector4.hh:345
const Vector4< T > & operator/=(const Vector4< T > &_v)
Division assignment operator.
Definition Vector4.hh:295
T Z() const
Get the z value.
Definition Vector4.hh:510
T & operator[](const std::size_t _index)
Array subscript operator.
Definition Vector4.hh:452
T Y() const
Get the y value.
Definition Vector4.hh:503
Vector4()
Constructor.
Definition Vector4.hh:42
const Vector4< T > & operator+=(const T _s)
Addition assignment operator.
Definition Vector4.hh:201
bool operator==(const Vector4< T > &_v) const
Equal to operator.
Definition Vector4.hh:422
static const Vector4< T > One
math::Vector4(1, 1, 1, 1)
Definition Vector4.hh:39
const Vector4< T > operator/(const Vector4< T > &_v) const
Division assignment operator.
Definition Vector4.hh:282
void Z(const T &_v)
Set the z value.
Definition Vector4.hh:538
Vector4(const T &_x, const T &_y, const T &_z, const T &_w)
Constructor with component values.
Definition Vector4.hh:52
friend Vector4< T > operator-(const T _s, const Vector4< T > &_v)
Subtraction operators.
Definition Vector4.hh:258
void Set(T _x=0, T _y=0, T _z=0, T _w=0)
Set the contents of the vector.
Definition Vector4.hh:120
T operator[](const std::size_t _index) const
Const-qualified array subscript operator.
Definition Vector4.hh:461
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Vector4< T > &_pt)
Stream insertion operator.
Definition Vector4.hh:554
const Vector4< T > operator/(T _v) const
Division assignment operator.
Definition Vector4.hh:310
friend std::istream & operator>>(std::istream &_in, ignition::math::Vector4< T > &_pt)
Stream extraction operator.
Definition Vector4.hh:565
friend Vector4< T > operator+(const T _s, const Vector4< T > &_v)
Addition operators.
Definition Vector4.hh:192
bool Equal(const Vector4 &_v, const T &_tol) const
Equality test with tolerance.
Definition Vector4.hh:410
Vector4< T > & operator=(const Vector4< T > &_v)
Assignment operator.
Definition Vector4.hh:131
Vector4< T > operator-(const Vector4< T > &_v) const
Subtraction operator.
Definition Vector4.hh:222
T & X()
Return a mutable x value.
Definition Vector4.hh:468
T & Y()
Return a mutable y value.
Definition Vector4.hh:475
Vector4< T > operator-(const T _s) const
Subtraction operators.
Definition Vector4.hh:246
const Vector4< T > & operator+=(const Vector4< T > &_v)
Addition operator.
Definition Vector4.hh:167
virtual ~Vector4()
Destructor.
Definition Vector4.hh:71
T Distance(const Vector4< T > &_pt) const
Calc distance to the given point.
Definition Vector4.hh:76
Vector4< T > & operator=(T _value)
Assignment operator.
Definition Vector4.hh:143
T Length() const
Returns the length (magnitude) of the vector.
Definition Vector4.hh:86
T & W()
Return a mutable w value.
Definition Vector4.hh:489
void Y(const T &_v)
Set the y value.
Definition Vector4.hh:531
const Vector4< T > operator*(T _v) const
Multiplication operators.
Definition Vector4.hh:376
void X(const T &_v)
Set the x value.
Definition Vector4.hh:524
Vector4< T > operator+(const Vector4< T > &_v) const
Addition operator.
Definition Vector4.hh:156
T & Z()
Return a mutable z value.
Definition Vector4.hh:482
friend const Vector4 operator*(const T _s, const Vector4 &_v)
Scalar left multiplication operators.
Definition Vector4.hh:386
T X() const
Get the x value.
Definition Vector4.hh:496
static const Vector4< T > Zero
math::Vector4(0, 0, 0, 0)
Definition Vector4.hh:36
const Vector4< T > & operator*=(const Vector4< T > &_pt)
Multiplication assignment operator.
Definition Vector4.hh:363
Vector4 operator-() const
Negation operator.
Definition Vector4.hh:213
const Vector4< T > & operator-=(const Vector4< T > &_v)
Subtraction assigment operators.
Definition Vector4.hh:233
const Vector4< T > & operator*=(T _v)
Multiplication assignment operator.
Definition Vector4.hh:395
void W(const T &_v)
Set the w value.
Definition Vector4.hh:545
Vector4< int > Vector4i
Definition Vector4.hh:587
Vector4< double > Vector4d
Definition Vector4.hh:588
static const size_t IGN_THREE_SIZE_T
size_t type with a value of 3
Definition Helpers.hh:225
T clamp(T _v, T _min, T _max)
Simple clamping function.
Definition Helpers.hh:395
bool equal(const T &_a, const T &_b, const T &_epsilon=T(1e-6))
check if two values are equal, within a tolerance
Definition Helpers.hh:545
static const size_t IGN_ZERO_SIZE_T
size_t type with a value of 0
Definition Helpers.hh:216
Vector4< float > Vector4f
Definition Vector4.hh:589