mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-04 05:40:39 +08:00
rewrite functionality of inverse function
This commit is contained in:
parent
d7c1f8bad8
commit
4f4abe3350
@ -83,17 +83,20 @@ double TransformationMatrix::determinante() const
|
||||
return m11*(m22*m33 - m23*m32) - m12*(m21*m33 - m23*m31) + m13*(m21*m32 - m31*m22);
|
||||
}
|
||||
|
||||
bool TransformationMatrix::inverse(TransformationMatrix &inverse) const
|
||||
TransformationMatrix TransformationMatrix::inverse() const
|
||||
{
|
||||
// from http://mathworld.wolfram.com/MatrixInverse.html
|
||||
// and https://math.stackexchange.com/questions/152462/inverse-of-transformation-matrix
|
||||
double det = this->determinante();
|
||||
if (abs(det) < 1e-9)
|
||||
{
|
||||
return false;
|
||||
printf("Matrix (very close to) singular. Inverse cannot be computed");
|
||||
return TransformationMatrix();
|
||||
}
|
||||
double fac = 1.0 / det;
|
||||
|
||||
TransformationMatrix inverse;
|
||||
|
||||
inverse.m11 = fac * (this->m22 * this->m33 - this->m23 * this->m32);
|
||||
inverse.m12 = fac * (this->m13 * this->m32 - this->m12 * this->m33);
|
||||
inverse.m13 = fac * (this->m12 * this->m23 - this->m13 * this->m22);
|
||||
@ -108,7 +111,7 @@ bool TransformationMatrix::inverse(TransformationMatrix &inverse) const
|
||||
inverse.m24 = -(inverse.m21 * this->m14 + inverse.m22 * this->m24 + inverse.m23 * this->m34);
|
||||
inverse.m34 = -(inverse.m31 * this->m14 + inverse.m32 * this->m24 + inverse.m33 * this->m34);
|
||||
|
||||
return true;
|
||||
return inverse;
|
||||
}
|
||||
|
||||
void TransformationMatrix::applyLeft(const TransformationMatrix &left)
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
double determinante() const;
|
||||
|
||||
/// returns the inverse of the matrix
|
||||
bool inverse(TransformationMatrix &inverse) const;
|
||||
TransformationMatrix inverse() const;
|
||||
|
||||
/// multiplies the parameter-matrix from the left (this=left*this)
|
||||
void applyLeft(const TransformationMatrix &left);
|
||||
|
Loading…
x
Reference in New Issue
Block a user