All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Matrix4.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _IGNITION_MATRIX4_HH_
18 #define _IGNITION_MATRIX4_HH_
19 
20 #include <ignition/math/Helpers.hh>
22 #include <ignition/math/Matrix3.hh>
23 #include <ignition/math/Vector3.hh>
24 #include <ignition/math/Pose3.hh>
25 
26 namespace ignition
27 {
28  namespace math
29  {
32  template<typename T>
33  class Matrix4
34  {
36  public: static const Matrix4<T> Identity;
37 
39  public: static const Matrix4<T> Zero;
40 
42  public: Matrix4()
43  {
44  memset(this->data, 0, sizeof(this->data[0][0])*16);
45  }
46 
49  public: Matrix4(const Matrix4<T> &_m)
50  {
51  memcpy(this->data, _m.data, sizeof(this->data[0][0])*16);
52  }
53 
71  public: Matrix4(T _v00, T _v01, T _v02, T _v03,
72  T _v10, T _v11, T _v12, T _v13,
73  T _v20, T _v21, T _v22, T _v23,
74  T _v30, T _v31, T _v32, T _v33)
75  {
76  this->Set(_v00, _v01, _v02, _v03,
77  _v10, _v11, _v12, _v13,
78  _v20, _v21, _v22, _v23,
79  _v30, _v31, _v32, _v33);
80  }
81 
84  public: Matrix4(const Quaternion<T> &_q)
85  {
86  Quaternion<T> qt = _q;
87  qt.Normalize();
88  this->Set(1 - 2*qt.Y()*qt.Y() - 2 *qt.Z()*qt.Z(),
89  2 * qt.X()*qt.Y() - 2*qt.Z()*qt.W(),
90  2 * qt.X() * qt.Z() + 2 * qt.Y() * qt.W(),
91  0,
92 
93  2 * qt.X() * qt.Y() + 2 * qt.Z() * qt.W(),
94  1 - 2*qt.X()*qt.X() - 2 * qt.Z()*qt.Z(),
95  2 * qt.Y() * qt.Z() - 2 * qt.X() * qt.W(),
96  0,
97 
98  2 * qt.X() * qt.Z() - 2 * qt.Y() * qt.W(),
99  2 * qt.Y() * qt.Z() + 2 * qt.X() * qt.W(),
100  1 - 2 * qt.X()*qt.X() - 2 * qt.Y()*qt.Y(),
101  0,
102 
103  0, 0, 0, 1);
104  }
105 
107  public: virtual ~Matrix4() {}
108 
126  public: void Set(
127  T _v00, T _v01, T _v02, T _v03,
128  T _v10, T _v11, T _v12, T _v13,
129  T _v20, T _v21, T _v22, T _v23,
130  T _v30, T _v31, T _v32, T _v33)
131  {
132  this->data[0][0] = _v00;
133  this->data[0][1] = _v01;
134  this->data[0][2] = _v02;
135  this->data[0][3] = _v03;
136 
137  this->data[1][0] = _v10;
138  this->data[1][1] = _v11;
139  this->data[1][2] = _v12;
140  this->data[1][3] = _v13;
141 
142  this->data[2][0] = _v20;
143  this->data[2][1] = _v21;
144  this->data[2][2] = _v22;
145  this->data[2][3] = _v23;
146 
147  this->data[3][0] = _v30;
148  this->data[3][1] = _v31;
149  this->data[3][2] = _v32;
150  this->data[3][3] = _v33;
151  }
152 
156  public: void Axis(const Vector3<T> &_axis, T _angle)
157  {
158  T c = cos(_angle);
159  T s = sin(_angle);
160  T C = 1-c;
161 
162  this->data[0][0] = _axis.X()*_axis.X()*C + c;
163  this->data[0][1] = _axis.X()*_axis.Y()*C - _axis.Z()*s;
164  this->data[0][2] = _axis.X()*_axis.Z()*C + _axis.Y()*s;
165 
166  this->data[1][0] = _axis.Y()*_axis.X()*C + _axis.Z()*s;
167  this->data[1][1] = _axis.Y()*_axis.Y()*C + c;
168  this->data[1][2] = _axis.Y()*_axis.Z()*C - _axis.X()*s;
169 
170  this->data[2][0] = _axis.Z()*_axis.X()*C - _axis.Y()*s;
171  this->data[2][1] = _axis.Z()*_axis.Y()*C + _axis.X()*s;
172  this->data[2][2] = _axis.Z()*_axis.Z()*C + c;
173  }
174 
177  public: void Translate(const Vector3<T> &_t)
178  {
179  this->data[0][3] = _t.X();
180  this->data[1][3] = _t.Y();
181  this->data[2][3] = _t.Z();
182  }
183 
188  public: void Translate(T _x, T _y, T _z)
189  {
190  this->data[0][3] = _x;
191  this->data[1][3] = _y;
192  this->data[2][3] = _z;
193  }
194 
197  public: Vector3<T> Translation() const
198  {
199  return Vector3<T>(this->data[0][3], this->data[1][3], this->data[2][3]);
200  }
201 
204  public: Vector3<T> Scale() const
205  {
206  return Vector3<T>(this->data[0][0], this->data[1][1], this->data[2][2]);
207  }
208 
211  public: Quaternion<T> Rotation() const
212  {
213  Quaternion<T> q;
216  T trace = this->data[0][0] + this->data[1][1] + this->data[2][2];
217  T root;
218  if (trace > 0)
219  {
220  root = sqrt(trace + 1.0);
221  q.W(root / 2.0);
222  root = 1.0 / (2.0 * root);
223  q.X((this->data[2][1] - this->data[1][2]) * root);
224  q.Y((this->data[0][2] - this->data[2][0]) * root);
225  q.Z((this->data[1][0] - this->data[0][1]) * root);
226  }
227  else
228  {
229  static unsigned int s_iNext[3] = {1, 2, 0};
230  unsigned int i = 0;
231  if (this->data[1][1] > this->data[0][0])
232  i = 1;
233  if (this->data[2][2] > this->data[i][i])
234  i = 2;
235  unsigned int j = s_iNext[i];
236  unsigned int k = s_iNext[j];
237 
238  root = sqrt(this->data[i][i] - this->data[j][j] -
239  this->data[k][k] + 1.0);
240 
241  T a, b, c;
242  a = root / 2.0;
243  root = 1.0 / (2.0 * root);
244  b = (this->data[j][i] + this->data[i][j]) * root;
245  c = (this->data[k][i] + this->data[i][k]) * root;
246 
247  switch (i)
248  {
249  default:
250  case 0: q.X(a); break;
251  case 1: q.Y(a); break;
252  case 2: q.Z(a); break;
253  };
254  switch (j)
255  {
256  default:
257  case 0: q.X(b); break;
258  case 1: q.Y(b); break;
259  case 2: q.Z(b); break;
260  };
261  switch (k)
262  {
263  default:
264  case 0: q.X(c); break;
265  case 1: q.Y(c); break;
266  case 2: q.Z(c); break;
267  };
268 
269  q.W((this->data[k][j] - this->data[j][k]) * root);
270  }
271 
272  return q;
273  }
274 
279  public: Vector3<T> EulerRotation(bool _firstSolution) const
280  {
281  Vector3<T> euler;
282  Vector3<T> euler2;
283 
284  T m31 = this->data[2][0];
285  T m11 = this->data[0][0];
286  T m12 = this->data[0][1];
287  T m13 = this->data[0][2];
288  T m32 = this->data[2][1];
289  T m33 = this->data[2][2];
290  T m21 = this->data[1][0];
291 
292  if (std::abs(m31) >= 1.0)
293  {
294  euler.Z(0.0);
295  euler2.Z(0.0);
296 
297  if (m31 < 0.0)
298  {
299  euler.Y(IGN_PI / 2.0);
300  euler2.Y(IGN_PI / 2.0);
301  euler.X(atan2(m12, m13));
302  euler2.X(atan2(m12, m13));
303  }
304  else
305  {
306  euler.Y(-IGN_PI / 2.0);
307  euler2.Y(-IGN_PI / 2.0);
308  euler.X(atan2(-m12, -m13));
309  euler2.X(atan2(-m12, -m13));
310  }
311  }
312  else
313  {
314  euler.Y(-asin(m31));
315  euler2.Y(IGN_PI - euler.Y());
316 
317  euler.X(atan2(m32 / cos(euler.Y()), m33 / cos(euler.Y())));
318  euler2.X(atan2(m32 / cos(euler2.Y()), m33 / cos(euler2.Y())));
319 
320  euler.Z(atan2(m21 / cos(euler.Y()), m11 / cos(euler.Y())));
321  euler2.Z(atan2(m21 / cos(euler2.Y()), m11 / cos(euler2.Y())));
322  }
323 
324  if (_firstSolution)
325  return euler;
326  else
327  return euler2;
328  }
329 
332  public: Pose3<T> Pose() const
333  {
334  return Pose3<T>(this->Translation(), this->Rotation());
335  }
336 
339  public: void Scale(const Vector3<T> &_s)
340  {
341  this->data[0][0] = _s.X();
342  this->data[1][1] = _s.Y();
343  this->data[2][2] = _s.Z();
344  this->data[3][3] = 1.0;
345  }
346 
351  public: void Scale(T _x, T _y, T _z)
352  {
353  this->data[0][0] = _x;
354  this->data[1][1] = _y;
355  this->data[2][2] = _z;
356  this->data[3][3] = 1.0;
357  }
358 
361  public: bool IsAffine() const
362  {
363  return equal(this->data[3][0], static_cast<T>(0)) &&
364  equal(this->data[3][1], static_cast<T>(0)) &&
365  equal(this->data[3][2], static_cast<T>(0)) &&
366  equal(this->data[3][3], static_cast<T>(1));
367  }
368 
373  public: Vector3<T> TransformAffine(const Vector3<T> &_v) const
374  {
375  if (!this->IsAffine())
376  throw AffineException();
377 
378  return Vector3<T>(this->data[0][0]*_v.X() + this->data[0][1]*_v.Y() +
379  this->data[0][2]*_v.Z() + this->data[0][3],
380  this->data[1][0]*_v.X() + this->data[1][1]*_v.Y() +
381  this->data[1][2]*_v.Z() + this->data[1][3],
382  this->data[2][0]*_v.X() + this->data[2][1]*_v.Y() +
383  this->data[2][2]*_v.Z() + this->data[2][3]);
384  }
385 
389  public: Matrix4<T> Inverse() const
390  {
391  T v0, v1, v2, v3, v4, v5, t00, t10, t20, t30;
392  Matrix4<T> r;
393 
394  v0 = this->data[2][0]*this->data[3][1] -
395  this->data[2][1]*this->data[3][0];
396  v1 = this->data[2][0]*this->data[3][2] -
397  this->data[2][2]*this->data[3][0];
398  v2 = this->data[2][0]*this->data[3][3] -
399  this->data[2][3]*this->data[3][0];
400  v3 = this->data[2][1]*this->data[3][2] -
401  this->data[2][2]*this->data[3][1];
402  v4 = this->data[2][1]*this->data[3][3] -
403  this->data[2][3]*this->data[3][1];
404  v5 = this->data[2][2]*this->data[3][3] -
405  this->data[2][3]*this->data[3][2];
406 
407  t00 = +(v5*this->data[1][1] -
408  v4*this->data[1][2] + v3*this->data[1][3]);
409  t10 = -(v5*this->data[1][0] -
410  v2*this->data[1][2] + v1*this->data[1][3]);
411  t20 = +(v4*this->data[1][0] -
412  v2*this->data[1][1] + v0*this->data[1][3]);
413  t30 = -(v3*this->data[1][0] -
414  v1*this->data[1][1] + v0*this->data[1][2]);
415 
416  T invDet = 1 / (t00 * this->data[0][0] + t10 * this->data[0][1] +
417  t20 * this->data[0][2] + t30 * this->data[0][3]);
418 
419  r(0, 0) = t00 * invDet;
420  r(1, 0) = t10 * invDet;
421  r(2, 0) = t20 * invDet;
422  r(3, 0) = t30 * invDet;
423 
424  r(0, 1) = -(v5*this->data[0][1] -
425  v4*this->data[0][2] + v3*this->data[0][3]) * invDet;
426  r(1, 1) = +(v5*this->data[0][0] -
427  v2*this->data[0][2] + v1*this->data[0][3]) * invDet;
428  r(2, 1) = -(v4*this->data[0][0] -
429  v2*this->data[0][1] + v0*this->data[0][3]) * invDet;
430  r(3, 1) = +(v3*this->data[0][0] -
431  v1*this->data[0][1] + v0*this->data[0][2]) * invDet;
432 
433  v0 = this->data[1][0]*this->data[3][1] -
434  this->data[1][1]*this->data[3][0];
435  v1 = this->data[1][0]*this->data[3][2] -
436  this->data[1][2]*this->data[3][0];
437  v2 = this->data[1][0]*this->data[3][3] -
438  this->data[1][3]*this->data[3][0];
439  v3 = this->data[1][1]*this->data[3][2] -
440  this->data[1][2]*this->data[3][1];
441  v4 = this->data[1][1]*this->data[3][3] -
442  this->data[1][3]*this->data[3][1];
443  v5 = this->data[1][2]*this->data[3][3] -
444  this->data[1][3]*this->data[3][2];
445 
446  r(0, 2) = +(v5*this->data[0][1] -
447  v4*this->data[0][2] + v3*this->data[0][3]) * invDet;
448  r(1, 2) = -(v5*this->data[0][0] -
449  v2*this->data[0][2] + v1*this->data[0][3]) * invDet;
450  r(2, 2) = +(v4*this->data[0][0] -
451  v2*this->data[0][1] + v0*this->data[0][3]) * invDet;
452  r(3, 2) = -(v3*this->data[0][0] -
453  v1*this->data[0][1] + v0*this->data[0][2]) * invDet;
454 
455  v0 = this->data[2][1]*this->data[1][0] -
456  this->data[2][0]*this->data[1][1];
457  v1 = this->data[2][2]*this->data[1][0] -
458  this->data[2][0]*this->data[1][2];
459  v2 = this->data[2][3]*this->data[1][0] -
460  this->data[2][0]*this->data[1][3];
461  v3 = this->data[2][2]*this->data[1][1] -
462  this->data[2][1]*this->data[1][2];
463  v4 = this->data[2][3]*this->data[1][1] -
464  this->data[2][1]*this->data[1][3];
465  v5 = this->data[2][3]*this->data[1][2] -
466  this->data[2][2]*this->data[1][3];
467 
468  r(0, 3) = -(v5*this->data[0][1] -
469  v4*this->data[0][2] + v3*this->data[0][3]) * invDet;
470  r(1, 3) = +(v5*this->data[0][0] -
471  v2*this->data[0][2] + v1*this->data[0][3]) * invDet;
472  r(2, 3) = -(v4*this->data[0][0] -
473  v2*this->data[0][1] + v0*this->data[0][3]) * invDet;
474  r(3, 3) = +(v3*this->data[0][0] -
475  v1*this->data[0][1] + v0*this->data[0][2]) * invDet;
476 
477  return r;
478  }
479 
483  public: Matrix4<T> &operator=(const Matrix4<T> &_mat)
484  {
485  memcpy(this->data, _mat.data, sizeof(this->data[0][0])*16);
486  return *this;
487  }
488 
492  public: const Matrix4<T> &operator=(const Matrix3<T> &_mat)
493  {
494  this->data[0][0] = _mat(0, 0);
495  this->data[0][1] = _mat(0, 1);
496  this->data[0][2] = _mat(0, 2);
497 
498  this->data[1][0] = _mat(1, 0);
499  this->data[1][1] = _mat(1, 1);
500  this->data[1][2] = _mat(1, 2);
501 
502  this->data[2][0] = _mat(2, 0);
503  this->data[2][1] = _mat(2, 1);
504  this->data[2][2] = _mat(2, 2);
505 
506  return *this;
507  }
508 
512  public: Matrix4<T> operator*(const Matrix4<T> &_m2) const
513  {
514  return Matrix4<T>(
515  this->data[0][0] * _m2(0, 0) +
516  this->data[0][1] * _m2(1, 0) +
517  this->data[0][2] * _m2(2, 0) +
518  this->data[0][3] * _m2(3, 0),
519 
520  this->data[0][0] * _m2(0, 1) +
521  this->data[0][1] * _m2(1, 1) +
522  this->data[0][2] * _m2(2, 1) +
523  this->data[0][3] * _m2(3, 1),
524 
525  this->data[0][0] * _m2(0, 2) +
526  this->data[0][1] * _m2(1, 2) +
527  this->data[0][2] * _m2(2, 2) +
528  this->data[0][3] * _m2(3, 2),
529 
530  this->data[0][0] * _m2(0, 3) +
531  this->data[0][1] * _m2(1, 3) +
532  this->data[0][2] * _m2(2, 3) +
533  this->data[0][3] * _m2(3, 3),
534 
535  this->data[1][0] * _m2(0, 0) +
536  this->data[1][1] * _m2(1, 0) +
537  this->data[1][2] * _m2(2, 0) +
538  this->data[1][3] * _m2(3, 0),
539 
540  this->data[1][0] * _m2(0, 1) +
541  this->data[1][1] * _m2(1, 1) +
542  this->data[1][2] * _m2(2, 1) +
543  this->data[1][3] * _m2(3, 1),
544 
545  this->data[1][0] * _m2(0, 2) +
546  this->data[1][1] * _m2(1, 2) +
547  this->data[1][2] * _m2(2, 2) +
548  this->data[1][3] * _m2(3, 2),
549 
550  this->data[1][0] * _m2(0, 3) +
551  this->data[1][1] * _m2(1, 3) +
552  this->data[1][2] * _m2(2, 3) +
553  this->data[1][3] * _m2(3, 3),
554 
555  this->data[2][0] * _m2(0, 0) +
556  this->data[2][1] * _m2(1, 0) +
557  this->data[2][2] * _m2(2, 0) +
558  this->data[2][3] * _m2(3, 0),
559 
560  this->data[2][0] * _m2(0, 1) +
561  this->data[2][1] * _m2(1, 1) +
562  this->data[2][2] * _m2(2, 1) +
563  this->data[2][3] * _m2(3, 1),
564 
565  this->data[2][0] * _m2(0, 2) +
566  this->data[2][1] * _m2(1, 2) +
567  this->data[2][2] * _m2(2, 2) +
568  this->data[2][3] * _m2(3, 2),
569 
570  this->data[2][0] * _m2(0, 3) +
571  this->data[2][1] * _m2(1, 3) +
572  this->data[2][2] * _m2(2, 3) +
573  this->data[2][3] * _m2(3, 3),
574 
575  this->data[3][0] * _m2(0, 0) +
576  this->data[3][1] * _m2(1, 0) +
577  this->data[3][2] * _m2(2, 0) +
578  this->data[3][3] * _m2(3, 0),
579 
580  this->data[3][0] * _m2(0, 1) +
581  this->data[3][1] * _m2(1, 1) +
582  this->data[3][2] * _m2(2, 1) +
583  this->data[3][3] * _m2(3, 1),
584 
585  this->data[3][0] * _m2(0, 2) +
586  this->data[3][1] * _m2(1, 2) +
587  this->data[3][2] * _m2(2, 2) +
588  this->data[3][3] * _m2(3, 2),
589 
590  this->data[3][0] * _m2(0, 3) +
591  this->data[3][1] * _m2(1, 3) +
592  this->data[3][2] * _m2(2, 3) +
593  this->data[3][3] * _m2(3, 3));
594  }
595 
599  public: Vector3<T> operator*(const Vector3<T> &_vec) const
600  {
601  return Vector3<T>(
602  this->data[0][0]*_vec.X() + this->data[0][1]*_vec.Y() +
603  this->data[0][2]*_vec.Z() + this->data[0][3],
604  this->data[1][0]*_vec.X() + this->data[1][1]*_vec.Y() +
605  this->data[1][2]*_vec.Z() + this->data[1][3],
606  this->data[2][0]*_vec.X() + this->data[2][1]*_vec.Y() +
607  this->data[2][2]*_vec.Z() + this->data[2][3]);
608  }
609 
614  public: inline const T &operator()(size_t _row, size_t _col) const
615  {
616  if (_row >= 4 || _col >= 4)
617  throw IndexException();
618  return this->data[_row][_col];
619  }
620 
626  public: inline T &operator()(size_t _row, size_t _col)
627  {
628  if (_row >= 4 || _col >= 4)
629  throw IndexException();
630  return this->data[_row][_col];
631  }
632 
637  public: bool operator==(const Matrix4<T> &_m) const
638  {
639  return math::equal(this->data[0][0], _m(0, 0)) &&
640  math::equal(this->data[0][1], _m(0, 1)) &&
641  math::equal(this->data[0][2], _m(0, 2)) &&
642  math::equal(this->data[0][3], _m(0, 3)) &&
643 
644  math::equal(this->data[1][0], _m(1, 0)) &&
645  math::equal(this->data[1][1], _m(1, 1)) &&
646  math::equal(this->data[1][2], _m(1, 2)) &&
647  math::equal(this->data[1][3], _m(1, 3)) &&
648 
649  math::equal(this->data[2][0], _m(2, 0)) &&
650  math::equal(this->data[2][1], _m(2, 1)) &&
651  math::equal(this->data[2][2], _m(2, 2)) &&
652  math::equal(this->data[2][3], _m(2, 3)) &&
653 
654  math::equal(this->data[3][0], _m(3, 0)) &&
655  math::equal(this->data[3][1], _m(3, 1)) &&
656  math::equal(this->data[3][2], _m(3, 2)) &&
657  math::equal(this->data[3][3], _m(3, 3));
658  }
659 
663  public: bool operator!=(const Matrix4<T> &_m) const
664  {
665  return !(*this == _m);
666  }
667 
672  public: friend std::ostream &operator<<(
673  std::ostream &_out, const ignition::math::Matrix4<T> &_m)
674  {
675  _out << precision(_m(0, 0), 6) << " "
676  << precision(_m(0, 1), 6) << " "
677  << precision(_m(0, 2), 6) << " "
678  << precision(_m(0, 3), 6) << " "
679  << precision(_m(1, 0), 6) << " "
680  << precision(_m(1, 1), 6) << " "
681  << precision(_m(1, 2), 6) << " "
682  << precision(_m(1, 3), 6) << " "
683  << precision(_m(2, 0), 6) << " "
684  << precision(_m(2, 1), 6) << " "
685  << precision(_m(2, 2), 6) << " "
686  << precision(_m(2, 3), 6) << " "
687  << precision(_m(3, 0), 6) << " "
688  << precision(_m(3, 1), 6) << " "
689  << precision(_m(3, 2), 6) << " "
690  << precision(_m(3, 3), 6);
691 
692  return _out;
693  }
694 
699  public: friend std::istream &operator>>(
700  std::istream &_in, ignition::math::Matrix4<T> &_m)
701  {
702  // Skip white spaces
703  _in.setf(std::ios_base::skipws);
704  T d[16];
705  _in >> d[0] >> d[1] >> d[2] >> d[3]
706  >> d[4] >> d[5] >> d[6] >> d[7]
707  >> d[8] >> d[9] >> d[10] >> d[11]
708  >> d[12] >> d[13] >> d[14] >> d[15];
709 
710  _m.Set(d[0], d[1], d[2], d[3],
711  d[4], d[5], d[6], d[7],
712  d[8], d[9], d[10], d[11],
713  d[12], d[13], d[14], d[15]);
714  return _in;
715  }
716 
718  private: T data[4][4];
719  };
720 
721  template<typename T>
722  const Matrix4<T> Matrix4<T>::Identity(
723  1, 0, 0, 0,
724  0, 1, 0, 0,
725  0, 0, 1, 0,
726  0, 0, 0, 1);
727 
728  template<typename T>
729  const Matrix4<T> Matrix4<T>::Zero(
730  0, 0, 0, 0,
731  0, 0, 0, 0,
732  0, 0, 0, 0,
733  0, 0, 0, 0);
734 
738  }
739 }
740 #endif
ignition/math/AffineException.hh
Definition: AffineException.hh:30
Matrix4< T > Inverse() const
Return the inverse matrix.
Definition: Matrix4.hh:389
static const Matrix4< T > Identity
Identity matrix.
Definition: Matrix4.hh:36
T & operator()(size_t _row, size_t _col)
Get a mutable version the value at the specified row, column index.
Definition: Matrix4.hh:626
T precision(const T &_a, const unsigned int &_precision)
get value at a specified precision
Definition: Helpers.hh:188
const T & operator()(size_t _row, size_t _col) const
Get the value at the specified row, column index.
Definition: Matrix4.hh:614
const Matrix4< T > & operator=(const Matrix3< T > &_mat)
Equal operator for 3x3 matrix.
Definition: Matrix4.hh:492
Matrix4< int > Matrix4i
Definition: Matrix4.hh:735
Matrix4(const Matrix4< T > &_m)
Copy constructor.
Definition: Matrix4.hh:49
Encapsulates a position and rotation in three space.
Definition: Pose3.hh:30
friend std::istream & operator>>(std::istream &_in, ignition::math::Matrix4< T > &_m)
Stream extraction operator.
Definition: Matrix4.hh:699
A 4x4 matrix class.
Definition: Matrix4.hh:33
const T & Y() const
Get the y component.
Definition: Quaternion.hh:750
static const Matrix4< T > Zero
Zero matrix.
Definition: Matrix4.hh:39
void Scale(const Vector3< T > &_s)
Set the scale.
Definition: Matrix4.hh:339
T X() const
Get the x value.
Definition: Vector3.hh:545
const T & Z() const
Get the z component.
Definition: Quaternion.hh:757
Vector3< T > Scale() const
Get the scale values as a Vector3<T>
Definition: Matrix4.hh:204
T Y() const
Get the y value.
Definition: Vector3.hh:552
A 3x3 matrix class.
Definition: Matrix3.hh:32
Matrix4()
Constructor.
Definition: Matrix4.hh:42
Vector3< T > operator*(const Vector3< T > &_vec) const
Multiplication operator.
Definition: Matrix4.hh:599
Matrix4(T _v00, T _v01, T _v02, T _v03, T _v10, T _v11, T _v12, T _v13, T _v20, T _v21, T _v22, T _v23, T _v30, T _v31, T _v32, T _v33)
Constructor.
Definition: Matrix4.hh:71
bool IsAffine() const
Return true if the matrix is affine.
Definition: Matrix4.hh:361
bool operator==(const Matrix4< T > &_m) const
Equality operator.
Definition: Matrix4.hh:637
T Z() const
Get the z value.
Definition: Vector3.hh:559
Exception that is thrown when an out-of-bounds index is encountered.
Definition: IndexException.hh:30
void Axis(const Vector3< T > &_axis, T _angle)
Set the upper-left 3x3 matrix from an axis and angle.
Definition: Matrix4.hh:156
Quaternion< T > Rotation() const
Get the rotation as a quaternion.
Definition: Matrix4.hh:211
Vector3< T > EulerRotation(bool _firstSolution) const
Get the rotation as a Euler angles.
Definition: Matrix4.hh:279
bool operator!=(const Matrix4< T > &_m) const
Inequality test operator.
Definition: Matrix4.hh:663
void Scale(T _x, T _y, T _z)
Set the scale.
Definition: Matrix4.hh:351
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:37
Vector3< T > TransformAffine(const Vector3< T > &_v) const
Perform an affine transformation.
Definition: Matrix4.hh:373
Matrix4< float > Matrix4f
Definition: Matrix4.hh:737
void Translate(const Vector3< T > &_t)
Set the translational values [ (0, 3) (1, 3) (2, 3) ].
Definition: Matrix4.hh:177
virtual ~Matrix4()
Destructor.
Definition: Matrix4.hh:107
void Translate(T _x, T _y, T _z)
Set the translational values [ (0, 3) (1, 3) (2, 3) ].
Definition: Matrix4.hh:188
Matrix4< T > operator*(const Matrix4< T > &_m2) const
Multiplication operator.
Definition: Matrix4.hh:512
Pose3< T > Pose() const
Get the transformation as math::Pose.
Definition: Matrix4.hh:332
const T & W() const
Get the w component.
Definition: Quaternion.hh:736
Vector3< T > Translation() const
Get the translational values as a Vector3.
Definition: Matrix4.hh:197
void Set(T _v00, T _v01, T _v02, T _v03, T _v10, T _v11, T _v12, T _v13, T _v20, T _v21, T _v22, T _v23, T _v30, T _v31, T _v32, T _v33)
Change the values.
Definition: Matrix4.hh:126
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
Matrix4< double > Matrix4d
Definition: Matrix4.hh:736
void Normalize()
Normalize the quaternion.
Definition: Quaternion.hh:206
A quaternion class.
Definition: Quaternion.hh:31
Matrix4(const Quaternion< T > &_q)
Construct Matrix4 from a quaternion.
Definition: Matrix4.hh:84
#define IGN_PI
Define IGN_PI, IGN_PI_2, and IGN_PI_4.
Definition: Helpers.hh:59
Matrix4< T > & operator=(const Matrix4< T > &_mat)
Equal operator.
Definition: Matrix4.hh:483
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Matrix4< T > &_m)
Stream insertion operator.
Definition: Matrix4.hh:672
const T & X() const
Get the x component.
Definition: Quaternion.hh:743