27 constexpr T
trace() const noexcept {
return xx +
yy; }
31 constexpr T
det() const noexcept;
42 if constexpr ( std::is_integral_v<T> )
43 {
xx /= b;
xy /= b;
yy /= b;
return *
this; }
45 return *
this *= ( 1 / b );
74 a.xx * b.
x + a.xy * b.y,
75 a.xy * b.x + a.yy * b.y
94 const auto ka = k * a;
108 {
return !( a == b ); }
128 { b /= a;
return b; }
152 const auto tr =
trace();
153 const auto q = tr / 2;
154 const auto p = std::sqrt( std::max( T(0),
sqr( tr ) - 4 *
det() ) ) / 2;
156 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
168 const auto x = eigenvector( eig[0] ).normalized();
177 const Vector2<T> row0(
xx - eigenvalue,
xy );
178 const Vector2<T> row1(
xy,
yy - eigenvalue );
180 const T lsq0 = row0.lengthSq();
181 const T lsq1 = row1.lengthSq();
182 return lsq0 >= lsq1 ? row0.perpendicular() : row1.perpendicular();
188 const auto tr =
trace();
189 const auto q = tr / 2;
190 const auto p = std::sqrt( std::max( T(0),
sqr( tr ) - 4 *
det() ) ) / 2;
191 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
194 return Vector2<T>( T(1), T(0) );
196 return eigenvector( q + p );
204 const auto eigenvalues = eigens( &eigenvectors );
205 const auto threshold = std::max( std::abs( eigenvalues[0] ), std::abs( eigenvalues[1] ) ) * tol;
207 for (
int i = 0; i < 2; ++i )
209 if ( std::abs( eigenvalues[i] ) <= threshold )
211 res +=
outerSquare( 1 / eigenvalues[i], eigenvectors[i] );
216 *space = eigenvectors[i];
218 *space = Vector2<T>{};
#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
MRMESH_CLASS Vector3< double > Matrix2
Definition MRMesh/MRMeshFwd.h:153
Color operator/(const Color &b, float a)
Definition MRColor.h:128
Color operator+(const Color &a, const Color &b)
Definition MRColor.h:108
Definition MRMatrix2.h:13
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:38
Definition MRSymMatrix2.h:14
SymMatrix2 & operator-=(const SymMatrix2< T > &b)
Definition MRSymMatrix2.h:38
constexpr SymMatrix2() noexcept=default
constexpr SymMatrix2< T > inverse() const noexcept
computes inverse matrix
Definition MRSymMatrix2.h:33
T ValueType
Definition MRSymMatrix2.h:15
constexpr T trace() const noexcept
computes trace of the matrix
Definition MRSymMatrix2.h:27
T xy
Definition MRSymMatrix2.h:18
static constexpr SymMatrix2 diagonal(T diagVal) noexcept
Definition MRSymMatrix2.h:24
T yy
Definition MRSymMatrix2.h:18
static constexpr SymMatrix2 identity() noexcept
Definition MRSymMatrix2.h:23
constexpr SymMatrix2< T > inverse(T det) const noexcept
computes inverse matrix given determinant of this
SymMatrix2 & operator*=(T b)
Definition MRSymMatrix2.h:39
SymMatrix2< T > outerSquare(T k, const Vector2< T > &a)
x = k * a * a^T
Definition MRSymMatrix2.h:92
SymMatrix2< T > outerSquare(const Vector2< T > &a)
x = a * a^T
Definition MRSymMatrix2.h:81
Vector2< T > operator*(const SymMatrix2< T > &a, const Vector2< T > &b)
x = a * b
Definition MRSymMatrix2.h:70
SymMatrix2 & operator/=(T b)
Definition MRSymMatrix2.h:40
constexpr T det() const noexcept
computes determinant of the matrix
SymMatrix2 & operator+=(const SymMatrix2< T > &b)
Definition MRSymMatrix2.h:37
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:29
T xx
zero matrix by default
Definition MRSymMatrix2.h:18
Definition MRVector2.h:18
T x
Definition MRVector2.h:24
T y
Definition MRVector2.h:24