18 #ifndef _IGNITION_MATRIX3_HH_ 19 #define _IGNITION_MATRIX3_HH_ 44 std::memset(this->data, 0,
sizeof(this->data[0][0])*9);
51 std::memcpy(this->data, _m.data,
sizeof(this->data[0][0])*9);
65 T _v10, T _v11, T _v12,
66 T _v20, T _v21, T _v22)
68 this->data[0][0] = _v00;
69 this->data[0][1] = _v01;
70 this->data[0][2] = _v02;
71 this->data[1][0] = _v10;
72 this->data[1][1] = _v11;
73 this->data[1][2] = _v12;
74 this->data[2][0] = _v20;
75 this->data[2][1] = _v21;
76 this->data[2][2] = _v22;
85 this->
Set(1 - 2*qt.
Y()*qt.
Y() - 2 *qt.
Z()*qt.
Z(),
86 2 * qt.
X()*qt.
Y() - 2*qt.
Z()*qt.
W(),
87 2 * qt.
X() * qt.
Z() + 2 * qt.
Y() * qt.
W(),
88 2 * qt.
X() * qt.
Y() + 2 * qt.
Z() * qt.
W(),
89 1 - 2*qt.
X()*qt.
X() - 2 * qt.
Z()*qt.
Z(),
90 2 * qt.
Y() * qt.
Z() - 2 * qt.
X() * qt.
W(),
91 2 * qt.
X() * qt.
Z() - 2 * qt.
Y() * qt.
W(),
92 2 * qt.
Y() * qt.
Z() + 2 * qt.
X() * qt.
W(),
93 1 - 2 * qt.
X()*qt.
X() - 2 * qt.
Y()*qt.
Y());
109 public:
void Set(T _v00, T _v01, T _v02,
110 T _v10, T _v11, T _v12,
111 T _v20, T _v21, T _v22)
113 this->data[0][0] = _v00;
114 this->data[0][1] = _v01;
115 this->data[0][2] = _v02;
116 this->data[1][0] = _v10;
117 this->data[1][1] = _v11;
118 this->data[1][2] = _v12;
119 this->data[2][0] = _v20;
120 this->data[2][1] = _v21;
121 this->data[2][2] = _v22;
132 this->
Col(0, _xAxis);
133 this->
Col(1, _yAxis);
134 this->
Col(2, _zAxis);
146 this->data[0][0] = _axis.
X()*_axis.
X()*C + c;
147 this->data[0][1] = _axis.
X()*_axis.
Y()*C - _axis.
Z()*s;
148 this->data[0][2] = _axis.
X()*_axis.
Z()*C + _axis.
Y()*s;
150 this->data[1][0] = _axis.
Y()*_axis.
X()*C + _axis.
Z()*s;
151 this->data[1][1] = _axis.
Y()*_axis.
Y()*C + c;
152 this->data[1][2] = _axis.
Y()*_axis.
Z()*C - _axis.
X()*s;
154 this->data[2][0] = _axis.
Z()*_axis.
X()*C - _axis.
Y()*s;
155 this->data[2][1] = _axis.
Z()*_axis.
Y()*C + _axis.
X()*s;
156 this->data[2][2] = _axis.
Z()*_axis.
Z()*C + c;
167 this->data[0][_c] = _v.
X();
168 this->data[1][_c] = _v.
Y();
169 this->data[2][_c] = _v.
Z();
176 this->data[0][0] - _m(0, 0),
177 this->data[0][1] - _m(0, 1),
178 this->data[0][2] - _m(0, 2),
179 this->data[1][0] - _m(1, 0),
180 this->data[1][1] - _m(1, 1),
181 this->data[1][2] - _m(1, 2),
182 this->data[2][0] - _m(2, 0),
183 this->data[2][1] - _m(2, 1),
184 this->data[2][2] - _m(2, 2));
191 this->data[0][0]+_m(0, 0),
192 this->data[0][1]+_m(0, 1),
193 this->data[0][2]+_m(0, 2),
194 this->data[1][0]+_m(1, 0),
195 this->data[1][1]+_m(1, 1),
196 this->data[1][2]+_m(1, 2),
197 this->data[2][0]+_m(2, 0),
198 this->data[2][1]+_m(2, 1),
199 this->data[2][2]+_m(2, 2));
206 _s * this->data[0][0], _s * this->data[0][1], _s * this->data[0][2],
207 _s * this->data[1][0], _s * this->data[1][1], _s * this->data[1][2],
208 _s * this->data[2][0], _s * this->data[2][1], _s * this->data[2][2]);
218 this->data[0][0]*_m(0, 0)+
219 this->data[0][1]*_m(1, 0)+
220 this->data[0][2]*_m(2, 0),
222 this->data[0][0]*_m(0, 1)+
223 this->data[0][1]*_m(1, 1)+
224 this->data[0][2]*_m(2, 1),
226 this->data[0][0]*_m(0, 2)+
227 this->data[0][1]*_m(1, 2)+
228 this->data[0][2]*_m(2, 2),
231 this->data[1][0]*_m(0, 0)+
232 this->data[1][1]*_m(1, 0)+
233 this->data[1][2]*_m(2, 0),
235 this->data[1][0]*_m(0, 1)+
236 this->data[1][1]*_m(1, 1)+
237 this->data[1][2]*_m(2, 1),
239 this->data[1][0]*_m(0, 2)+
240 this->data[1][1]*_m(1, 2)+
241 this->data[1][2]*_m(2, 2),
244 this->data[2][0]*_m(0, 0)+
245 this->data[2][1]*_m(1, 0)+
246 this->data[2][2]*_m(2, 0),
248 this->data[2][0]*_m(0, 1)+
249 this->data[2][1]*_m(1, 1)+
250 this->data[2][2]*_m(2, 1),
252 this->data[2][0]*_m(0, 2)+
253 this->data[2][1]*_m(1, 2)+
254 this->data[2][2]*_m(2, 2));
264 this->data[0][0]*_vec.
X() + this->data[0][1]*_vec.
Y() +
265 this->data[0][2]*_vec.
Z(),
266 this->data[1][0]*_vec.
X() + this->data[1][1]*_vec.
Y() +
267 this->data[1][2]*_vec.
Z(),
268 this->data[2][0]*_vec.
X() + this->data[2][1]*_vec.
Y() +
269 this->data[2][2]*_vec.
Z());
291 _m(0, 0)*_v.
X() + _m(1, 0)*_v.
Y() + _m(2, 0)*_v.
Z(),
292 _m(0, 1)*_v.
X() + _m(1, 1)*_v.
Y() + _m(2, 1)*_v.
Z(),
293 _m(0, 2)*_v.
X() + _m(1, 2)*_v.
Y() + _m(2, 2)*_v.
Z());
303 return equal<T>(this->data[0][0], _m(0, 0), _tol)
304 && equal<T>(this->data[0][1], _m(0, 1), _tol)
305 && equal<T>(this->data[0][2], _m(0, 2), _tol)
306 && equal<T>(this->data[1][0], _m(1, 0), _tol)
307 && equal<T>(this->data[1][1], _m(1, 1), _tol)
308 && equal<T>(this->data[1][2], _m(1, 2), _tol)
309 && equal<T>(this->data[2][0], _m(2, 0), _tol)
310 && equal<T>(this->data[2][1], _m(2, 1), _tol)
311 && equal<T>(this->data[2][2], _m(2, 2), _tol);
319 return this->
Equal(_m, static_cast<T>(1e-6));
327 return !(*
this == _m);
333 public:
inline const T &
operator()(
size_t _row,
size_t _col)
const 335 if (_row >= 3 || _col >= 3)
337 return this->data[_row][_col];
345 if (_row >= 3 || _col >=3)
347 return this->data[_row][_col];
354 T t0 = this->data[2][2]*this->data[1][1]
355 - this->data[2][1]*this->data[1][2];
357 T t1 = -(this->data[2][2]*this->data[1][0]
358 -this->data[2][0]*this->data[1][2]);
360 T t2 = this->data[2][1]*this->data[1][0]
361 - this->data[2][0]*this->data[1][1];
363 return t0 * this->data[0][0]
364 + t1 * this->data[0][1]
365 + t2 * this->data[0][2];
372 T t0 = this->data[2][2]*this->data[1][1] -
373 this->data[2][1]*this->data[1][2];
375 T t1 = -(this->data[2][2]*this->data[1][0] -
376 this->data[2][0]*this->data[1][2]);
378 T t2 = this->data[2][1]*this->data[1][0] -
379 this->data[2][0]*this->data[1][1];
381 T invDet = 1.0 / (t0 * this->data[0][0] +
382 t1 * this->data[0][1] +
383 t2 * this->data[0][2]);
387 - (this->data[2][2] * this->data[0][1] -
388 this->data[2][1] * this->data[0][2]),
389 + (this->data[1][2] * this->data[0][1] -
390 this->data[1][1] * this->data[0][2]),
392 + (this->data[2][2] * this->data[0][0] -
393 this->data[2][0] * this->data[0][2]),
394 - (this->data[1][2] * this->data[0][0] -
395 this->data[1][0] * this->data[0][2]),
397 - (this->data[2][1] * this->data[0][0] -
398 this->data[2][0] * this->data[0][1]),
399 + (this->data[1][1] * this->data[0][0] -
400 this->data[1][0] * this->data[0][1]));
406 std::swap(this->data[0][1], this->data[1][0]);
407 std::swap(this->data[0][2], this->data[2][0]);
408 std::swap(this->data[1][2], this->data[2][1]);
416 this->data[0][0], this->data[1][0], this->data[2][0],
417 this->data[0][1], this->data[1][1], this->data[2][1],
418 this->data[0][2], this->data[1][2], this->data[2][2]);
448 _in.setf(std::ios_base::skipws);
450 _in >> d[0] >> d[1] >> d[2]
451 >> d[3] >> d[4] >> d[5]
452 >> d[6] >> d[7] >> d[8];
454 _m.
Set(d[0], d[1], d[2],
461 private: T data[3][3];
const T & operator()(size_t _row, size_t _col) const
Array subscript operator.
Definition: Matrix3.hh:333
bool operator!=(const Matrix3< T > &_m) const
Inequality test operator.
Definition: Matrix3.hh:325
friend std::istream & operator>>(std::istream &_in, ignition::math::Matrix3< T > &_m)
Stream extraction operator.
Definition: Matrix3.hh:444
Matrix3< double > Matrix3d
Definition: Matrix3.hh:477
T precision(const T &_a, const unsigned int &_precision)
get value at a specified precision
Definition: Helpers.hh:269
Matrix3< int > Matrix3i
Definition: Matrix3.hh:476
Matrix3(const Matrix3< T > &_m)
Copy constructor.
Definition: Matrix3.hh:49
Matrix3()
Constructor.
Definition: Matrix3.hh:42
T Determinant() const
Return the determinant of the matrix.
Definition: Matrix3.hh:352
T & operator()(size_t _row, size_t _col)
Array subscript operator.
Definition: Matrix3.hh:343
friend Vector3< T > operator*(const Vector3< T > &_v, const Matrix3< T > &_m)
Matrix left multiplication operator for Vector3.
Definition: Matrix3.hh:287
Vector3< T > operator*(const Vector3< T > &_vec) const
Multiplication operator with Vector3 on the right treated like a column vector.
Definition: Matrix3.hh:261
const T & Y() const
Get the y component.
Definition: Quaternion.hh:789
Matrix3< T > operator*(const T &_s) const
returns the element wise scalar multiplication
Definition: Matrix3.hh:203
T X() const
Get the x value.
Definition: Vector3.hh:630
const T & Z() const
Get the z component.
Definition: Quaternion.hh:796
static const Matrix3< T > Zero
Zero matrix.
Definition: Matrix3.hh:39
friend Matrix3< T > operator*(T _s, const Matrix3< T > &_m)
Matrix multiplication operator for scaling.
Definition: Matrix3.hh:276
Matrix3< T > Inverse() const
Return the inverse matrix.
Definition: Matrix3.hh:370
virtual ~Matrix3()
Desctructor.
Definition: Matrix3.hh:97
T Y() const
Get the y value.
Definition: Vector3.hh:637
void Col(unsigned int _c, const Vector3< T > &_v)
Set a column.
Definition: Matrix3.hh:162
A 3x3 matrix class.
Definition: Matrix3.hh:33
Matrix3< float > Matrix3f
Definition: Matrix3.hh:478
bool operator==(const Matrix3< T > &_m) const
Equality test operator.
Definition: Matrix3.hh:317
T Z() const
Get the z value.
Definition: Vector3.hh:644
Exception that is thrown when an out-of-bounds index is encountered.
Definition: IndexException.hh:37
Matrix3< T > operator*(const Matrix3< T > &_m) const
Matrix multiplication operator.
Definition: Matrix3.hh:214
Matrix3< T > operator+(const Matrix3< T > &_m) const
returns the element wise sum of two matrices
Definition: Matrix3.hh:188
Matrix3< T > Transposed() const
Return the transpose of this matrix.
Definition: Matrix3.hh:413
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:37
static const Matrix3< T > Identity
Identity matrix.
Definition: Matrix3.hh:36
void Set(T _v00, T _v01, T _v02, T _v10, T _v11, T _v12, T _v20, T _v21, T _v22)
Set values.
Definition: Matrix3.hh:109
Matrix3< T > operator-(const Matrix3< T > &_m) const
returns the element wise difference of two matrices
Definition: Matrix3.hh:173
void Transpose()
Transpose this matrix.
Definition: Matrix3.hh:404
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Matrix3< T > &_m)
Stream insertion operator.
Definition: Matrix3.hh:425
void Axes(const Vector3< T > &_xAxis, const Vector3< T > &_yAxis, const Vector3< T > &_zAxis)
Set the matrix from three axis (1 per column)
Definition: Matrix3.hh:128
const T & W() const
Get the w component.
Definition: Quaternion.hh:775
Matrix3(const Quaternion< T > &_q)
Construct Matrix3 from a quaternion.
Definition: Matrix3.hh:81
Definition: AffineException.hh:30
void Axis(const Vector3< T > &_axis, T _angle)
Set the matrix from an axis and angle.
Definition: Matrix3.hh:140
void Normalize()
Normalize the quaternion.
Definition: Quaternion.hh:206
A quaternion class.
Definition: Quaternion.hh:31
Matrix3(T _v00, T _v01, T _v02, T _v10, T _v11, T _v12, T _v20, T _v21, T _v22)
Constructor.
Definition: Matrix3.hh:64
bool Equal(const Matrix3 &_m, const T &_tol) const
Equality test with tolerance.
Definition: Matrix3.hh:301
const T & X() const
Get the x component.
Definition: Quaternion.hh:782