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]));
84 this->data[0] * this->data[0] +
85 this->data[1] * this->data[1] +
86 this->data[2] * this->data[2] +
87 this->data[3] * this->data[3]);
94 return this->data[0] * this->data[0] + this->data[1] * this->data[1] +
95 this->data[2] * this->data[2] + this->data[3] * this->data[3];
114 public:
void Set(T _x = 0, T _y = 0, T _z = 0, T _w = 0)
127 this->data[0] = _v[0];
128 this->data[1] = _v[1];
129 this->data[2] = _v[2];
130 this->data[3] = _v[3];
139 this->data[0] = _value;
140 this->data[1] = _value;
141 this->data[2] = _value;
142 this->data[3] = _value;
153 this->data[1] + _v[1],
154 this->data[2] + _v[2],
155 this->data[3] + _v[3]);
163 this->data[0] += _v[0];
164 this->data[1] += _v[1];
165 this->data[2] += _v[2];
166 this->data[3] += _v[3];
177 this->data[1] - _v[1],
178 this->data[2] - _v[2],
179 this->data[3] - _v[3]);
187 this->data[0] -= _v[0];
188 this->data[1] -= _v[1];
189 this->data[2] -= _v[2];
190 this->data[3] -= _v[3];
203 this->data[1] / _v[1],
204 this->data[2] / _v[2],
205 this->data[3] / _v[3]);
215 this->data[0] /= _v[0];
216 this->data[1] /= _v[1];
217 this->data[2] /= _v[2];
218 this->data[3] /= _v[3];
230 return Vector4<T>(this->data[0] / _v, this->data[1] / _v,
231 this->data[2] / _v, this->data[3] / _v);
255 this->data[1] * _pt[1],
256 this->data[2] * _pt[2],
257 this->data[3] * _pt[3]);
266 this->data[0]*_m(0, 0) + this->data[1]*_m(1, 0) +
267 this->data[2]*_m(2, 0) + this->data[3]*_m(3, 0),
268 this->data[0]*_m(0, 1) + this->data[1]*_m(1, 1) +
269 this->data[2]*_m(2, 1) + this->data[3]*_m(3, 1),
270 this->data[0]*_m(0, 2) + this->data[1]*_m(1, 2) +
271 this->data[2]*_m(2, 2) + this->data[3]*_m(3, 2),
272 this->data[0]*_m(0, 3) + this->data[1]*_m(1, 3) +
273 this->data[2]*_m(2, 3) + this->data[3]*_m(3, 3));
283 this->data[0] *= _pt[0];
284 this->data[1] *= _pt[1];
285 this->data[2] *= _pt[2];
286 this->data[3] *= _pt[3];
296 return Vector4<T>(this->data[0] * _v, this->data[1] * _v,
297 this->data[2] * _v, this->data[3] * _v);
319 return equal(this->data[0], _v[0]) &&
equal(this->data[1], _v[1]) &&
320 equal(this->data[2], _v[2]) &&
equal(this->data[3], _v[3]);
329 return !(*
this == _pt);
338 return std::isfinite(static_cast<double>(this->data[0])) &&
339 std::isfinite(static_cast<double>(this->data[1])) &&
340 std::isfinite(static_cast<double>(this->data[2])) &&
341 std::isfinite(static_cast<double>(this->data[3]));
352 return this->data[_index];
357 public:
inline T
X()
const
359 return this->data[0];
364 public:
inline T
Y()
const
366 return this->data[1];
371 public:
inline T
Z()
const
373 return this->data[2];
378 public:
inline T
W()
const
380 return this->data[3];
385 public:
inline void X(
const T &_v)
392 public:
inline void Y(
const T &_v)
399 public:
inline void Z(
const T &_v)
406 public:
inline void W(
const T &_v)
418 _out << _pt[0] <<
" " << _pt[1] <<
" " << _pt[2] <<
" " << _pt[3];
432 _in.setf(std::ios_base::skipws);
433 _in >> x >> y >> z >> w;
Vector4< int > Vector4i
Definition: Vector4.hh:448
const Vector4< T > & operator-=(const Vector4< T > &_v)
Subtraction assigment operators.
Definition: Vector4.hh:185
const Vector4< T > operator*(const Vector4< T > &_pt) const
Multiplication operator.
Definition: Vector4.hh:252
Vector4< double > Vector4d
Definition: Vector4.hh:449
const Vector4< T > operator/(const Vector4< T > &_v) const
Division assignment operator.
Definition: Vector4.hh:200
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Vector4< T > &_pt)
Stream insertion operator.
Definition: Vector4.hh:415
Vector4< T > & operator=(const Vector4< T > &_v)
Assignment operator.
Definition: Vector4.hh:125
Vector4()
Constructor.
Definition: Vector4.hh:38
Vector4< T > & operator=(T _value)
Assignment operator.
Definition: Vector4.hh:137
void Z(const T &_v)
Set the z value.
Definition: Vector4.hh:399
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:263
A 4x4 matrix class.
Definition: Matrix4.hh:33
bool IsFinite() const
See if a point is finite (e.g., not nan)
Definition: Vector4.hh:334
T Y() const
Get the y value.
Definition: Vector4.hh:364
void Normalize()
Normalize the vector length.
Definition: Vector4.hh:99
virtual ~Vector4()
Destructor.
Definition: Vector4.hh:67
const Vector4< T > & operator*=(T _v)
Multiplication assignment operator.
Definition: Vector4.hh:303
void Set(T _x=0, T _y=0, T _z=0, T _w=0)
Set the contents of the vector.
Definition: Vector4.hh:114
bool operator!=(const Vector4< T > &_pt) const
Not equal to operator.
Definition: Vector4.hh:327
Vector4< T > operator-(const Vector4< T > &_v) const
Subtraction operator.
Definition: Vector4.hh:174
T W() const
Get the w value.
Definition: Vector4.hh:378
Vector4< float > Vector4f
Definition: Vector4.hh:450
void W(const T &_v)
Set the w value.
Definition: Vector4.hh:406
const Vector4< T > & operator*=(const Vector4< T > &_pt)
Multiplication assignment operator.
Definition: Vector4.hh:281
T Length() const
Returns the length (magnitude) of the vector.
Definition: Vector4.hh:81
T operator[](size_t _index) const
Array subscript operator.
Definition: Vector4.hh:348
const Vector4< T > & operator/=(const Vector4< T > &_v)
Division assignment operator.
Definition: Vector4.hh:213
Exception that is thrown when an out-of-bounds index is encountered.
Definition: IndexException.hh:30
void Y(const T &_v)
Set the y value.
Definition: Vector4.hh:392
const Vector4< T > & operator/=(T _v)
Division operator.
Definition: Vector4.hh:237
void X(const T &_v)
Set the x value.
Definition: Vector4.hh:385
static const Vector4< T > One
math::Vector3(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:294
T Z() const
Get the z value.
Definition: Vector4.hh:371
Vector4< T > operator+(const Vector4< T > &_v) const
Addition operator.
Definition: Vector4.hh:150
T X() const
Get the x value.
Definition: Vector4.hh:357
friend std::istream & operator>>(std::istream &_in, ignition::math::Vector4< T > &_pt)
Stream extraction operator.
Definition: Vector4.hh:426
bool equal(const T &_a, const T &_b, const T &_epsilon=1e-6)
check if two values are equal, within a tolerance
Definition: Helpers.hh:177
const Vector4< T > operator/(T _v) const
Division assignment operator.
Definition: Vector4.hh:228
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::Vector3(0, 0, 0)
Definition: Vector4.hh:32
T SquaredLength() const
Return the square of the length (magnitude) of the vector.
Definition: Vector4.hh:92
bool operator==(const Vector4< T > &_v) const
Equal to operator.
Definition: Vector4.hh:317
const Vector4< T > & operator+=(const Vector4< T > &_v)
Addition operator.
Definition: Vector4.hh:161