32 constexpr T
det() const noexcept;
43 if constexpr ( std::is_integral_v<T> )
44 {
xx /= b;
xy /= b;
xz /= b;
yy /= b;
yz /= b;
zz /= b;
return *
this; }
46 return *
this *= ( 1 / b );
73 a.xx * b.
x + a.xy * b.y + a.xz * b.z,
74 a.xy * b.x + a.yy * b.y + a.yz * b.z,
75 a.xz * b.x + a.yz * b.y + a.zz * b.z
97 const auto ka = k * a;
128 {
return !( a == b ); }
148 { b /= a;
return b; }
185 const auto q =
trace() / 3;
186 const auto B = *
this -
diagonal( q );
187 const auto p2 = B.normSq();
188 const auto p = std::sqrt( p2 / 6 );
190 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
195 *eigenvectors = Matrix3<T>{};
198 const auto r = B.det() / ( 2 * p * p * p );
206 eig[1] = eig[2] = q + p;
209 const auto x = eigenvector( eig[0] ).normalized();
210 const auto [ y, z ] = x.perpendicular();
218 eig[0] = eig[1] = q - p;
222 const auto z = eigenvector( eig[2] ).normalized();
223 const auto [ x, y ] = z.perpendicular();
228 const auto phi = std::acos( r ) / 3;
229 eig[0] = q + 2 * p * cos( phi + T( 2 * PI / 3 ) );
230 eig[2] = q + 2 * p * cos( phi );
231 eig[1] = 3 * q - eig[0] - eig[2];
234 const auto x = eigenvector( eig[0] ).normalized();
235 const auto z = eigenvector( eig[2] ).normalized();
236 const auto y = cross( z, x );
252 const T lsq01 = crs01.lengthSq();
253 const T lsq12 = crs12.lengthSq();
254 const T lsq20 = crs20.lengthSq();
260 else if ( lsq12 > lsq20 )
269 Matrix3<T> eigenvectors;
270 const auto eigenvalues = eigens( &eigenvectors );
271 const auto threshold = std::max( std::abs( eigenvalues[0] ), std::abs( eigenvalues[2] ) ) * tol;
273 for (
int i = 0; i < 3; ++i )
275 if ( std::abs( eigenvalues[i] ) <= threshold )
277 res +=
outerSquare( 1 / eigenvalues[i], eigenvectors[i] );
282 *space = eigenvectors[i];
283 else if ( myRank == 2 )
284 *space = cross( *space, eigenvectors[i] );
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:29
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:342
MRMESH_API bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
bool operator!=(const SetBitIteratorT< T > &a, const SetBitIteratorT< T > &b)
Definition MRMesh/MRBitSet.h:276
Definition MRCameraOrientationPlugin.h:8
constexpr T sqr(T x) noexcept
Definition MRMesh/MRMeshFwd.h:600
Color operator/(const Color &b, float a)
Definition MRColor.h:128
MRMESH_CLASS Vector3
Definition MRMesh/MRMeshFwd.h:137
Color operator+(const Color &a, const Color &b)
Definition MRColor.h:108
Definition MRMesh/MRMatrix3.h:13
static constexpr Matrix3 static rotation(const Vector3< T > &axis, T angle) noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix3 static rotation(const Vector3< T > &from, const Vector3< T > &to) noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix3 static rotationFromEuler(const Vector3< T > &eulerAngles) noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix3 static approximateLinearRotationMatrixFromEuler(const Vector3< T > &eulerAngles) noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix fromRows)(const Vector3< T > &x, const Vector3< T > &y, const Vector3< T > &z) noexcept
creates matrix representing rotation around given axis on given angle
Definition MRMesh/MRMatrix3.h:44
Definition MRSymMatrix3.h:15
static constexpr SymMatrix3 identity() noexcept
Definition MRSymMatrix3.h:24
constexpr T det() const noexcept
computes determinant of the matrix
T xy
Definition MRSymMatrix3.h:19
T ValueType
Definition MRSymMatrix3.h:16
SymMatrix3< T > crossSquare(const Vector3< T > &a)
Definition MRSymMatrix3.h:112
constexpr SymMatrix3() noexcept=default
SymMatrix3< T > outerSquare(const Vector3< T > &a)
x = a * a^T
Definition MRSymMatrix3.h:81
T yz
Definition MRSymMatrix3.h:19
SymMatrix3 & operator+=(const SymMatrix3< T > &b)
Definition MRSymMatrix3.h:38
constexpr T normSq() const noexcept
computes the squared norm of the matrix, which is equal to the sum of 9 squared elements
T xz
Definition MRSymMatrix3.h:19
T xx
zero matrix by default
Definition MRSymMatrix3.h:19
SymMatrix3 & operator*=(T b)
Definition MRSymMatrix3.h:40
constexpr SymMatrix3< T > inverse(T det) const noexcept
computes inverse matrix given determinant of this
constexpr T trace() const noexcept
computes trace of the matrix
Definition MRSymMatrix3.h:28
SymMatrix3 & operator-=(const SymMatrix3< T > &b)
Definition MRSymMatrix3.h:39
static constexpr SymMatrix3 diagonal(T diagVal) noexcept
Definition MRSymMatrix3.h:25
T zz
Definition MRSymMatrix3.h:19
constexpr SymMatrix3< T > inverse() const noexcept
computes inverse matrix
Definition MRSymMatrix3.h:34
T yy
Definition MRSymMatrix3.h:19
SymMatrix3< T > outerSquare(T k, const Vector3< T > &a)
x = k * a * a^T
Definition MRSymMatrix3.h:95
SymMatrix3 & operator/=(T b)
Definition MRSymMatrix3.h:41
Vector3< T > operator*(const SymMatrix3< T > &a, const Vector3< T > &b)
x = a * b
Definition MRSymMatrix3.h:69
Definition MRMesh/MRVector3.h:19
T x
Definition MRMesh/MRVector3.h:25
T y
Definition MRMesh/MRVector3.h:25
T z
Definition MRMesh/MRVector3.h:25
T lengthSq() const
Definition MRMesh/MRVector3.h:46