MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMatrix3Decompose.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMatrix3.h"
4
5namespace MR
6{
9
10
15template <typename T>
16void decomposeMatrix3( const Matrix3<T>& m, Matrix3<T>& rotation, Matrix3<T>& scaling, bool signedScale = false )
17{
18 const auto [q, r] = m.qr();
19
20 scaling = {};
21 Matrix3<T> sign;
22 for ( int i = 0; i < 3; ++i )
23 {
24 scaling[i][i] = std::abs( r[i][i] );
25 if ( r[i][i] < 0 )
26 sign[i][i] = -1;
27 }
28 rotation = q * sign;
29 if ( signedScale && rotation.det() < 0 )
30 {
32 int j = 0;
33 for ( int i = 1; i < 3; ++i )
34 if ( rotation[i][i] < rotation[j][j] )
35 j = i;
36 for ( int i = 0; i < 3; ++i )
37 rotation[i][j] = -rotation[i][j];
38 scaling[j][j] = -scaling[j][j];
39 }
40}
41
43template <typename T>
44bool isRigid( const Matrix3<T>& m )
45{
46 Matrix3<T> rot, scale;
47 decomposeMatrix3( m, rot, scale );
48 auto eps = T( 10 ) * std::numeric_limits<T>::epsilon();
49 if ( std::abs( scale.x.x - T( 1 ) ) > eps )
50 return false;
51 if ( std::abs( scale.y.y - T( 1 ) ) > eps )
52 return false;
53 if ( std::abs( scale.z.z - T( 1 ) ) > eps )
54 return false;
55 return true;
56}
57
58}
void decomposeMatrix3(const Matrix3< T > &m, Matrix3< T > &rotation, Matrix3< T > &scaling, bool signedScale=false)
Definition MRMatrix3Decompose.h:16
constexpr T det() const noexcept
computes determinant of the matrix
bool isRigid(const Matrix3< T > &m)
Returns true if matrix scale is identity.
Definition MRMatrix3Decompose.h:44
QR qr() const noexcept
decompose this matrix on the product Q*R, where Q is orthogonal and R is upper triangular
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRMatrix3.h:24