36 constexpr T
det() const noexcept;
47 if constexpr ( std::is_integral_v<T> )
48 {
xx /= b;
xy /= b;
xz /= b;
yy /= b;
yz /= b;
zz /= b;
return *
this; }
50 return *
this *= ( 1 / b );
77 a.xx * b.
x + a.xy * b.y + a.xz * b.z,
78 a.xy * b.x + a.yy * b.y + a.yz * b.z,
79 a.xz * b.x + a.yz * b.y + a.zz * b.z
101 const auto ka = k * a;
132 {
return !( a == b ); }
152 { b /= a;
return b; }
186Vector3<T> SymMatrix3<T>::eigens( Matrix3<T> * eigenvectors )
const MR_REQUIRES_IF_SUPPORTED( std::is_floating_point_v<T> )
189 const auto q =
trace() / 3;
190 const auto B = *
this -
diagonal( q );
191 const auto p2 = B.normSq();
192 const auto p = std::sqrt( p2 / 6 );
194 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
199 *eigenvectors = Matrix3<T>{};
202 const auto r = B.det() / ( 2 * p * p * p );
210 eig[1] = eig[2] = q + p;
213 const auto x = eigenvector( eig[0] ).normalized();
214 const auto [ y, z ] = x.perpendicular();
222 eig[0] = eig[1] = q - p;
226 const auto z = eigenvector( eig[2] ).normalized();
227 const auto [ x, y ] = z.perpendicular();
232 const auto phi = std::acos( r ) / 3;
233 eig[0] = q + 2 * p * cos( phi + T( 2 * PI / 3 ) );
234 eig[2] = q + 2 * p * cos( phi );
235 eig[1] = 3 * q - eig[0] - eig[2];
238 const auto x = eigenvector( eig[0] ).normalized();
239 const auto z = eigenvector( eig[2] ).normalized();
240 const auto y =
cross( z, x );
249 const Vector3<T> row0(
xx - eigenvalue,
xy,
xz );
250 const Vector3<T> row1(
xy,
yy - eigenvalue,
yz );
251 const Vector3<T> row2(
xz,
yz,
zz - eigenvalue );
253 const Vector3<T> crs01 =
cross( row0, row1 );
254 const Vector3<T> crs12 =
cross( row1, row2 );
255 const Vector3<T> crs20 =
cross( row2, row0 );
256 const T lsq01 = crs01.lengthSq();
257 const T lsq12 = crs12.lengthSq();
258 const T lsq20 = crs20.lengthSq();
264 else if ( lsq12 > lsq20 )
273 Matrix3<T> eigenvectors;
274 const auto eigenvalues = eigens( &eigenvectors );
275 const auto threshold = std::max( std::abs( eigenvalues[0] ), std::abs( eigenvalues[2] ) ) * tol;
277 for (
int i = 0; i < 3; ++i )
279 if ( std::abs( eigenvalues[i] ) <= threshold )
281 res +=
outerSquare( 1 / eigenvalues[i], eigenvectors[i] );
286 *space = eigenvectors[i];
287 else if ( myRank == 2 )
288 *space =
cross( *space, eigenvectors[i] );
290 *space = Vector3<T>{};
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:34
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:442
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...
Definition MRCameraOrientationPlugin.h:8
constexpr T sqr(T x) noexcept
squared value
Definition MRMeshFwd.h:752
bool operator!=(const Color &a, const Color &b)
Definition MRMesh/MRColor.h:101
Color operator/(const Color &b, float a)
Definition MRMesh/MRColor.h:126
Color operator+(const Color &a, const Color &b)
Definition MRMesh/MRColor.h:106
float cross(Vector2f a, Vector2f b)
Definition MRMesh/MRMatrix3.h:21
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:59
Definition MRSymMatrix3.h:15
static constexpr SymMatrix3 identity() noexcept
Definition MRSymMatrix3.h:28
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:116
constexpr SymMatrix3() noexcept=default
SymMatrix3< T > outerSquare(const Vector3< T > &a)
x = a * a^T
Definition MRSymMatrix3.h:85
T yz
Definition MRSymMatrix3.h:19
SymMatrix3 & operator+=(const SymMatrix3< T > &b)
Definition MRSymMatrix3.h:42
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:44
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:32
SymMatrix3 & operator-=(const SymMatrix3< T > &b)
Definition MRSymMatrix3.h:43
static constexpr SymMatrix3 diagonal(T diagVal) noexcept
Definition MRSymMatrix3.h:29
T zz
Definition MRSymMatrix3.h:19
constexpr SymMatrix3< T > inverse() const noexcept
computes inverse matrix
Definition MRSymMatrix3.h:38
T yy
Definition MRSymMatrix3.h:19
SymMatrix3< T > outerSquare(T k, const Vector3< T > &a)
x = k * a * a^T
Definition MRSymMatrix3.h:99
SymMatrix3 & operator/=(T b)
Definition MRSymMatrix3.h:45
Vector3< T > operator*(const SymMatrix3< T > &a, const Vector3< T > &b)
x = a * b
Definition MRSymMatrix3.h:73
Definition MRMesh/MRVector3.h:30
T x
Definition MRMesh/MRVector3.h:36
T y
Definition MRMesh/MRVector3.h:36
T z
Definition MRMesh/MRVector3.h:36
T lengthSq() const
Definition MRMesh/MRVector3.h:65