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
12template <typename T>
13void decomposeMatrix3( const Matrix3<T>& m, Matrix3<T>& rotation, Matrix3<T>& scaling )
14{
15 const auto [q, r] = m.qr();
16
17 scaling = {};
18 Matrix3<T> sign;
19 for ( int i = 0; i < 3; ++i )
20 {
21 scaling[i][i] = std::abs( r[i][i] );
22 if ( r[i][i] < 0 )
23 sign[i][i] = -1;
24 }
25 rotation = q * sign;
26}
27
29template <typename T>
30bool isRigid( const Matrix3<T>& m )
31{
32 Matrix3<T> rot, scale;
33 decomposeMatrix3( m, rot, scale );
34 auto eps = T( 10 ) * std::numeric_limits<T>::epsilon();
35 if ( std::abs( scale.x.x - T( 1 ) ) > eps )
36 return false;
37 if ( std::abs( scale.y.y - T( 1 ) ) > eps )
38 return false;
39 if ( std::abs( scale.z.z - T( 1 ) ) > eps )
40 return false;
41 return true;
42}
43
44}
void decomposeMatrix3(const Matrix3< T > &m, Matrix3< T > &rotation, Matrix3< T > &scaling)
Decomposes matrix into rotation and scaling matrices.
Definition MRMatrix3Decompose.h:13
bool isRigid(const Matrix3< T > &m)
Returns true if matrix scale is identity.
Definition MRMatrix3Decompose.h:30
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMatrix3.h:24