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