Vector-Vector rotation, changed to double to minimize precision loss when multiplying multiple matrices

This commit is contained in:
Oekn5w 2018-06-09 21:09:17 +02:00 committed by Joseph Lenox
parent dde72b12ef
commit 418719cfb9
2 changed files with 372 additions and 315 deletions

View File

@ -15,80 +15,84 @@
namespace Slic3r { namespace Slic3r {
TransformationMatrix::TransformationMatrix() TransformationMatrix::TransformationMatrix()
{ : m11(1.0), m12(0.0), m13(0.0), m14(0.0),
*this = mat_eye(); m21(0.0), m22(1.0), m23(0.0), m24(0.0),
} m31(0.0), m32(0.0), m33(1.0), m34(0.0)
{
}
TransformationMatrix::TransformationMatrix(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34) TransformationMatrix::TransformationMatrix(
{ double _m11, double _m12, double _m13, double _m14,
this->m11 = m11; this->m12 = m12; this->m13 = m13; this->m14 = m14; double _m21, double _m22, double _m23, double _m24,
this->m21 = m21; this->m22 = m22; this->m23 = m23; this->m21 = m24; double _m31, double _m32, double _m33, double _m34)
this->m31 = m31; this->m32 = m32; this->m33 = m33; this->m34 = m34; : m11(_m11), m12(_m12), m13(_m13), m14(_m14),
} m21(_m21), m22(_m22), m23(_m23), m24(_m24),
#ifndef Testumgebung m31(_m31), m32(_m32), m33(_m33), m34(_m34)
TransformationMatrix::TransformationMatrix(std::vector<float> &entries_row_maj) {
{ }
TransformationMatrix::TransformationMatrix(const std::vector<double> &entries_row_maj)
{
if (entries_row_maj.size() != 12) if (entries_row_maj.size() != 12)
{ {
*this = mat_eye(); *this = TransformationMatrix();
CONFESS("Invalid number of entries when initalizing TransformationMatrix. Vector length must be 12."); CONFESS("Invalid number of entries when initalizing TransformationMatrix. Vector length must be 12.");
return; return;
} }
m11 = entries_row_maj[0]; m12 = entries_row_maj[1]; m13 = entries_row_maj[2]; m14 = entries_row_maj[3]; m11 = entries_row_maj[0]; m12 = entries_row_maj[1]; m13 = entries_row_maj[2]; m14 = entries_row_maj[3];
m21 = entries_row_maj[4]; m22 = entries_row_maj[5]; m23 = entries_row_maj[6]; m24 = entries_row_maj[7]; m21 = entries_row_maj[4]; m22 = entries_row_maj[5]; m23 = entries_row_maj[6]; m24 = entries_row_maj[7];
m31 = entries_row_maj[8]; m32 = entries_row_maj[9]; m33 = entries_row_maj[10]; m34 = entries_row_maj[11]; m31 = entries_row_maj[8]; m32 = entries_row_maj[9]; m33 = entries_row_maj[10]; m34 = entries_row_maj[11];
} }
#endif
TransformationMatrix::TransformationMatrix(const TransformationMatrix &other) TransformationMatrix::TransformationMatrix(const TransformationMatrix &other)
{ {
this->m11 = other.m11; this->m12 = other.m12; this->m13 = other.m13; this->m14 = other.m14; this->m11 = other.m11; this->m12 = other.m12; this->m13 = other.m13; this->m14 = other.m14;
this->m11 = other.m11; this->m22 = other.m22; this->m23 = other.m23; this->m24 = other.m24; this->m11 = other.m11; this->m22 = other.m22; this->m23 = other.m23; this->m24 = other.m24;
this->m31 = other.m31; this->m32 = other.m32; this->m33 = other.m33; this->m34 = other.m34; this->m31 = other.m31; this->m32 = other.m32; this->m33 = other.m33; this->m34 = other.m34;
} }
TransformationMatrix& TransformationMatrix::operator= (TransformationMatrix other) TransformationMatrix& TransformationMatrix::operator= (TransformationMatrix other)
{ {
this->swap(other); this->swap(other);
return *this; return *this;
} }
void void TransformationMatrix::swap(TransformationMatrix &other)
TransformationMatrix::swap(TransformationMatrix &other) {
{
std::swap(this->m11, other.m11); std::swap(this->m12, other.m12); std::swap(this->m11, other.m11); std::swap(this->m12, other.m12);
std::swap(this->m13, other.m13); std::swap(this->m14, other.m14); std::swap(this->m13, other.m13); std::swap(this->m14, other.m14);
std::swap(this->m21, other.m21); std::swap(this->m22, other.m22); std::swap(this->m21, other.m21); std::swap(this->m22, other.m22);
std::swap(this->m23, other.m23); std::swap(this->m24, other.m24); std::swap(this->m23, other.m23); std::swap(this->m24, other.m24);
std::swap(this->m31, other.m31); std::swap(this->m32, other.m32); std::swap(this->m31, other.m31); std::swap(this->m32, other.m32);
std::swap(this->m33, other.m33); std::swap(this->m34, other.m34); std::swap(this->m33, other.m33); std::swap(this->m34, other.m34);
} }
float* TransformationMatrix::matrix3x4f() float* TransformationMatrix::matrix3x4f()
{ {
float mat[12]; float out_arr[12];
mat[0] = this->m11; mat[1] = this->m12; mat[2] = this->m13; mat[3] = this->m14; out_arr[0] = this->m11; out_arr[1] = this->m12; out_arr[2] = this->m13; out_arr[3] = this->m14;
mat[4] = this->m21; mat[5] = this->m22; mat[6] = this->m23; mat[7] = this->m24; out_arr[4] = this->m21; out_arr[5] = this->m22; out_arr[6] = this->m23; out_arr[7] = this->m24;
mat[8] = this->m31; mat[9] = this->m32; mat[10] = this->m33; mat[11] = this->m34; out_arr[8] = this->m31; out_arr[9] = this->m32; out_arr[10] = this->m33; out_arr[11] = this->m34;
return mat; return out_arr;
} }
float TransformationMatrix::determinante() double TransformationMatrix::determinante()
{ {
// translation elements don't influence the determinante // translation elements don't influence the determinante
// because of the 0s on the other side of main diagonal // because of the 0s on the other side of main diagonal
return m11*(m22*m33 - m23*m32) - m12*(m21*m33 - m23*m31) + m13*(m21*m32 - m31*m22); return m11*(m22*m33 - m23*m32) - m12*(m21*m33 - m23*m31) + m13*(m21*m32 - m31*m22);
} }
bool TransformationMatrix::inverse(TransformationMatrix* inverse) bool TransformationMatrix::inverse(TransformationMatrix* inverse)
{ {
// from http://mathworld.wolfram.com/MatrixInverse.html // from http://mathworld.wolfram.com/MatrixInverse.html
// and https://math.stackexchange.com/questions/152462/inverse-of-transformation-matrix // and https://math.stackexchange.com/questions/152462/inverse-of-transformation-matrix
TransformationMatrix mat; TransformationMatrix mat;
float det = this->determinante(); double det = this->determinante();
if (abs(det) < 1e-9) if (abs(det) < 1e-9)
return false; return false;
float fac = 1.0f / det; double fac = 1.0 / det;
mat.m11 = fac*(this->m22*this->m33 - this->m23*this->m32); mat.m11 = fac*(this->m22*this->m33 - this->m23*this->m32);
mat.m12 = fac*(this->m13*this->m32 - this->m12*this->m33); mat.m12 = fac*(this->m13*this->m32 - this->m12*this->m33);
@ -106,67 +110,67 @@ namespace Slic3r {
inverse = &mat; inverse = &mat;
return true; return true;
} }
void TransformationMatrix::translate(float x, float y, float z) void TransformationMatrix::translate(double x, double y, double z)
{ {
TransformationMatrix mat = mat_translation(x, y, z); TransformationMatrix mat = mat_translation(x, y, z);
this->multiplyLeft(mat); this->multiplyLeft(mat);
} }
void TransformationMatrix::scale(float factor) void TransformationMatrix::scale(double factor)
{ {
this->scale(factor, factor, factor); this->scale(factor, factor, factor);
} }
void TransformationMatrix::scale(float x, float y, float z) void TransformationMatrix::scale(double x, double y, double z)
{ {
TransformationMatrix mat = mat_scale(x, y, z); TransformationMatrix mat = mat_scale(x, y, z);
this->multiplyLeft(mat); this->multiplyLeft(mat);
} }
void TransformationMatrix::mirror(const Axis &axis) void TransformationMatrix::mirror(const Axis &axis)
{ {
TransformationMatrix mat = mat_mirror(axis); TransformationMatrix mat = mat_mirror(axis);
this->multiplyLeft(mat); this->multiplyLeft(mat);
} }
void TransformationMatrix::mirror(const Pointf3 & normal) void TransformationMatrix::mirror(const Pointf3 & normal)
{ {
TransformationMatrix mat = mat_mirror(normal); TransformationMatrix mat = mat_mirror(normal);
this->multiplyLeft(mat); this->multiplyLeft(mat);
} }
void TransformationMatrix::rotate(float angle_rad, const Axis & axis) void TransformationMatrix::rotate(double angle_rad, const Axis & axis)
{ {
TransformationMatrix mat = mat_rotation(angle_rad, axis); TransformationMatrix mat = mat_rotation(angle_rad, axis);
this->multiplyLeft(mat); this->multiplyLeft(mat);
} }
void TransformationMatrix::rotate(float angle_rad, const Pointf3 & axis) void TransformationMatrix::rotate(double angle_rad, const Pointf3 & axis)
{ {
TransformationMatrix mat = mat_rotation(angle_rad, axis); TransformationMatrix mat = mat_rotation(angle_rad, axis);
this->multiplyLeft(mat); this->multiplyLeft(mat);
} }
void TransformationMatrix::rotate(float q1, float q2, float q3, float q4) void TransformationMatrix::rotate(double q1, double q2, double q3, double q4)
{ {
TransformationMatrix mat = mat_rotation(q1, q2, q3, q4); TransformationMatrix mat = mat_rotation(q1, q2, q3, q4);
this->multiplyLeft(mat); this->multiplyLeft(mat);
} }
void TransformationMatrix::multiplyLeft(TransformationMatrix &left) void TransformationMatrix::multiplyLeft(const TransformationMatrix &left)
{ {
*this = multiply(left, *this); *this = multiply(left, *this);
} }
void TransformationMatrix::multiplyRight(TransformationMatrix &right) void TransformationMatrix::multiplyRight(const TransformationMatrix &right)
{ {
*this = multiply(*this, right); *this = multiply(*this, right);
} }
TransformationMatrix TransformationMatrix::multiply(const TransformationMatrix &left, const TransformationMatrix &right) TransformationMatrix TransformationMatrix::multiply(const TransformationMatrix &left, const TransformationMatrix &right)
{ {
TransformationMatrix trafo; TransformationMatrix trafo;
trafo.m11 = left.m11*right.m11 + left.m12*right.m21 + left.m13 + right.m31; trafo.m11 = left.m11*right.m11 + left.m12*right.m21 + left.m13 + right.m31;
@ -185,61 +189,58 @@ namespace Slic3r {
trafo.m34 = left.m31*right.m14 + left.m32*right.m24 + left.m33 + right.m34 + left.m34; trafo.m34 = left.m31*right.m14 + left.m32*right.m24 + left.m33 + right.m34 + left.m34;
return trafo; return trafo;
} }
TransformationMatrix TransformationMatrix::mat_eye() TransformationMatrix TransformationMatrix::mat_eye()
{ {
return TransformationMatrix();
}
TransformationMatrix TransformationMatrix::mat_translation(double x, double y, double z)
{
return TransformationMatrix( return TransformationMatrix(
1.0f, 0.0f, 0.0f, 0.0f, 1.0, 0.0, 0.0, x,
0.0f, 1.0f, 0.0f, 0.0f, 0.0, 1.0, 0.0, y,
0.0f, 0.0f, 1.0f, 0.0f); 0.0, 0.0, 1.0, z);
} }
TransformationMatrix TransformationMatrix::mat_translation(float x, float y, float z) TransformationMatrix TransformationMatrix::mat_scale(double x, double y, double z)
{ {
return TransformationMatrix( return TransformationMatrix(
1.0f, 0.0f, 0.0f, x, x, 0.0, 0.0, 0.0,
0.0f, 1.0f, 0.0f, y, 0.0, y, 0.0, 0.0,
0.0f, 0.0f, 1.0f, z); 0.0, 0.0, z, 0.0);
} }
TransformationMatrix TransformationMatrix::mat_scale(float x, float y, float z) TransformationMatrix TransformationMatrix::mat_scale(double scale)
{ {
return TransformationMatrix(
x, 0.0f, 0.0f, 0.0f,
0.0f, y, 0.0f, 0.0f,
0.0f, 0.0f, z, 0.0f);
}
TransformationMatrix TransformationMatrix::mat_scale(float scale)
{
return TransformationMatrix::mat_scale(scale, scale, scale); return TransformationMatrix::mat_scale(scale, scale, scale);
} }
TransformationMatrix TransformationMatrix::mat_rotation(float angle_rad, const Axis &axis) TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const Axis &axis)
{ {
float s = sin(angle_rad); double s = sin(angle_rad);
float c = cos(angle_rad); double c = cos(angle_rad);
TransformationMatrix mat; // For RVO TransformationMatrix mat; // For RVO
switch (axis) switch (axis)
{ {
case X: case X:
mat = TransformationMatrix( mat = TransformationMatrix(
1.0f, 0.0f, 0.0f, 0.0f, 1.0, 0.0, 0.0, 0.0,
0.0f, c, s, 0.0f, 0.0, c, s, 0.0,
0.0f, -s, c, 0.0f); 0.0, -s, c, 0.0);
break; break;
case Y: case Y:
mat = TransformationMatrix( mat = TransformationMatrix(
c, 0.0f, -s, 0.0f, c, 0.0, -s, 0.0,
0.0f, 1.0f, 0.0f, 0.0f, 0.0, 1.0, 0.0, 0.0,
s, 0.0f, c, 0.0f); s, 0.0, c, 0.0);
break; break;
case Z: case Z:
mat = TransformationMatrix( mat = TransformationMatrix(
c, s, 0.0f, 0.0f, c, s, 0.0, 0.0,
-s, c, 0.0f, 0.0f, -s, c, 0.0, 0.0,
0.0f, 0.0f, 1.0f, 0.0f); 0.0, 0.0, 1.0, 0.0);
break; break;
default: default:
CONFESS("Invalid Axis supplied to TransformationMatrix::mat_rotation"); CONFESS("Invalid Axis supplied to TransformationMatrix::mat_rotation");
@ -247,14 +248,14 @@ namespace Slic3r {
break; break;
} }
return mat; return mat;
} }
TransformationMatrix TransformationMatrix::mat_rotation(float q1, float q2, float q3, float q4) TransformationMatrix TransformationMatrix::mat_rotation(double q1, double q2, double q3, double q4)
{
double factor = q1*q1 + q2*q2 + q3*q3 + q4*q4;
if (abs(factor - 1.0) > 1e-12)
{ {
float factor = q1*q1 + q2*q2 + q3*q3 + q4*q4; factor = 1.0 / sqrt(factor);
if (abs(factor - 1.0f) > 1e-9)
{
factor = 1.0f / sqrtf(factor);
q1 *= factor; q1 *= factor;
q2 *= factor; q2 *= factor;
q3 *= factor; q3 *= factor;
@ -262,71 +263,120 @@ namespace Slic3r {
} }
// https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Quaternion-derived_rotation_matrix // https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Quaternion-derived_rotation_matrix
return TransformationMatrix( return TransformationMatrix(
1 - 2 * (q2*q2 + q3*q3), 2 * (q1*q2 - q3*q4), 2 * (q1*q3 + q2*q4), 0.0f, 1.0 - 2.0 * (q2*q2 + q3*q3), 2.0 * (q1*q2 - q3*q4), 2.0 * (q1*q3 + q2*q4), 0.0,
2 * (q1*q2 + q3*q4), 1 - 2 * (q1*q1 + q3*q3), 2 * (q2*q3 - q1*q4), 0.0f, 2.0 * (q1*q2 + q3*q4), 1.0 - 2.0 * (q1*q1 + q3*q3), 2.0 * (q2*q3 - q1*q4), 0.0,
2 * (q1*q3 - q2*q4), 2 * (q2*q3 + q1*q4), 1 - 2 * (q1*q1 + q2*q2), 0.0f); 2.0 * (q1*q3 - q2*q4), 2.0 * (q2*q3 + q1*q4), 1.0 - 2.0 * (q1*q1 + q2*q2), 0.0);
} }
TransformationMatrix TransformationMatrix::mat_rotation(float angle_rad, const Pointf3 &axis) TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const Pointf3 &axis)
{ {
float s, factor, q1, q2, q3, q4; double s, factor, q1, q2, q3, q4;
s = sin(angle_rad); s = sin(angle_rad);
TransformationMatrix mat; // For RVO
factor = axis.x*axis.x + axis.y*axis.y + axis.z*axis.z; factor = axis.x*axis.x + axis.y*axis.y + axis.z*axis.z;
factor = 1.0f / sqrtf(factor); factor = s / sqrt(factor);
q1 = s*factor*axis.x; q1 = factor*axis.x;
q2 = s*factor*axis.y; q2 = factor*axis.y;
q3 = s*factor*axis.z; q3 = factor*axis.z;
q4 = cos(angle_rad); q4 = cos(angle_rad);
return mat_rotation(q1, q2, q3, q4); return mat_rotation(q1, q2, q3, q4);
} }
TransformationMatrix TransformationMatrix::mat_mirror(const Axis &axis) TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3 target)
{
TransformationMatrix mat;
double length_sq = origin.x*origin.x + origin.y*origin.y + origin.z*origin.z;
double rec_length;
if (length_sq < 1e-12)
{ {
CONFESS("0-length Vector supplied to TransformationMatrix::mat_rotation(origin,target)");
return mat;
}
rec_length = 1.0 / sqrt(length_sq);
origin.scale(rec_length);
length_sq = target.x*target.x + target.y*target.y + target.z*target.z;
if (length_sq < 1e-12)
{
CONFESS("0-length Vector supplied to TransformationMatrix::mat_rotation(origin,target)");
return mat;
}
rec_length = 1.0 / sqrt(length_sq);
target.scale(rec_length);
Pointf3 cross;
cross.x = origin.y*target.z - origin.z*target.y;
cross.y = origin.z*target.x - origin.x*target.z;
cross.z = origin.x*target.y - origin.y*target.x;
length_sq = cross.x*cross.x + cross.y*cross.y + cross.z*cross.z;
if (length_sq < 1e-12) {// colinear, but maybe opposite directions
double dot = origin.x*target.x + origin.y*target.y + origin.z*target.z;
if (dot > 0.0)
{
return mat; // same direction, nothing to do
}
else
{
Pointf3 help;
// make help garanteed not colinear
if (abs(abs(origin.x) - 1) < 0.02)
help.z = 1.0; // origin mainly in x direction
else
help.x = 1.0;
Pointf3 proj = Pointf3(origin);
// projection of axis onto unit vector origin
dot = origin.x*help.x + origin.y*help.y + origin.z*help.z;
proj.scale(dot);
// help - proj is normal to origin -> rotation axis
// axis is not unit length -> gets normalized in called function
Pointf3 axis = (Pointf3)proj.vector_to(help);
return mat_rotation(PI, axis);
}
}
else
{
}
return mat; // Shouldn't be reached
}
TransformationMatrix TransformationMatrix::mat_mirror(const Axis &axis)
{
TransformationMatrix mat; // For RVO TransformationMatrix mat; // For RVO
switch (axis) switch (axis)
{ {
case X: case X:
mat = TransformationMatrix( mat.m11 = -1.0;
-1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f);
break; break;
case Y: case Y:
mat = TransformationMatrix( mat.m22 = -1.0;
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f);
break; break;
case Z: case Z:
mat = TransformationMatrix( mat.m33 = -1.0;
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, -1.0f, 0.0f);
break; break;
default: default:
CONFESS("Invalid Axis supplied to TransformationMatrix::mat_mirror"); CONFESS("Invalid Axis supplied to TransformationMatrix::mat_mirror");
mat = TransformationMatrix();
break; break;
} }
return mat; return mat;
} }
TransformationMatrix TransformationMatrix::mat_mirror(const Pointf3 &normal) TransformationMatrix TransformationMatrix::mat_mirror(const Pointf3 &normal)
{ {
// Kovács, E. Rotation about arbitrary axis and reflection through an arbitrary plane, Annales Mathematicae // Kovács, E. Rotation about arbitrary axis and reflection through an arbitrary plane, Annales Mathematicae
// et Informaticae, Vol 40 (2012) pp 175-186 // et Informaticae, Vol 40 (2012) pp 175-186
// http://ami.ektf.hu/uploads/papers/finalpdf/AMI_40_from175to186.pdf // http://ami.ektf.hu/uploads/papers/finalpdf/AMI_40_from175to186.pdf
float factor, c1, c2, c3; double factor, c1, c2, c3;
factor = normal.x*normal.x + normal.y*normal.y + normal.z*normal.z; factor = normal.x*normal.x + normal.y*normal.y + normal.z*normal.z;
factor = 1.0f / sqrtf(factor); factor = 1.0 / sqrt(factor);
c1 = factor*normal.x; c1 = factor*normal.x;
c2 = factor*normal.y; c2 = factor*normal.y;
c3 = factor*normal.z; c3 = factor*normal.z;
return TransformationMatrix( return TransformationMatrix(
1 - 2 * c1*c1, -2 * c2*c1, -2 * c3*c1, 0.0f, 1.0 - 2.0 * c1*c1, -2 * c2*c1, -2 * c3*c1, 0.0,
-2 * c2*c1, 1 - 2 * c2*c2, -2 * c2*c3, 0.0f, -2 * c2*c1, 1.0 - 2.0 * c2*c2, -2 * c2*c3, 0.0,
-2 * c1*c3, -2 * c2*c3, 1 - 2 * c3*c3, 0.0f); -2 * c1*c3, -2 * c2*c3, 1.0 - 2.0 * c3*c3, 0.0);
} }
} }

View File

@ -1,10 +1,8 @@
#ifndef slic3r_TriangleMatrix_hpp_ #ifndef slic3r_TriangleMatrix_hpp_
#define slic3r_TriangleMatrix_hpp_ #define slic3r_TriangleMatrix_hpp_
#ifndef Testumgebung
#include "libslic3r.h" #include "libslic3r.h"
#include "Point.hpp" #include "Point.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -12,34 +10,39 @@ class TransformationMatrix
{ {
public: public:
TransformationMatrix(); TransformationMatrix();
#ifndef Testumgebung
TransformationMatrix(std::vector<float> &entries); TransformationMatrix(const std::vector<double> &entries_row_maj);
#endif
TransformationMatrix(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34); TransformationMatrix(
double m11, double m12, double m13, double m14,
double m21, double m22, double m23, double m24,
double m31, double m32, double m33, double m34);
TransformationMatrix(const TransformationMatrix &other); TransformationMatrix(const TransformationMatrix &other);
TransformationMatrix& operator= (TransformationMatrix other); TransformationMatrix& operator= (TransformationMatrix other);
void swap(TransformationMatrix &other); void swap(TransformationMatrix &other);
/// matrix entries /// matrix entries
float m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34; double m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34;
/// Return the row-major form of the represented transformation matrix /// Return the row-major form of the represented transformation matrix
float* matrix3x4f(); /// for admesh transform
float * matrix3x4f();
/// Return the determinante of the matrix /// Return the determinante of the matrix
float determinante(); double determinante();
/// Returns the inverse of the matrix /// Returns the inverse of the matrix
bool inverse(TransformationMatrix * inverse); bool inverse(TransformationMatrix * inverse);
/// Perform Translation /// Perform Translation
void translate(float x, float y, float z); void translate(double x, double y, double z);
/// Perform uniform scale /// Perform uniform scale
void scale(float factor); void scale(double factor);
/// Perform per-axis scale /// Perform per-axis scale
void scale(float x, float y, float z); void scale(double x, double y, double z);
/// Perform mirroring along given axis /// Perform mirroring along given axis
void mirror(const Axis &axis); void mirror(const Axis &axis);
@ -48,28 +51,28 @@ public:
void mirror(const Pointf3 &normal); void mirror(const Pointf3 &normal);
/// Perform rotation around given axis /// Perform rotation around given axis
void rotate(float angle_rad, const Axis &axis); void rotate(double angle_rad, const Axis &axis);
/// Perform rotation around arbitrary axis /// Perform rotation around arbitrary axis
void rotate(float angle_rad, const Pointf3 &axis); void rotate(double angle_rad, const Pointf3 &axis);
/// Perform rotation defined by unit quaternion /// Perform rotation defined by unit quaternion
void rotate(float q1, float q2, float q3, float q4); void rotate(double q1, double q2, double q3, double q4);
/// Multiplies the Parameter-Matrix from the left (this=left*this) /// Multiplies the Parameter-Matrix from the left (this=left*this)
void multiplyLeft(TransformationMatrix &left); void multiplyLeft(const TransformationMatrix &left);
/// Multiplies the Parameter-Matrix from the right (this=this*right) /// Multiplies the Parameter-Matrix from the right (this=this*right)
void multiplyRight(TransformationMatrix &right); void multiplyRight(const TransformationMatrix &right);
/// Generate an eye matrix. /// Generate an eye matrix.
static TransformationMatrix mat_eye(); static TransformationMatrix mat_eye();
/// Generate a per axis scaling matrix /// Generate a per axis scaling matrix
static TransformationMatrix mat_scale(float x, float y, float z); static TransformationMatrix mat_scale(double x, double y, double z);
/// Generate a uniform scaling matrix /// Generate a uniform scaling matrix
static TransformationMatrix mat_scale(float scale); static TransformationMatrix mat_scale(double scale);
/// Generate a reflection matrix by coordinate axis /// Generate a reflection matrix by coordinate axis
static TransformationMatrix mat_mirror(const Axis &axis); static TransformationMatrix mat_mirror(const Axis &axis);
@ -78,16 +81,20 @@ public:
static TransformationMatrix mat_mirror(const Pointf3 &normal); static TransformationMatrix mat_mirror(const Pointf3 &normal);
/// Generate a translation matrix /// Generate a translation matrix
static TransformationMatrix mat_translation(float x, float y, float z); static TransformationMatrix mat_translation(double x, double y, double z);
/// Generate a rotation matrix around coodinate axis /// Generate a rotation matrix around coodinate axis
static TransformationMatrix mat_rotation(float angle_rad, const Axis &axis); static TransformationMatrix mat_rotation(double angle_rad, const Axis &axis);
/// Generate a rotation matrix defined by unit quaternion q1*i + q2*j + q3*k + q4 /// Generate a rotation matrix defined by unit quaternion q1*i + q2*j + q3*k + q4
static TransformationMatrix mat_rotation(float q1, float q2, float q3, float q4); static TransformationMatrix mat_rotation(double q1, double q2, double q3, double q4);
/// Generate a rotation matrix around arbitrary axis /// Generate a rotation matrix around arbitrary axis
static TransformationMatrix mat_rotation(float angle_rad, const Pointf3 &axis); static TransformationMatrix mat_rotation(double angle_rad, const Pointf3 &axis);
/// Generate a rotation matrix by specifying a vector (origin) that is to be rotated
/// to be colinear with another vector (target)
static TransformationMatrix mat_rotation(Pointf3 origin, Pointf3 target);
/// Performs a matrix multiplication /// Performs a matrix multiplication
static TransformationMatrix multiply(const TransformationMatrix &left, const TransformationMatrix &right); static TransformationMatrix multiply(const TransformationMatrix &left, const TransformationMatrix &right);