39 constexpr T
det() const noexcept;
50 if constexpr ( std::is_integral_v<T> )
51 {
xx /= b;
xy /= b;
xz /= b;
yy /= b;
yz /= b;
zz /= b;
return *
this; }
53 return *
this *= ( 1 / b );
80 a.xx * b.
x + a.xy * b.y + a.xz * b.z,
81 a.xy * b.x + a.yy * b.y + a.yz * b.z,
82 a.xz * b.x + a.yz * b.y + a.zz * b.z
104 const auto ka = k * a;
135 {
return !( a == b ); }
155 { b /= a;
return b; }
169 return sqr(
xx ) + sqr(
yy ) + sqr(
zz ) +
170 2 * ( sqr(
xy ) + sqr(
xz ) + sqr(
yz ) );
189Vector3<T> SymMatrix3<T>::eigens( Matrix3<T> * eigenvectors )
const MR_REQUIRES_IF_SUPPORTED( std::is_floating_point_v<T> )
192 const auto q =
trace() / 3;
193 const auto B = *
this -
diagonal( q );
194 const auto p2 = B.normSq();
195 const auto p = std::sqrt( p2 / 6 );
197 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
202 *eigenvectors = Matrix3<T>{};
205 const auto r = B.det() / ( 2 * p * p * p );
213 eig[1] = eig[2] = q + p;
216 const auto x = eigenvector( eig[0] ).normalized();
217 const auto [ y, z ] = x.perpendicular();
225 eig[0] = eig[1] = q - p;
229 const auto z = eigenvector( eig[2] ).normalized();
230 const auto [ x, y ] = z.perpendicular();
235 const auto phi = std::acos( r ) / 3;
236 eig[0] = q + 2 * p * cos( phi + T( 2 * PI / 3 ) );
237 eig[2] = q + 2 * p * cos( phi );
238 eig[1] = 3 * q - eig[0] - eig[2];
241 const auto x = eigenvector( eig[0] ).normalized();
242 const auto z = eigenvector( eig[2] ).normalized();
243 const auto y = cross( z, x );
252 const Vector3<T> row0(
xx - eigenvalue,
xy,
xz );
253 const Vector3<T> row1(
xy,
yy - eigenvalue,
yz );
254 const Vector3<T> row2(
xz,
yz,
zz - eigenvalue );
256 const Vector3<T> crs01 = cross( row0, row1 );
257 const Vector3<T> crs12 = cross( row1, row2 );
258 const Vector3<T> crs20 = cross( row2, row0 );
259 const T lsq01 = crs01.lengthSq();
260 const T lsq12 = crs12.lengthSq();
261 const T lsq20 = crs20.lengthSq();
267 else if ( lsq12 > lsq20 )
276 Matrix3<T> eigenvectors;
277 const auto eigenvalues = eigens( &eigenvectors );
278 const auto threshold = std::max( std::abs( eigenvalues[0] ), std::abs( eigenvalues[2] ) ) * tol;
280 for (
int i = 0; i < 3; ++i )
282 if ( std::abs( eigenvalues[i] ) <= threshold )
284 res +=
outerSquare( 1 / eigenvalues[i], eigenvectors[i] );
289 *space = eigenvectors[i];
290 else if ( myRank == 2 )
291 *space = cross( *space, eigenvectors[i] );
293 *space = Vector3<T>{};
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:34
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:457
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...
static constexpr SymMatrix3 identity() noexcept
Definition MRSymMatrix3.h:31
constexpr T det() const noexcept
computes determinant of the matrix
T xy
Definition MRSymMatrix3.h:22
T x
Definition MRVector3.h:39
T ValueType
Definition MRSymMatrix3.h:19
T y
Definition MRVector3.h:39
bool operator!=(const Color &a, const Color &b)
Definition MRColor.h:104
SymMatrix3< T > crossSquare(const Vector3< T > &a)
Definition MRSymMatrix3.h:119
constexpr SymMatrix3() noexcept=default
SymMatrix3< T > outerSquare(const Vector3< T > &a)
x = a * a^T
Definition MRSymMatrix3.h:88
Color operator/(const Color &b, float a)
Definition MRColor.h:129
T yz
Definition MRSymMatrix3.h:22
SymMatrix3 & operator+=(const SymMatrix3< T > &b)
Definition MRSymMatrix3.h:45
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:22
T xx
zero matrix by default
Definition MRSymMatrix3.h:22
SymMatrix3 & operator*=(T b)
Definition MRSymMatrix3.h:47
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:35
SymMatrix3 & operator-=(const SymMatrix3< T > &b)
Definition MRSymMatrix3.h:46
static constexpr SymMatrix3 diagonal(T diagVal) noexcept
Definition MRSymMatrix3.h:32
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 MRMatrix3.h:62
T zz
Definition MRSymMatrix3.h:22
constexpr SymMatrix3< T > inverse() const noexcept
computes inverse matrix
Definition MRSymMatrix3.h:41
T z
Definition MRVector3.h:39
T yy
Definition MRSymMatrix3.h:22
T lengthSq() const
Definition MRVector3.h:68
SymMatrix3< T > outerSquare(T k, const Vector3< T > &a)
x = k * a * a^T
Definition MRSymMatrix3.h:102
Color operator+(const Color &a, const Color &b)
Definition MRColor.h:109
SymMatrix3 & operator/=(T b)
Definition MRSymMatrix3.h:48
Vector3< T > operator*(const SymMatrix3< T > &a, const Vector3< T > &b)
x = a * b
Definition MRSymMatrix3.h:76
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMatrix3.h:24
Definition MRSymMatrix3.h:18
Definition MRVector3.h:33