46 static constexpr Matrix4 scale( T s )
noexcept {
return Matrix4( { s, T(0), T(0), T(0) }, { T(0), s, T(0), T(0) }, { T(0), T(0), s, T(0) }, { T(0), T(0), T(0), s } ); }
60 constexpr T
trace() const noexcept {
return x.x +
y.y +
z.z +
w.w; }
62 constexpr T
normSq() const noexcept {
return x.lengthSq() +
y.lengthSq() +
z.lengthSq() +
w.lengthSq(); }
63 constexpr auto norm() const noexcept
73 T
det() const noexcept;
84 constexpr T*
data() {
return (T*) (&
x); };
85 constexpr const T*
data()
const {
return (T*) (&
x); };
91 if constexpr ( std::is_integral_v<T> )
92 {
x /= b;
y /= b;
z /= b;
w /= b;
return *
this; }
94 return *
this *= ( 1 / b );
99 assert( std::abs(
w.x ) < std::numeric_limits<T>::epsilon() * 1000 );
100 assert( std::abs(
w.y ) < std::numeric_limits<T>::epsilon() * 1000 );
101 assert( std::abs(
w.z ) < std::numeric_limits<T>::epsilon() * 1000 );
102 assert( std::abs( 1 -
w.w ) < std::numeric_limits<T>::epsilon() * 1000 );
104 res.
A.x.x =
x.x; res.
A.x.y =
x.y; res.
A.x.z =
x.z; res.
b.x =
x.w;
105 res.
A.y.x =
y.x; res.
A.y.y =
y.y; res.
A.y.z =
y.z; res.
b.y =
y.w;
106 res.
A.z.x =
z.x; res.
A.z.y =
z.y; res.
A.z.z =
z.z; res.
b.z =
z.w;
122 return { dot( a.
x, b ), dot( a.
y, b ), dot( a.
z, b ), dot( a.
w, b ) };
129 return dot( a.
x, b.
x ) + dot( a.
y, b.
y ) + dot( a.
z, b.
z ) + dot( a.
w, b.
w );
135 return ( *
this *
Vector4<T>{ b.
x, b.y, b.z, T(1) } ).proj3d();
143 for (
int i = 0; i < 4; ++i )
144 for (
int j = 0; j < 4; ++j )
145 res[i][j] = dot( a[i], b.
col(j) );
153 return { a.
x * b, a.
y * b, a.
z * b, a.
w * b };
158 {
return a.
x == b.
x && a.
y == b.
y && a.
z == b.
z && a.
w == b.
w; }
162 {
return !( a == b ); }
166 {
return { a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w }; }
170 {
return { a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w }; }
174 {
return { a * b.x, a * b.y, a * b.z, a * b.w }; }
178 {
return { a * b.x, a * b.y, a * b.z, a * b.z }; }
182 { b /= a;
return b; }
188 auto* resM = (T*) &res.x;
190 for (
int m = 0; m < 4; m++ )
194 for (
int n = 0; n < 4; n++ )
198 resM[cur++] = (*this)[m][n];
209 x.x * submatrix3( 0, 0 ).det()
210 - x.y * submatrix3( 0, 1 ).det()
211 + x.z * submatrix3( 0, 2 ).det()
212 - x.w * submatrix3( 0, 3 ).det();
220 { x.x, y.x, z.x, w.x },
221 { x.y, y.y, z.y, w.y },
222 { x.z, y.z, z.z, w.z },
223 { x.w, y.w, z.w, w.w },
234 inv[0][0] = m[5] * m[10] * m[15] -
235 m[5] * m[11] * m[14] -
236 m[9] * m[6] * m[15] +
237 m[9] * m[7] * m[14] +
238 m[13] * m[6] * m[11] -
239 m[13] * m[7] * m[10];
241 inv[1][0] = -m[4] * m[10] * m[15] +
242 m[4] * m[11] * m[14] +
243 m[8] * m[6] * m[15] -
244 m[8] * m[7] * m[14] -
245 m[12] * m[6] * m[11] +
246 m[12] * m[7] * m[10];
248 inv[2][0] = m[4] * m[9] * m[15] -
249 m[4] * m[11] * m[13] -
250 m[8] * m[5] * m[15] +
251 m[8] * m[7] * m[13] +
252 m[12] * m[5] * m[11] -
255 inv[3][0] = -m[4] * m[9] * m[14] +
256 m[4] * m[10] * m[13] +
257 m[8] * m[5] * m[14] -
258 m[8] * m[6] * m[13] -
259 m[12] * m[5] * m[10] +
262 inv[0][1] = -m[1] * m[10] * m[15] +
263 m[1] * m[11] * m[14] +
264 m[9] * m[2] * m[15] -
265 m[9] * m[3] * m[14] -
266 m[13] * m[2] * m[11] +
267 m[13] * m[3] * m[10];
269 inv[1][1] = m[0] * m[10] * m[15] -
270 m[0] * m[11] * m[14] -
271 m[8] * m[2] * m[15] +
272 m[8] * m[3] * m[14] +
273 m[12] * m[2] * m[11] -
274 m[12] * m[3] * m[10];
276 inv[2][1] = -m[0] * m[9] * m[15] +
277 m[0] * m[11] * m[13] +
278 m[8] * m[1] * m[15] -
279 m[8] * m[3] * m[13] -
280 m[12] * m[1] * m[11] +
283 inv[3][1] = m[0] * m[9] * m[14] -
284 m[0] * m[10] * m[13] -
285 m[8] * m[1] * m[14] +
286 m[8] * m[2] * m[13] +
287 m[12] * m[1] * m[10] -
290 inv[0][2] = m[1] * m[6] * m[15] -
291 m[1] * m[7] * m[14] -
292 m[5] * m[2] * m[15] +
293 m[5] * m[3] * m[14] +
294 m[13] * m[2] * m[7] -
297 inv[1][2] = -m[0] * m[6] * m[15] +
298 m[0] * m[7] * m[14] +
299 m[4] * m[2] * m[15] -
300 m[4] * m[3] * m[14] -
301 m[12] * m[2] * m[7] +
304 inv[2][2] = m[0] * m[5] * m[15] -
305 m[0] * m[7] * m[13] -
306 m[4] * m[1] * m[15] +
307 m[4] * m[3] * m[13] +
308 m[12] * m[1] * m[7] -
311 inv[3][2] = -m[0] * m[5] * m[14] +
312 m[0] * m[6] * m[13] +
313 m[4] * m[1] * m[14] -
314 m[4] * m[2] * m[13] -
315 m[12] * m[1] * m[6] +
318 inv[0][3] = -m[1] * m[6] * m[11] +
319 m[1] * m[7] * m[10] +
320 m[5] * m[2] * m[11] -
321 m[5] * m[3] * m[10] -
325 inv[1][3] = m[0] * m[6] * m[11] -
326 m[0] * m[7] * m[10] -
327 m[4] * m[2] * m[11] +
328 m[4] * m[3] * m[10] +
332 inv[2][3] = -m[0] * m[5] * m[11] +
334 m[4] * m[1] * m[11] -
339 inv[3][3] = m[0] * m[5] * m[10] -
341 m[4] * m[1] * m[10] +
346 det = m[0] * inv[0][0] + m[1] * inv[1][0] + m[2] * inv[2][0] + m[3] * inv[3][0];
374 x.x = rot.x.x; x.y = rot.x.y; x.z = rot.x.z;
375 y.x = rot.y.x; y.y = rot.y.y; y.z = rot.y.z;
376 z.x = rot.z.x; z.y = rot.z.y; z.z = rot.z.z;
388 x.w = t.x; y.w = t.y; z.w = t.z;
#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
Color operator/(const Color &b, float a)
Definition MRColor.h:128
Color operator*(float a, const Color &b)
Definition MRColor.h:118
MRMESH_CLASS Vector3< double > Matrix2< double > Matrix4
Definition MRMesh/MRMeshFwd.h:169
MRMESH_CLASS Vector3
Definition MRMesh/MRMeshFwd.h:137
AffineXf< Vector3< T > > AffineXf3
Definition MRMesh/MRMeshFwd.h:208
Color operator+(const Color &a, const Color &b)
Definition MRColor.h:108
Definition MRMesh/MRAffineXf.h:14
V b
Definition MRMesh/MRAffineXf.h:19
M A
Definition MRMesh/MRAffineXf.h:18
Definition MRMesh/MRMatrix3.h:13
Vector3< T > x
rows, identity matrix by default
Definition MRMesh/MRMatrix3.h:18
Vector3< T > y
Definition MRMesh/MRMatrix3.h:19
Vector3< T > z
Definition MRMesh/MRMatrix3.h:20
Definition MRMatrix4.h:14
Vector4< T > z
Definition MRMatrix4.h:21
T dot(const Matrix4< T > &a, const Matrix4< T > &b)
double-dot product: x = a : b
Definition MRMatrix4.h:127
constexpr T * data()
Definition MRMatrix4.h:84
constexpr Matrix4(const AffineXf3< T > &xf) MR_REQUIRES_IF_SUPPORTED(std
Definition MRMatrix4.h:39
T ValueType
Definition MRMatrix4.h:15
constexpr T trace() const noexcept
computes trace of the matrix
Definition MRMatrix4.h:60
void setTranslation(const Vector3< T > &t) noexcept
Matrix4 & operator+=(const Matrix4< T > &b)
Definition MRMatrix4.h:86
Matrix4 & operator*=(T b)
Definition MRMatrix4.h:88
Matrix3< T > submatrix3(int i, int j) const noexcept
computes submatrix of the matrix with excluded i-th row and j-th column
static constexpr Matrix4 zero() noexcept
Definition MRMatrix4.h:43
constexpr T normSq() const noexcept
compute sum of squared matrix elements
Definition MRMatrix4.h:62
constexpr const T & operator()(int row, int col) const noexcept
element access
Definition MRMatrix4.h:49
Vector4< T > y
Definition MRMatrix4.h:20
static constexpr Matrix4 scale(T s) noexcept
returns a matrix that scales uniformly
Definition MRMatrix4.h:46
void setRotation(const Matrix3< T > &rot) noexcept
constexpr Matrix3< T > getRotation() const noexcept
constexpr Matrix4(const Matrix3< T > &r, const Vector3< T > &t)
construct from rotation matrix and translation vector
Definition MRMatrix4.h:29
T det() const noexcept
computes determinant of the matrix
Vector4< T > w
Definition MRMatrix4.h:22
constexpr Matrix4< T > transposed() const noexcept
computes transposed matrix
constexpr auto norm() const noexcept
Definition MRMatrix4.h:63
constexpr Matrix4(const Matrix4< U > &m)
Definition MRMatrix4.h:42
constexpr const Vector4< T > & operator[](int row) const noexcept
row access
Definition MRMatrix4.h:53
constexpr Vector4< T > col(int i) const noexcept
column access
Definition MRMatrix4.h:57
constexpr Matrix4() noexcept=default
Matrix4 & operator/=(T b)
Definition MRMatrix4.h:89
constexpr const T * data() const
Definition MRMatrix4.h:85
static constexpr Matrix4 identity() noexcept
Definition MRMatrix4.h:44
constexpr Matrix4< T > inverse() const noexcept
computes inverse matrix
Matrix4 & operator-=(const Matrix4< T > &b)
Definition MRMatrix4.h:87
constexpr Vector3< T > getTranslation() const noexcept
Vector4< T > x
rows, identity matrix by default
Definition MRMatrix4.h:19
Matrix4< T > outer(const Vector4< T > &a, const Vector4< T > &b)
x = a * b^T
Definition MRMatrix4.h:151
Definition MRMesh/MRVector3.h:19
T x
Definition MRMesh/MRVector3.h:25
T y
Definition MRMesh/MRVector3.h:25
T z
Definition MRMesh/MRVector3.h:25
Definition MRVector4.h:13
T y
Definition MRVector4.h:19
T z
Definition MRVector4.h:19
T x
Definition MRVector4.h:19
T w
Definition MRVector4.h:19