17 #ifndef _IGNITION_VECTOR4_HH_ 18 #define _IGNITION_VECTOR4_HH_ 40 this->data[0] = this->data[1] = this->data[2] = this->data[3] = 0;
48 public:
Vector4(
const T &_x,
const T &_y,
const T &_z,
const T &_w)
60 this->data[0] = _v[0];
61 this->data[1] = _v[1];
62 this->data[2] = _v[2];
63 this->data[3] = _v[3];
74 return sqrt((this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
75 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]) +
76 (this->data[2]-_pt[2])*(this->data[2]-_pt[2]) +
77 (this->data[3]-_pt[3])*(this->data[3]-_pt[3]));
91 return std::pow(this->data[0], 2)
92 + std::pow(this->data[1], 2)
93 + std::pow(this->data[2], 2)
94 + std::pow(this->data[3], 2);
102 if (!equal<T>(d, static_cast<T>(0.0)))
116 public:
void Set(T _x = 0, T _y = 0, T _z = 0, T _w = 0)
129 this->data[0] = _v[0];
130 this->data[1] = _v[1];
131 this->data[2] = _v[2];
132 this->data[3] = _v[3];
141 this->data[0] = _value;
142 this->data[1] = _value;
143 this->data[2] = _value;
144 this->data[3] = _value;
155 this->data[1] + _v[1],
156 this->data[2] + _v[2],
157 this->data[3] + _v[3]);
165 this->data[0] += _v[0];
166 this->data[1] += _v[1];
167 this->data[2] += _v[2];
168 this->data[3] += _v[3];
211 return Vector4(-this->data[0], -this->data[1],
212 -this->data[2], -this->data[3]);
221 this->data[1] - _v[1],
222 this->data[2] - _v[2],
223 this->data[3] - _v[3]);
231 this->data[0] -= _v[0];
232 this->data[1] -= _v[1];
233 this->data[2] -= _v[2];
234 this->data[3] -= _v[3];
257 return Vector4<T>(_s - _v.
X(), _s - _v.
Y(), _s - _v.
Z(), _s - _v.
W());
281 this->data[1] / _v[1],
282 this->data[2] / _v[2],
283 this->data[3] / _v[3]);
293 this->data[0] /= _v[0];
294 this->data[1] /= _v[1];
295 this->data[2] /= _v[2];
296 this->data[3] /= _v[3];
308 return Vector4<T>(this->data[0] / _v, this->data[1] / _v,
309 this->data[2] / _v, this->data[3] / _v);
333 this->data[1] * _pt[1],
334 this->data[2] * _pt[2],
335 this->data[3] * _pt[3]);
344 this->data[0]*_m(0, 0) + this->data[1]*_m(1, 0) +
345 this->data[2]*_m(2, 0) + this->data[3]*_m(3, 0),
346 this->data[0]*_m(0, 1) + this->data[1]*_m(1, 1) +
347 this->data[2]*_m(2, 1) + this->data[3]*_m(3, 1),
348 this->data[0]*_m(0, 2) + this->data[1]*_m(1, 2) +
349 this->data[2]*_m(2, 2) + this->data[3]*_m(3, 2),
350 this->data[0]*_m(0, 3) + this->data[1]*_m(1, 3) +
351 this->data[2]*_m(2, 3) + this->data[3]*_m(3, 3));
361 this->data[0] *= _pt[0];
362 this->data[1] *= _pt[1];
363 this->data[2] *= _pt[2];
364 this->data[3] *= _pt[3];
374 return Vector4<T>(this->data[0] * _v, this->data[1] * _v,
375 this->data[2] * _v, this->data[3] * _v);
408 return equal<T>(this->data[0], _v[0], _tol)
409 && equal<T>(this->data[1], _v[1], _tol)
410 && equal<T>(this->data[2], _v[2], _tol)
411 && equal<T>(this->data[3], _v[3], _tol);
420 return this->
Equal(_v, static_cast<T>(1e-6));
429 return !(*
this == _pt);
438 return std::isfinite(static_cast<double>(this->data[0])) &&
439 std::isfinite(static_cast<double>(this->data[1])) &&
440 std::isfinite(static_cast<double>(this->data[2])) &&
441 std::isfinite(static_cast<double>(this->data[3]));
452 return this->data[_index];
457 public:
inline T
X()
const 459 return this->data[0];
464 public:
inline T
Y()
const 466 return this->data[1];
471 public:
inline T
Z()
const 473 return this->data[2];
478 public:
inline T
W()
const 480 return this->data[3];
485 public:
inline void X(
const T &_v)
492 public:
inline void Y(
const T &_v)
499 public:
inline void Z(
const T &_v)
506 public:
inline void W(
const T &_v)
518 _out << _pt[0] <<
" " << _pt[1] <<
" " << _pt[2] <<
" " << _pt[3];
532 _in.setf(std::ios_base::skipws);
533 _in >> x >> y >> z >> w;
friend Vector4< T > operator+(const T _s, const Vector4< T > &_v)
Addition operators.
Definition: Vector4.hh:188
Vector4< T > operator+(const T _s) const
Addition operators.
Definition: Vector4.hh:176
Vector4 operator-() const
Negation operator.
Definition: Vector4.hh:209
Vector4< int > Vector4i
Definition: Vector4.hh:548
const Vector4< T > & operator-=(const Vector4< T > &_v)
Subtraction assigment operators.
Definition: Vector4.hh:229
const Vector4< T > operator*(const Vector4< T > &_pt) const
Multiplication operator.
Definition: Vector4.hh:330
Vector4< double > Vector4d
Definition: Vector4.hh:549
bool Equal(const Vector4 &_v, const T &_tol) const
Equality test with tolerance.
Definition: Vector4.hh:406
const Vector4< T > operator/(const Vector4< T > &_v) const
Division assignment operator.
Definition: Vector4.hh:278
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Vector4< T > &_pt)
Stream insertion operator.
Definition: Vector4.hh:515
Vector4< T > & operator=(const Vector4< T > &_v)
Assignment operator.
Definition: Vector4.hh:127
Vector4()
Constructor.
Definition: Vector4.hh:38
friend const Vector4 operator*(const T _s, const Vector4 &_v)
Scalar left multiplication operators.
Definition: Vector4.hh:382
Vector4< T > & operator=(T _value)
Assignment operator.
Definition: Vector4.hh:139
void Z(const T &_v)
Set the z value.
Definition: Vector4.hh:499
const Vector4< T > & operator-=(const T _s)
Subtraction assignment operator.
Definition: Vector4.hh:263
Vector4(const Vector4< T > &_v)
Copy constructor.
Definition: Vector4.hh:58
const Vector4< T > operator*(const Matrix4< T > &_m) const
Matrix multiplication operator.
Definition: Vector4.hh:341
A 4x4 matrix class.
Definition: Matrix4.hh:34
bool IsFinite() const
See if a point is finite (e.g., not nan)
Definition: Vector4.hh:434
T Y() const
Get the y value.
Definition: Vector4.hh:464
void Normalize()
Normalize the vector length.
Definition: Vector4.hh:98
virtual ~Vector4()
Destructor.
Definition: Vector4.hh:67
const Vector4< T > & operator*=(T _v)
Multiplication assignment operator.
Definition: Vector4.hh:391
void Set(T _x=0, T _y=0, T _z=0, T _w=0)
Set the contents of the vector.
Definition: Vector4.hh:116
bool operator!=(const Vector4< T > &_pt) const
Not equal to operator.
Definition: Vector4.hh:427
Vector4< T > operator-(const Vector4< T > &_v) const
Subtraction operator.
Definition: Vector4.hh:218
T W() const
Get the w value.
Definition: Vector4.hh:478
Vector4< float > Vector4f
Definition: Vector4.hh:550
void W(const T &_v)
Set the w value.
Definition: Vector4.hh:506
const Vector4< T > & operator+=(const T _s)
Addition assignment operator.
Definition: Vector4.hh:197
const Vector4< T > & operator*=(const Vector4< T > &_pt)
Multiplication assignment operator.
Definition: Vector4.hh:359
T Length() const
Returns the length (magnitude) of the vector.
Definition: Vector4.hh:82
T operator[](size_t _index) const
Array subscript operator.
Definition: Vector4.hh:448
const Vector4< T > & operator/=(const Vector4< T > &_v)
Division assignment operator.
Definition: Vector4.hh:291
Exception that is thrown when an out-of-bounds index is encountered.
Definition: IndexException.hh:37
void Y(const T &_v)
Set the y value.
Definition: Vector4.hh:492
const Vector4< T > & operator/=(T _v)
Division operator.
Definition: Vector4.hh:315
void X(const T &_v)
Set the x value.
Definition: Vector4.hh:485
static const Vector4< T > One
math::Vector4(1, 1, 1, 1)
Definition: Vector4.hh:35
Vector4(const T &_x, const T &_y, const T &_z, const T &_w)
Constructor with component values.
Definition: Vector4.hh:48
const Vector4< T > operator*(T _v) const
Multiplication operators.
Definition: Vector4.hh:372
T Z() const
Get the z value.
Definition: Vector4.hh:471
Vector4< T > operator+(const Vector4< T > &_v) const
Addition operator.
Definition: Vector4.hh:152
T X() const
Get the x value.
Definition: Vector4.hh:457
Vector4< T > operator-(const T _s) const
Subtraction operators.
Definition: Vector4.hh:242
Definition: AffineException.hh:30
friend std::istream & operator>>(std::istream &_in, ignition::math::Vector4< T > &_pt)
Stream extraction operator.
Definition: Vector4.hh:526
friend Vector4< T > operator-(const T _s, const Vector4< T > &_v)
Subtraction operators.
Definition: Vector4.hh:254
const Vector4< T > operator/(T _v) const
Division assignment operator.
Definition: Vector4.hh:306
T Distance(const Vector4< T > &_pt) const
Calc distance to the given point.
Definition: Vector4.hh:72
T Generic x, y, z, w vector.
Definition: Vector4.hh:29
static const Vector4< T > Zero
math::Vector4(0, 0, 0, 0)
Definition: Vector4.hh:32
T SquaredLength() const
Return the square of the length (magnitude) of the vector.
Definition: Vector4.hh:89
bool operator==(const Vector4< T > &_v) const
Equal to operator.
Definition: Vector4.hh:418
const Vector4< T > & operator+=(const Vector4< T > &_v)
Addition operator.
Definition: Vector4.hh:163