17 #ifndef IGNITION_MATH_VECTOR4_HH_ 18 #define IGNITION_MATH_VECTOR4_HH_ 41 this->data[0] = this->data[1] = this->data[2] = this->data[3] = 0;
49 public:
Vector4(
const T &_x,
const T &_y,
const T &_z,
const T &_w)
61 this->data[0] = _v[0];
62 this->data[1] = _v[1];
63 this->data[2] = _v[2];
64 this->data[3] = _v[3];
75 return sqrt((this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
76 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]) +
77 (this->data[2]-_pt[2])*(this->data[2]-_pt[2]) +
78 (this->data[3]-_pt[3])*(this->data[3]-_pt[3]));
92 return std::pow(this->data[0], 2)
93 + std::pow(this->data[1], 2)
94 + std::pow(this->data[2], 2)
95 + std::pow(this->data[3], 2);
103 if (!equal<T>(d, static_cast<T>(0.0)))
117 public:
void Set(T _x = 0, T _y = 0, T _z = 0, T _w = 0)
130 this->data[0] = _v[0];
131 this->data[1] = _v[1];
132 this->data[2] = _v[2];
133 this->data[3] = _v[3];
142 this->data[0] = _value;
143 this->data[1] = _value;
144 this->data[2] = _value;
145 this->data[3] = _value;
156 this->data[1] + _v[1],
157 this->data[2] + _v[2],
158 this->data[3] + _v[3]);
166 this->data[0] += _v[0];
167 this->data[1] += _v[1];
168 this->data[2] += _v[2];
169 this->data[3] += _v[3];
212 return Vector4(-this->data[0], -this->data[1],
213 -this->data[2], -this->data[3]);
222 this->data[1] - _v[1],
223 this->data[2] - _v[2],
224 this->data[3] - _v[3]);
232 this->data[0] -= _v[0];
233 this->data[1] -= _v[1];
234 this->data[2] -= _v[2];
235 this->data[3] -= _v[3];
258 return Vector4<T>(_s - _v.
X(), _s - _v.
Y(), _s - _v.
Z(), _s - _v.
W());
282 this->data[1] / _v[1],
283 this->data[2] / _v[2],
284 this->data[3] / _v[3]);
294 this->data[0] /= _v[0];
295 this->data[1] /= _v[1];
296 this->data[2] /= _v[2];
297 this->data[3] /= _v[3];
309 return Vector4<T>(this->data[0] / _v, this->data[1] / _v,
310 this->data[2] / _v, this->data[3] / _v);
334 this->data[1] * _pt[1],
335 this->data[2] * _pt[2],
336 this->data[3] * _pt[3]);
345 this->data[0]*_m(0, 0) + this->data[1]*_m(1, 0) +
346 this->data[2]*_m(2, 0) + this->data[3]*_m(3, 0),
347 this->data[0]*_m(0, 1) + this->data[1]*_m(1, 1) +
348 this->data[2]*_m(2, 1) + this->data[3]*_m(3, 1),
349 this->data[0]*_m(0, 2) + this->data[1]*_m(1, 2) +
350 this->data[2]*_m(2, 2) + this->data[3]*_m(3, 2),
351 this->data[0]*_m(0, 3) + this->data[1]*_m(1, 3) +
352 this->data[2]*_m(2, 3) + this->data[3]*_m(3, 3));
362 this->data[0] *= _pt[0];
363 this->data[1] *= _pt[1];
364 this->data[2] *= _pt[2];
365 this->data[3] *= _pt[3];
375 return Vector4<T>(this->data[0] * _v, this->data[1] * _v,
376 this->data[2] * _v, this->data[3] * _v);
409 return equal<T>(this->data[0], _v[0], _tol)
410 && equal<T>(this->data[1], _v[1], _tol)
411 && equal<T>(this->data[2], _v[2], _tol)
412 && equal<T>(this->data[3], _v[3], _tol);
421 return this->
Equal(_v, static_cast<T>(1e-6));
430 return !(*
this == _pt);
439 return std::isfinite(static_cast<double>(this->data[0])) &&
440 std::isfinite(static_cast<double>(this->data[1])) &&
441 std::isfinite(static_cast<double>(this->data[2])) &&
442 std::isfinite(static_cast<double>(this->data[3]));
455 public:
inline T
X()
const 457 return this->data[0];
462 public:
inline T
Y()
const 464 return this->data[1];
469 public:
inline T
Z()
const 471 return this->data[2];
476 public:
inline T
W()
const 478 return this->data[3];
483 public:
inline void X(
const T &_v)
490 public:
inline void Y(
const T &_v)
497 public:
inline void Z(
const T &_v)
504 public:
inline void W(
const T &_v)
516 _out << _pt[0] <<
" " << _pt[1] <<
" " << _pt[2] <<
" " << _pt[3];
530 _in.setf(std::ios_base::skipws);
531 _in >> x >> y >> z >> w;
const Vector4< T > operator*(const Matrix4< T > &_m) const
Matrix multiplication operator.
Definition: Vector4.hh:342
friend Vector4< T > operator+(const T _s, const Vector4< T > &_v)
Addition operators.
Definition: Vector4.hh:189
Vector4 operator-() const
Negation operator.
Definition: Vector4.hh:210
T operator[](const size_t _index) const
Array subscript operator.
Definition: Vector4.hh:448
bool Equal(const Vector4 &_v, const T &_tol) const
Equality test with tolerance.
Definition: Vector4.hh:407
Vector4< int > Vector4i
Definition: Vector4.hh:546
Vector4< T > operator-(const Vector4< T > &_v) const
Subtraction operator.
Definition: Vector4.hh:219
const Vector4< T > & operator-=(const Vector4< T > &_v)
Subtraction assigment operators.
Definition: Vector4.hh:230
T X() const
Get the x value.
Definition: Vector4.hh:455
Vector4< double > Vector4d
Definition: Vector4.hh:547
T Y() const
Get the y value.
Definition: Vector4.hh:462
static const size_t IGN_THREE_SIZE_T
size_t type with a value of 3
Definition: Helpers.hh:222
static const size_t IGN_ZERO_SIZE_T
size_t type with a value of 0
Definition: Helpers.hh:213
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Vector4< T > &_pt)
Stream insertion operator.
Definition: Vector4.hh:513
const Vector4< T > operator*(const Vector4< T > &_pt) const
Multiplication operator.
Definition: Vector4.hh:331
Vector4< T > & operator=(const Vector4< T > &_v)
Assignment operator.
Definition: Vector4.hh:128
Vector4()
Constructor.
Definition: Vector4.hh:39
friend const Vector4 operator*(const T _s, const Vector4 &_v)
Scalar left multiplication operators.
Definition: Vector4.hh:383
Vector4< T > & operator=(T _value)
Assignment operator.
Definition: Vector4.hh:140
void Z(const T &_v)
Set the z value.
Definition: Vector4.hh:497
const Vector4< T > & operator-=(const T _s)
Subtraction assignment operator.
Definition: Vector4.hh:264
const Vector4< T > operator/(const Vector4< T > &_v) const
Division assignment operator.
Definition: Vector4.hh:279
T Z() const
Get the z value.
Definition: Vector4.hh:469
Vector4(const Vector4< T > &_v)
Copy constructor.
Definition: Vector4.hh:59
Vector4< T > operator+(const Vector4< T > &_v) const
Addition operator.
Definition: Vector4.hh:153
A 4x4 matrix class.
Definition: Matrix4.hh:33
Vector4< T > operator+(const T _s) const
Addition operators.
Definition: Vector4.hh:177
T SquaredLength() const
Return the square of the length (magnitude) of the vector.
Definition: Vector4.hh:90
T Distance(const Vector4< T > &_pt) const
Calc distance to the given point.
Definition: Vector4.hh:73
void Normalize()
Normalize the vector length.
Definition: Vector4.hh:99
virtual ~Vector4()
Destructor.
Definition: Vector4.hh:68
const Vector4< T > operator/(T _v) const
Division assignment operator.
Definition: Vector4.hh:307
const Vector4< T > & operator*=(T _v)
Multiplication assignment operator.
Definition: Vector4.hh:392
bool operator!=(const Vector4< T > &_pt) const
Not equal to operator.
Definition: Vector4.hh:428
bool operator==(const Vector4< T > &_v) const
Equal to operator.
Definition: Vector4.hh:419
void Set(T _x=0, T _y=0, T _z=0, T _w=0)
Set the contents of the vector.
Definition: Vector4.hh:117
bool IsFinite() const
See if a point is finite (e.g., not nan)
Definition: Vector4.hh:435
const Vector4< T > operator*(T _v) const
Multiplication operators.
Definition: Vector4.hh:373
T Length() const
Returns the length (magnitude) of the vector.
Definition: Vector4.hh:83
Vector4< float > Vector4f
Definition: Vector4.hh:548
void W(const T &_v)
Set the w value.
Definition: Vector4.hh:504
const Vector4< T > & operator+=(const T _s)
Addition assignment operator.
Definition: Vector4.hh:198
const Vector4< T > & operator*=(const Vector4< T > &_pt)
Multiplication assignment operator.
Definition: Vector4.hh:360
const Vector4< T > & operator/=(const Vector4< T > &_v)
Division assignment operator.
Definition: Vector4.hh:292
void Y(const T &_v)
Set the y value.
Definition: Vector4.hh:490
const Vector4< T > & operator/=(T _v)
Division operator.
Definition: Vector4.hh:316
T W() const
Get the w value.
Definition: Vector4.hh:476
void X(const T &_v)
Set the x value.
Definition: Vector4.hh:483
static const Vector4< T > One
math::Vector4(1, 1, 1, 1)
Definition: Vector4.hh:36
Vector4(const T &_x, const T &_y, const T &_z, const T &_w)
Constructor with component values.
Definition: Vector4.hh:49
Vector4< T > operator-(const T _s) const
Subtraction operators.
Definition: Vector4.hh:243
friend std::istream & operator>>(std::istream &_in, ignition::math::Vector4< T > &_pt)
Stream extraction operator.
Definition: Vector4.hh:524
friend Vector4< T > operator-(const T _s, const Vector4< T > &_v)
Subtraction operators.
Definition: Vector4.hh:255
T Generic x, y, z, w vector.
Definition: Vector4.hh:30
static const Vector4< T > Zero
math::Vector4(0, 0, 0, 0)
Definition: Vector4.hh:33
T clamp(T _v, T _min, T _max)
Simple clamping function.
Definition: Helpers.hh:392
const Vector4< T > & operator+=(const Vector4< T > &_v)
Addition operator.
Definition: Vector4.hh:164