31 constexpr T
trace() const noexcept {
return xx +
yy; }
35 constexpr T
det() const noexcept;
46 if constexpr ( std::is_integral_v<T> )
47 {
xx /= b;
xy /= b;
yy /= b;
return *
this; }
49 return *
this *= ( 1 / b );
78 a.xx * b.
x + a.xy * b.y,
79 a.xy * b.x + a.yy * b.y
98 const auto ka = k * a;
112 {
return !( a == b ); }
132 { b /= a;
return b; }
153Vector2<T> SymMatrix2<T>::eigens( Matrix2<T> * eigenvectors )
const MR_REQUIRES_IF_SUPPORTED( std::is_floating_point_v<T> )
156 const auto tr =
trace();
157 const auto q = tr / 2;
158 const auto p = std::sqrt( std::max( T(0),
sqr( tr ) - 4 *
det() ) ) / 2;
160 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
165 *eigenvectors = Matrix2<T>{};
172 const auto x = eigenvector( eig[0] ).normalized();
181 const Vector2<T> row0(
xx - eigenvalue,
xy );
182 const Vector2<T> row1(
xy,
yy - eigenvalue );
184 const T lsq0 = row0.lengthSq();
185 const T lsq1 = row1.lengthSq();
186 return lsq0 >= lsq1 ? row0.perpendicular() : row1.perpendicular();
192 const auto tr =
trace();
193 const auto q = tr / 2;
194 const auto p = std::sqrt( std::max( T(0),
sqr( tr ) - 4 *
det() ) ) / 2;
195 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
198 return Vector2<T>( T(1), T(0) );
200 return eigenvector( q + p );
207 Matrix2<T> eigenvectors;
208 const auto eigenvalues = eigens( &eigenvectors );
209 const auto threshold = std::max( std::abs( eigenvalues[0] ), std::abs( eigenvalues[1] ) ) * tol;
211 for (
int i = 0; i < 2; ++i )
213 if ( std::abs( eigenvalues[i] ) <= threshold )
215 res +=
outerSquare( 1 / eigenvalues[i], eigenvectors[i] );
220 *space = eigenvectors[i];
222 *space = Vector2<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
Definition MRMatrix2.h:21
static constexpr Matrix2 static rotation(T angle) noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix2 static rotation(const Vector2< T > &from, const Vector2< T > &to) noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix fromRows)(const Vector2< T > &x, const Vector2< T > &y) noexcept
creates matrix representing rotation around origin on given angle
Definition MRMatrix2.h:49
Definition MRSymMatrix2.h:14
SymMatrix2 & operator-=(const SymMatrix2< T > &b)
Definition MRSymMatrix2.h:42
constexpr SymMatrix2() noexcept=default
constexpr SymMatrix2< T > inverse() const noexcept
computes inverse matrix
Definition MRSymMatrix2.h:37
T ValueType
Definition MRSymMatrix2.h:15
constexpr T trace() const noexcept
computes trace of the matrix
Definition MRSymMatrix2.h:31
T xy
Definition MRSymMatrix2.h:18
static constexpr SymMatrix2 diagonal(T diagVal) noexcept
Definition MRSymMatrix2.h:28
T yy
Definition MRSymMatrix2.h:18
static constexpr SymMatrix2 identity() noexcept
Definition MRSymMatrix2.h:27
constexpr SymMatrix2< T > inverse(T det) const noexcept
computes inverse matrix given determinant of this
SymMatrix2 & operator*=(T b)
Definition MRSymMatrix2.h:43
SymMatrix2< T > outerSquare(T k, const Vector2< T > &a)
x = k * a * a^T
Definition MRSymMatrix2.h:96
SymMatrix2< T > outerSquare(const Vector2< T > &a)
x = a * a^T
Definition MRSymMatrix2.h:85
Vector2< T > operator*(const SymMatrix2< T > &a, const Vector2< T > &b)
x = a * b
Definition MRSymMatrix2.h:74
SymMatrix2 & operator/=(T b)
Definition MRSymMatrix2.h:44
constexpr T det() const noexcept
computes determinant of the matrix
SymMatrix2 & operator+=(const SymMatrix2< T > &b)
Definition MRSymMatrix2.h:41
constexpr T normSq() const noexcept
computes the squared norm of the matrix, which is equal to the sum of 4 squared elements
Definition MRSymMatrix2.h:33
T xx
zero matrix by default
Definition MRSymMatrix2.h:18
Definition MRVector2.h:29
T x
Definition MRVector2.h:35
T y
Definition MRVector2.h:35