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; }
193 const auto q =
trace() / 3;
194 const auto B = *
this -
diagonal( q );
195 const auto p2 = B.normSq();
196 const auto p = std::sqrt( p2 / 6 );
198 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
206 const auto r = B.det() / ( 2 * p * p * p );
214 eig[1] = eig[2] = q + p;
218 const auto [ y, z ] = x.perpendicular();
226 eig[0] = eig[1] = q - p;
231 const auto [ x, y ] = z.perpendicular();
236 const auto phi = std::acos( r ) / 3;
237 eig[0] = q + 2 * p * cos( phi + T( 2 * PI / 3 ) );
238 eig[2] = q + 2 * p * cos( phi );
239 eig[1] = 3 * q - eig[0] - eig[2];
244 const auto y =
cross( z, x );
253 const Vector3<T> row0(
xx - eigenvalue,
xy,
xz );
254 const Vector3<T> row1(
xy,
yy - eigenvalue,
yz );
255 const Vector3<T> row2(
xz,
yz,
zz - eigenvalue );
257 const Vector3<T> crs01 =
cross( row0, row1 );
258 const Vector3<T> crs12 =
cross( row1, row2 );
259 const Vector3<T> crs20 =
cross( row2, row0 );
260 const T lsq01 = crs01.lengthSq();
261 const T lsq12 = crs12.lengthSq();
262 const T lsq20 = crs20.lengthSq();
268 else if ( lsq12 > lsq20 )
288 const auto d =
xx * myz +
xy * cxy +
xz * cxz;
290 if ( d > 0 && d > std::max( tol, T( 1e-4 ) ) *
trace() * ( mxy + mxz + myz ) )
295 *space = Vector3<T>{};
311 const auto eigenvalues =
eigens( &eigenvectors );
312 const auto threshold = std::max( std::abs( eigenvalues[0] ), std::abs( eigenvalues[2] ) ) * tol;
314 for (
int i = 0; i < 3; ++i )
316 if ( std::abs( eigenvalues[i] ) <= threshold )
318 res +=
outerSquare( 1 / eigenvalues[i], eigenvectors[i] );
323 *space = eigenvectors[i];
324 else if ( myRank == 2 )
325 *space =
cross( *space, eigenvectors[i] );
327 *space = Vector3<T>{};
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:33
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:507
static constexpr SymMatrix3 identity() noexcept
Definition MRSymMatrix3.h:31
bool operator==(const Allocator< T > &, const Allocator< U > &) noexcept
Definition MRAllocator.h:93
SymMatrix3< T > pseudoinverse(T tol=std::numeric_limits< T >::epsilon(), int *rank=nullptr, Vector3< T > *space=nullptr) const
static constexpr Matrix3 fromRows(const Vector3< T > &x, const Vector3< T > &y, const Vector3< T > &z) noexcept
constructs a matrix from its 3 rows
Definition MRMatrix3.h:62
constexpr auto sqr(T x) noexcept -> decltype(x *x)
squared value; the result type is the type of x*x, which is int for small integer types (char,...
Definition MRMeshFwd.h:800
constexpr T det() const noexcept
computes determinant of the matrix
T xy
Definition MRSymMatrix3.h:22
T x
Definition MRVector3.h:39
auto lengthSq() const -> decltype(std::declval< T >() *std::declval< T >())
Definition MRVector3.h:68
T ValueType
Definition MRSymMatrix3.h:19
T y
Definition MRVector3.h:39
constexpr SymMatrix3 & operator/=(T b)
Definition MRSymMatrix3.h:48
bool operator!=(const Color &a, const Color &b)
Definition MRColor.h:107
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:132
Vector3< T > eigens(Matrix3< T > *eigenvectors=nullptr) const
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
constexpr SymMatrix3 & operator*=(T b)
Definition MRSymMatrix3.h:47
T xx
zero matrix by default
Definition MRSymMatrix3.h:22
Matrix3
Definition MRMeshFwd.h:227
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
Vector3< T > eigenvector(T eigenvalue) const
computes not-unit eigenvector corresponding to a not-repeating eigenvalue
static constexpr SymMatrix3 diagonal(T diagVal) noexcept
Definition MRSymMatrix3.h:32
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
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:112
Vector3< T > operator*(const SymMatrix3< T > &a, const Vector3< T > &b)
x = a * b
Definition MRSymMatrix3.h:76
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRMatrix3.h:24
Definition MRSymMatrix3.h:18
auto cross(const Vector2< T > &a, const Vector2< T > &b) -> decltype(a.x *b.x)
cross product
Definition MRVector2.h:160
Definition MRVector3.h:33