34 constexpr T
trace() const noexcept {
return xx +
yy; }
36 constexpr T
normSq() const noexcept {
return sqr(
xx ) + 2 * sqr(
xy ) + sqr(
yy ); }
38 constexpr T
det() const noexcept;
49 if constexpr ( std::is_integral_v<T> )
50 {
xx /= b;
xy /= b;
yy /= b;
return *
this; }
52 return *
this *= ( 1 / b );
81 a.xx * b.
x + a.xy * b.y,
82 a.xy * b.x + a.yy * b.y
101 const auto ka = k * a;
115 {
return !( a == b ); }
135 { b /= a;
return b; }
156Vector2<T> SymMatrix2<T>::eigens( Matrix2<T> * eigenvectors )
const MR_REQUIRES_IF_SUPPORTED( std::is_floating_point_v<T> )
159 const auto tr =
trace();
160 const auto q = tr / 2;
161 const auto p = std::sqrt( std::max( T(0), sqr( tr ) - 4 *
det() ) ) / 2;
163 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
168 *eigenvectors = Matrix2<T>{};
175 const auto x = eigenvector( eig[0] ).normalized();
184 const Vector2<T> row0(
xx - eigenvalue,
xy );
185 const Vector2<T> row1(
xy,
yy - eigenvalue );
187 const T lsq0 = row0.lengthSq();
188 const T lsq1 = row1.lengthSq();
189 return lsq0 >= lsq1 ? row0.perpendicular() : row1.perpendicular();
195 const auto tr =
trace();
196 const auto q = tr / 2;
197 const auto p = std::sqrt( std::max( T(0), sqr( tr ) - 4 *
det() ) ) / 2;
198 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
201 return Vector2<T>( T(1), T(0) );
203 return eigenvector( q + p );
210 Matrix2<T> eigenvectors;
211 const auto eigenvalues = eigens( &eigenvectors );
212 const auto threshold = std::max( std::abs( eigenvalues[0] ), std::abs( eigenvalues[1] ) ) * tol;
214 for (
int i = 0; i < 2; ++i )
216 if ( std::abs( eigenvalues[i] ) <= threshold )
218 res +=
outerSquare( 1 / eigenvalues[i], eigenvectors[i] );
223 *space = eigenvectors[i];
225 *space = Vector2<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...
SymMatrix2 & operator-=(const SymMatrix2< T > &b)
Definition MRSymMatrix2.h:45
constexpr SymMatrix2() noexcept=default
constexpr SymMatrix2< T > inverse() const noexcept
computes inverse matrix
Definition MRSymMatrix2.h:40
T ValueType
Definition MRSymMatrix2.h:18
constexpr T trace() const noexcept
computes trace of the matrix
Definition MRSymMatrix2.h:34
T xy
Definition MRSymMatrix2.h:21
static constexpr SymMatrix2 diagonal(T diagVal) noexcept
Definition MRSymMatrix2.h:31
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:52
T yy
Definition MRSymMatrix2.h:21
static constexpr SymMatrix2 identity() noexcept
Definition MRSymMatrix2.h:30
constexpr SymMatrix2< T > inverse(T det) const noexcept
computes inverse matrix given determinant of this
bool operator!=(const Color &a, const Color &b)
Definition MRColor.h:104
SymMatrix2 & operator*=(T b)
Definition MRSymMatrix2.h:46
Color operator/(const Color &b, float a)
Definition MRColor.h:129
SymMatrix2< T > outerSquare(T k, const Vector2< T > &a)
x = k * a * a^T
Definition MRSymMatrix2.h:99
SymMatrix2< T > outerSquare(const Vector2< T > &a)
x = a * a^T
Definition MRSymMatrix2.h:88
Vector2< T > operator*(const SymMatrix2< T > &a, const Vector2< T > &b)
x = a * b
Definition MRSymMatrix2.h:77
SymMatrix2 & operator/=(T b)
Definition MRSymMatrix2.h:47
constexpr T det() const noexcept
computes determinant of the matrix
SymMatrix2 & operator+=(const SymMatrix2< T > &b)
Definition MRSymMatrix2.h:44
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:36
T xx
zero matrix by default
Definition MRSymMatrix2.h:21
Color operator+(const Color &a, const Color &b)
Definition MRColor.h:109
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMatrix2.h:24
Definition MRSymMatrix2.h:17
Definition MRVector2.h:29
T x
Definition MRVector2.h:35
T y
Definition MRVector2.h:35