16 #ifndef TF_MATRIX3x3_H 17 #define TF_MATRIX3x3_H 26 #define Matrix3x3Data Matrix3x3DoubleData 63 m_el[0] = other.
m_el[0];
64 m_el[1] = other.
m_el[1];
65 m_el[2] = other.
m_el[2];
72 m_el[0] = other.
m_el[0];
73 m_el[1] = other.
m_el[1];
74 m_el[2] = other.
m_el[2];
83 return Vector3(m_el[0][i],m_el[1][i],m_el[2][i]);
151 tfScalar xs = q.x() * s, ys = q.y() * s, zs = q.z() * s;
152 tfScalar wx = q.w() * xs, wy = q.w() * ys, wz = q.w() * zs;
153 tfScalar xx = q.x() * xs, xy = q.x() * ys, xz = q.x() * zs;
154 tfScalar yy = q.y() * ys, yz = q.y() * zs, zz = q.z() * zs;
156 xy + wz,
tfScalar(1.0) - (xx + zz), yz - wx,
157 xz - wy, yz + wx,
tfScalar(1.0) - (xx + yy));
192 setValue(cj * ch, sj * sc - cs, sj * cc + ss,
193 cj * sh, sj * ss + cc, sj * cs - sc,
194 -sj, cj * si, cj * ci);
220 return identityMatrix;
245 tfScalar trace = m_el[0].
x() + m_el[1].
y() + m_el[2].
z();
254 temp[0]=((m_el[2].
y() - m_el[1].
z()) * s);
255 temp[1]=((m_el[0].
z() - m_el[2].
x()) * s);
256 temp[2]=((m_el[1].
x() - m_el[0].
y()) * s);
260 int i = m_el[0].
x() < m_el[1].
y() ?
261 (m_el[1].
y() < m_el[2].
z() ? 2 : 1) :
262 (m_el[0].
x() < m_el[2].
z() ? 2 : 0);
270 temp[3] = (m_el[k][j] - m_el[j][k]) * s;
271 temp[j] = (m_el[j][i] + m_el[i][j]) * s;
272 temp[k] = (m_el[k][i] + m_el[i][k]) * s;
274 q.setValue(temp[0],temp[1],temp[2],temp[3]);
318 euler_out.roll = delta;
319 euler_out2.roll = delta;
326 euler_out.roll = delta;
327 euler_out2.roll = delta;
332 euler_out.pitch = -
tfAsin(m_el[2].
x());
333 euler_out2.pitch =
TFSIMD_PI - euler_out.pitch;
336 m_el[2].
z()/
tfCos(euler_out.pitch));
337 euler_out2.roll =
tfAtan2(m_el[2].
y()/
tfCos(euler_out2.pitch),
338 m_el[2].
z()/
tfCos(euler_out2.pitch));
341 m_el[0].
x()/
tfCos(euler_out.pitch));
342 euler_out2.yaw =
tfAtan2(m_el[1].
x()/
tfCos(euler_out2.pitch),
343 m_el[0].
x()/
tfCos(euler_out2.pitch));
349 pitch = euler_out.pitch;
350 roll = euler_out.roll;
354 yaw = euler_out2.yaw;
355 pitch = euler_out2.pitch;
356 roll = euler_out2.roll;
375 return Matrix3x3(m_el[0].
x() * s.
x(), m_el[0].
y() * s.
y(), m_el[0].
z() * s.
z(),
376 m_el[1].
x() * s.
x(), m_el[1].
y() * s.
y(), m_el[1].
z() * s.
z(),
377 m_el[2].
x() * s.
x(), m_el[2].
y() * s.
y(), m_el[2].
z() * s.
z());
396 return m_el[0].
x() * v.
x() + m_el[1].
x() * v.
y() + m_el[2].
x() * v.
z();
400 return m_el[0].
y() * v.
x() + m_el[1].
y() * v.
y() + m_el[2].
y() * v.
z();
404 return m_el[0].
z() * v.
x() + m_el[1].
z() * v.
y() + m_el[2].
z() * v.
z();
455 tfScalar theta = (m_el[q][q] - m_el[p][p]) / (2 * mpq);
461 t = (theta >= 0) ? 1 / (theta +
tfSqrt(1 + theta2))
462 : 1 / (theta -
tfSqrt(1 + theta2));
463 cos = 1 /
tfSqrt(1 + t * t);
469 t = 1 / (theta * (2 +
tfScalar(0.5) / theta2));
475 m_el[p][q] = m_el[q][p] = 0;
476 m_el[p][p] -= t * mpq;
477 m_el[q][q] += t * mpq;
480 m_el[r][p] = m_el[p][r] = cos * mrp - sin * mrq;
481 m_el[r][q] = m_el[q][r] = cos * mrq + sin * mrp;
484 for (
int i = 0; i < 3; i++)
489 row[p] = cos * mrp - sin * mrq;
490 row[q] = cos * mrq + sin * mrp;
507 return m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1];
535 return tfTriple((*
this)[0], (*
this)[1], (*
this)[2]);
552 m_el[0].
y(), m_el[1].
y(), m_el[2].
y(),
553 m_el[0].
z(), m_el[1].
z(), m_el[2].
z());
559 return Matrix3x3(
cofac(1, 1, 2, 2),
cofac(0, 2, 2, 1),
cofac(0, 1, 1, 2),
560 cofac(1, 2, 2, 0),
cofac(0, 0, 2, 2),
cofac(0, 2, 1, 0),
561 cofac(1, 0, 2, 1),
cofac(0, 1, 2, 0),
cofac(0, 0, 1, 1));
567 Vector3 co(
cofac(1, 1, 2, 2),
cofac(1, 2, 2, 0),
cofac(1, 0, 2, 1));
572 co.
y() * s,
cofac(0, 0, 2, 2) * s,
cofac(0, 2, 1, 0) * s,
573 co.
z() * s,
cofac(0, 1, 2, 0) * s,
cofac(0, 0, 1, 1) * s);
580 m_el[0].
x() * m[0].
x() + m_el[1].
x() * m[1].
x() + m_el[2].
x() * m[2].
x(),
581 m_el[0].
x() * m[0].
y() + m_el[1].
x() * m[1].
y() + m_el[2].
x() * m[2].
y(),
582 m_el[0].
x() * m[0].
z() + m_el[1].
x() * m[1].
z() + m_el[2].
x() * m[2].
z(),
583 m_el[0].
y() * m[0].
x() + m_el[1].
y() * m[1].
x() + m_el[2].
y() * m[2].
x(),
584 m_el[0].
y() * m[0].
y() + m_el[1].
y() * m[1].
y() + m_el[2].
y() * m[2].
y(),
585 m_el[0].
y() * m[0].
z() + m_el[1].
y() * m[1].
z() + m_el[2].
y() * m[2].
z(),
586 m_el[0].
z() * m[0].
x() + m_el[1].
z() * m[1].
x() + m_el[2].
z() * m[2].
x(),
587 m_el[0].
z() * m[0].
y() + m_el[1].
z() * m[1].
y() + m_el[2].
z() * m[2].
y(),
588 m_el[0].
z() * m[0].
z() + m_el[1].
z() * m[1].
z() + m_el[2].
z() * m[2].
z());
595 m_el[0].
dot(m[0]), m_el[0].
dot(m[1]), m_el[0].
dot(m[2]),
596 m_el[1].
dot(m[0]), m_el[1].
dot(m[1]), m_el[1].
dot(m[2]),
597 m_el[2].
dot(m[0]), m_el[2].
dot(m[1]), m_el[2].
dot(m[2]));
642 return ( m1[0][0] == m2[0][0] && m1[1][0] == m2[1][0] && m1[2][0] == m2[2][0] &&
643 m1[0][1] == m2[0][1] && m1[1][1] == m2[1][1] && m1[2][1] == m2[2][1] &&
644 m1[0][2] == m2[0][2] && m1[1][2] == m2[1][2] && m1[2][2] == m2[2][2] );
664 for (
int i=0;i<3;i++)
670 for (
int i=0;i<3;i++)
677 for (
int i=0;i<3;i++)
683 for (
int i=0;i<3;i++)
689 for (
int i=0;i<3;i++)
695 #endif //TF_MATRIX3x3_H
void setEulerZYX(const tfScalar &yaw, const tfScalar &pitch, const tfScalar &roll) __attribute__((deprecated))
Set the matrix from euler angles using YPR around ZYX respectively.
TFSIMD_FORCE_INLINE Vector3 operator*(const Matrix3x3 &m, const Vector3 &v)
TFSIMD_FORCE_INLINE const Vector3 & operator[](int i) const
Get a const reference to a row of the matrix as a vector.
void serializeFloat(struct Matrix3x3FloatData &dataOut) const
Matrix3x3(const tfScalar &xx, const tfScalar &xy, const tfScalar &xz, const tfScalar &yx, const tfScalar &yy, const tfScalar &yz, const tfScalar &zx, const tfScalar &zy, const tfScalar &zz)
Constructor with row major formatting.
The Quaternion implements quaternion to perform linear algebra rotations in combination with Matrix3x...
__attribute__((deprecated)) void getEulerZYX(tfScalar &yaw
Get the matrix represented as euler angles around ZYX.
TFSIMD_FORCE_INLINE tfScalar tdoty(const Vector3 &v) const
void deSerializeDouble(const struct Matrix3x3DoubleData &dataIn)
double tfScalar
The tfScalar type abstracts floating point numbers, to easily switch between double and single floati...
void diagonalize(Matrix3x3 &rot, tfScalar threshold, int maxSteps)
diagonalizes this matrix by the Jacobi method.
tfScalar length2() const
Return the length squared of the quaternion.
void getEulerYPR(tfScalar &yaw, tfScalar &pitch, tfScalar &roll, unsigned int solution_number=1) const
Get the matrix represented as euler angles around YXZ, roundtrip with setEulerYPR.
TFSIMD_FORCE_INLINE bool operator==(const Matrix3x3 &m1, const Matrix3x3 &m2)
Equality operator between two matrices It will test all elements are equal.
void setEulerYPR(tfScalar eulerZ, tfScalar eulerY, tfScalar eulerX)
Set the matrix from euler angles YPR around ZYX axes.
TFSIMD_FORCE_INLINE tfScalar tfTriple(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
TFSIMD_FORCE_INLINE Matrix3x3 & operator=(const Matrix3x3 &other)
Assignment Operator.
Matrix3x3 inverse() const
Return the inverse of the matrix.
tfScalar cofac(int r1, int c1, int r2, int c2) const
Calculate the matrix cofactor.
void setValue(const tfScalar &xx, const tfScalar &xy, const tfScalar &xz, const tfScalar &yx, const tfScalar &yy, const tfScalar &yz, const tfScalar &zx, const tfScalar &zy, const tfScalar &zz)
Set the values of the matrix explicitly (row major)
TFSIMD_FORCE_INLINE const tfScalar & y() const
Return the y value.
The Matrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with Q...
TFSIMD_FORCE_INLINE void setValue(const tfScalar &x, const tfScalar &y, const tfScalar &z)
void getRotation(Quaternion &q) const
Get the matrix represented as a quaternion.
void setRotation(const Quaternion &q)
Set the matrix from a quaternion.
TFSIMD_FORCE_INLINE tfScalar tdotz(const Vector3 &v) const
void setIdentity()
Set the matrix to the identity.
TFSIMD_FORCE_INLINE const Vector3 & getRow(int i) const
Get a row of the matrix as a vector.
TFSIMD_FORCE_INLINE const tfScalar & x() const
Return the x value.
tfScalar tfScalar unsigned int solution_number
TFSIMD_FORCE_INLINE tfScalar tfCos(tfScalar x)
TFSIMD_FORCE_INLINE const tfScalar & z() const
Return the z value.
TFSIMD_FORCE_INLINE Vector3 & operator[](int i)
Get a mutable reference to a row of the matrix as a vector.
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
Get the matrix represented as roll pitch and yaw about fixed axes XYZ.
Matrix3x3 scaled(const Vector3 &s) const
Create a scaled copy of the matrix.
Matrix3x3()
No initializaion constructor.
void setRPY(tfScalar roll, tfScalar pitch, tfScalar yaw)
Set the matrix using RPY about XYZ fixed axes.
Matrix3x3 & operator*=(const Matrix3x3 &m)
Multiply by the target matrix on the right.
TFSIMD_FORCE_INLINE Vector3()
No initialization constructor.
TFSIMD_FORCE_INLINE const tfScalar & y() const
Return the y value.
#define TFSIMD_FORCE_INLINE
Matrix3x3 transposeTimes(const Matrix3x3 &m) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
Return the x value.
TFSIMD_FORCE_INLINE tfScalar tfAtan2(tfScalar x, tfScalar y)
void deSerializeFloat(const struct Matrix3x3FloatData &dataIn)
Vector3DoubleData m_el[3]
TFSIMD_FORCE_INLINE tfScalar dot(const Quaternion &q1, const Quaternion &q2)
Calculate the dot product between two quaternions.
Matrix3x3 absolute() const
Return the matrix with all values non negative.
TFSIMD_FORCE_INLINE const tfScalar & z() const
Return the z value.
TFSIMD_FORCE_INLINE tfScalar tfSqrt(tfScalar x)
Matrix3x3 timesTranspose(const Matrix3x3 &m) const
TFSIMD_FORCE_INLINE tfScalar tfAsin(tfScalar x)
TFSIMD_FORCE_INLINE tfScalar tdotx(const Vector3 &v) const
void setFromOpenGLSubMatrix(const tfScalar *m)
Set from a carray of tfScalars.
tfScalar determinant() const
Return the determinant of the matrix.
TFSIMD_FORCE_INLINE tfScalar tfSin(tfScalar x)
Matrix3x3 adjoint() const
Return the adjoint of the matrix.
TFSIMD_FORCE_INLINE tfScalar tfFabs(tfScalar x)
Matrix3x3 transpose() const
Return the transpose of the matrix.
void deSerialize(const struct Matrix3x3Data &dataIn)
Vector3 m_el[3]
Data storage for the matrix, each vector is a row of the matrix.
void getOpenGLSubMatrix(tfScalar *m) const
Fill the values of the matrix into a 9 element array.
TFSIMD_FORCE_INLINE Matrix3x3(const Matrix3x3 &other)
Copy constructor.
static const Matrix3x3 & getIdentity()
Vector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-byte...
void serialize(struct Matrix3x3Data &dataOut) const
TFSIMD_FORCE_INLINE Vector3 getColumn(int i) const
Get a column of the matrix as a vector.
Matrix3x3(const Quaternion &q)
Constructor from Quaternion.