4 #ifndef OPENVDB_MATH_MAT3_H_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_MAT3_H_HAS_BEEN_INCLUDED
21 template<
typename T>
class Vec3;
22 template<
typename T>
class Mat4;
23 template<
typename T>
class Quat;
53 template<
typename Source>
55 Source d, Source e, Source
f,
56 Source
g, Source
h, Source i)
71 template<
typename Source>
85 template<
typename Source>
100 template<
typename Source>
103 for (
int i=0; i<3; ++i) {
104 for (
int j=0;
j<3; ++
j) {
113 for (
int i=0; i<3; ++i) {
114 for (
int j=0;
j<3; ++
j) {
155 return Vec3<T>((*this)(i,0), (*
this)(i,1), (*
this)(i,2));
171 return Vec3<T>((*this)(0,
j), (*
this)(1,
j), (*
this)(2,
j));
240 vdiag[0], vtri[0], vtri[1],
241 vtri[0], vdiag[1], vtri[2],
242 vtri[1], vtri[2], vdiag[2]
254 {*
this = rotation<Mat3<T> >(
q);}
259 {*
this = rotation<Mat3<T> >(axis,
angle);}
290 template<
typename Source>
301 bool eq(
const Mat3 &m, T eps=1.0e-8)
const
318 -
MyBase::mm[0], -MyBase::mm[1], -MyBase::mm[2],
319 -MyBase::mm[3], -MyBase::mm[4], -MyBase::mm[5],
320 -MyBase::mm[6], -MyBase::mm[7], -MyBase::mm[8]
330 template <
typename S>
346 template <
typename S>
364 template <
typename S>
382 template <
typename S>
427 MyBase::mm[5] * MyBase::mm[6] - MyBase::mm[3] * MyBase::mm[8],
428 MyBase::mm[3] * MyBase::mm[7] - MyBase::mm[4] * MyBase::mm[6],
429 MyBase::mm[2] * MyBase::mm[7] - MyBase::mm[1] * MyBase::mm[8],
430 MyBase::mm[0] * MyBase::mm[8] - MyBase::mm[2] * MyBase::mm[6],
431 MyBase::mm[1] * MyBase::mm[6] - MyBase::mm[0] * MyBase::mm[7],
432 MyBase::mm[1] * MyBase::mm[5] - MyBase::mm[2] * MyBase::mm[4],
433 MyBase::mm[2] * MyBase::mm[3] - MyBase::mm[0] * MyBase::mm[5],
434 MyBase::mm[0] * MyBase::mm[4] - MyBase::mm[1] * MyBase::mm[3]);
442 MyBase::mm[2] * MyBase::mm[7] - MyBase::mm[1] * MyBase::mm[8],
443 MyBase::mm[1] * MyBase::mm[5] - MyBase::mm[2] * MyBase::mm[4],
444 MyBase::mm[5] * MyBase::mm[6] - MyBase::mm[3] * MyBase::mm[8],
445 MyBase::mm[0] * MyBase::mm[8] - MyBase::mm[2] * MyBase::mm[6],
446 MyBase::mm[2] * MyBase::mm[3] - MyBase::mm[0] * MyBase::mm[5],
447 MyBase::mm[3] * MyBase::mm[7] - MyBase::mm[4] * MyBase::mm[6],
448 MyBase::mm[1] * MyBase::mm[6] - MyBase::mm[0] * MyBase::mm[7],
449 MyBase::mm[0] * MyBase::mm[4] - MyBase::mm[1] * MyBase::mm[3]);
458 MyBase::mm[1], MyBase::mm[4], MyBase::mm[7],
459 MyBase::mm[2], MyBase::mm[5], MyBase::mm[8]);
473 OPENVDB_THROW(ArithmeticError,
"Inversion of singular 3x3 matrix");
475 return inv * (
T(1)/
det);
482 const T co10 = MyBase::mm[5]*MyBase::mm[6] - MyBase::mm[3]*MyBase::mm[8];
483 const T co20 = MyBase::mm[3]*MyBase::mm[7] - MyBase::mm[4]*MyBase::mm[6];
484 return MyBase::mm[0]*co00 + MyBase::mm[1]*co10 + MyBase::mm[2]*co20;
504 template<
typename T0>
507 return static_cast< Vec3<T0> >(v * *
this);
512 template<
typename T0>
515 return static_cast< Vec3<T0> >(*
this *
v);
525 ret.
mm[0] *= diag(0);
526 ret.
mm[1] *= diag(1);
527 ret.
mm[2] *= diag(2);
528 ret.
mm[3] *= diag(0);
529 ret.
mm[4] *= diag(1);
530 ret.
mm[5] *= diag(2);
531 ret.
mm[6] *= diag(0);
532 ret.
mm[7] *= diag(1);
533 ret.
mm[8] *= diag(2);
541 template <
typename T0,
typename T1>
547 for (
int i=0; i<9; ++i) {
555 template <
typename T0,
typename T1>
560 template <
typename S,
typename T>
566 template <
typename S,
typename T>
576 template <
typename T0,
typename T1>
586 template <
typename T0,
typename T1>
596 template <
typename T0,
typename T1>
606 template<
typename T,
typename MT>
612 _v[0]*m[0] + _v[1]*m[1] + _v[2]*m[2],
613 _v[0]*m[3] + _v[1]*m[4] + _v[2]*m[5],
614 _v[0]*m[6] + _v[1]*m[7] + _v[2]*m[8]);
619 template<
typename T,
typename MT>
625 _v[0]*m[0] + _v[1]*m[3] + _v[2]*m[6],
626 _v[0]*m[1] + _v[1]*m[4] + _v[2]*m[7],
627 _v[0]*m[2] + _v[1]*m[5] + _v[2]*m[8]);
632 template<
typename T,
typename MT>
642 template <
typename T>
645 return Mat3<T>(v1[0]*v2[0], v1[0]*v2[1], v1[0]*v2[2],
646 v1[1]*v2[0], v1[1]*v2[1], v1[1]*v2[2],
647 v1[2]*v2[0], v1[2]*v2[1], v1[2]*v2[2]);
654 template<
typename T,
typename T0>
664 namespace mat3_internal {
673 double cotan_of_2_theta;
675 double cosin_of_theta;
681 double Sjj_minus_Sii = D[
j] - D[i];
684 tan_of_theta = Sij / Sjj_minus_Sii;
687 cotan_of_2_theta = 0.5*Sjj_minus_Sii / Sij ;
689 if (cotan_of_2_theta < 0.) {
691 -1./(
sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) - cotan_of_2_theta);
694 1./(
sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) + cotan_of_2_theta);
698 cosin_of_theta = 1./
sqrt( 1. + tan_of_theta * tan_of_theta);
699 sin_of_theta = cosin_of_theta * tan_of_theta;
700 z = tan_of_theta * Sij;
704 for (
int k = 0; k < i; ++k) {
706 S(k,i) = cosin_of_theta * temp - sin_of_theta * S(k,j);
707 S(k,j)= sin_of_theta * temp + cosin_of_theta * S(k,j);
709 for (
int k = i+1; k <
j; ++k) {
711 S(i,k) = cosin_of_theta * temp - sin_of_theta * S(k,j);
712 S(k,j) = sin_of_theta * temp + cosin_of_theta * S(k,j);
714 for (
int k = j+1; k <
n; ++k) {
716 S(i,k) = cosin_of_theta * temp - sin_of_theta * S(j,k);
717 S(j,k) = sin_of_theta * temp + cosin_of_theta * S(j,k);
719 for (
int k = 0; k <
n; ++k)
722 Q(k,i) = cosin_of_theta * temp - sin_of_theta*Q(k,j);
723 Q(k,j) = sin_of_theta * temp + cosin_of_theta*Q(k,j);
738 unsigned int MAX_ITERATIONS=250)
748 for (
int i = 0; i <
n; ++i) {
752 unsigned int iterations(0);
759 for (
int i = 0; i <
n; ++i) {
760 for (
int j = i+1;
j <
n; ++
j) {
773 for (
int i = 0; i <
n; ++i) {
774 for (
int j = i+1;
j <
n; ++
j){
780 if (fabs(S(i,
j)) > max_element) {
781 max_element = fabs(S(i,
j));
788 }
while (iterations < MAX_ITERATIONS);
800 for (
unsigned i = 0; i < 9; ++i, ++op, ++ip) *op =
math::Abs(*ip);
804 template<
typename Type1,
typename Type2>
811 for (
unsigned i = 0; i < 9; ++i, ++op, ++ip) {
823 return cwiseLessThan<3, T>(m0, m1);
830 return cwiseGreaterThan<3, T>(m0, m1);
849 #endif // OPENVDB_MATH_MAT3_H_HAS_BEEN_INCLUDED
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
void setToRotation(const Quat< T > &q)
Set this matrix to the rotation matrix specified by the quaternion.
bool cwiseGreaterThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
void pivot(int i, int j, Mat3< T > &S, Vec3< T > &D, Mat3< T > &Q)
Mat3< T > outerProduct(const Vec3< T > &v1, const Vec3< T > &v2)
Vec3< typename promote< T, MT >::type > operator*(const Vec3< T > &_v, const Mat3< MT > &_m)
Multiply _v by _m and return the resulting vector.
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Mat3(Source a, Source b, Source c, Source d, Source e, Source f, Source g, Source h, Source i)
Constructor given array of elements, the ordering is in row major form:
Mat3(const Mat4< T > &m)
Conversion from Mat4 (copies top left)
Mat3 snapBasis(Axis axis, const Vec3< T > &direction)
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
void setToRotation(const Vec3< T > &axis, T angle)
Set this matrix to the rotation specified by axis and angle.
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Vec3< T > col(int j) const
Get jth column, e.g. Vec3d v = m.col(0);.
Mat3< Type1 > cwiseAdd(const Mat3< Type1 > &m, const Type2 s)
void setZero()
Set this matrix to zero.
vfloat4 sqrt(const vfloat4 &a)
GLdouble GLdouble GLdouble z
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
GLboolean GLboolean GLboolean GLboolean a
#define OPENVDB_USE_VERSION_NAMESPACE
Mat3< T > operator-() const
Negation operator, for e.g. m1 = -m2;.
**But if you need a result
GLfloat GLfloat GLfloat v2
GLdouble GLdouble GLdouble q
GLfloat GLfloat GLfloat GLfloat v3
Tolerance for floating-point comparison.
void setRows(const Vec3< T > &v1, const Vec3< T > &v2, const Vec3< T > &v3)
Set the rows of this matrix to the vectors v1, v2, v3.
void setColumns(const Vec3< T > &v1, const Vec3< T > &v2, const Vec3< T > &v3)
Set the columns of this matrix to the vectors v1, v2, v3.
Mat3(const Vec3< Source > &v1, const Vec3< Source > &v2, const Vec3< Source > &v3, bool rows=true)
Vec3< T0 > transform(const Vec3< T0 > &v) const
Mat3 transpose() const
returns transpose of this
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
#define OPENVDB_IS_POD(Type)
static const Mat3< T > & identity()
Predefined constant for identity matrix.
static Mat3 symmetric(const Vec3< T > &vdiag, const Vec3< T > &vtri)
Return a matrix with the prescribed diagonal and symmetric triangular components. ...
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
bool diagonalizeSymmetricMatrix(const Mat3< T > &input, Mat3< T > &Q, Vec3< T > &D, unsigned int MAX_ITERATIONS=250)
Use Jacobi iterations to decompose a symmetric 3x3 matrix (diagonalize and compute eigenvectors) ...
Coord Abs(const Coord &xyz)
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Mat3 inverse(T tolerance=0) const
Mat3< typename promote< S, T >::type > operator*(const Mat3< T > &m, S scalar)
Multiply each element of the given matrix by scalar and return the result.
void setCol(int j, const Vec3< T > &v)
Set jth column to vector v.
Vec3< T > row(int i) const
Get ith row, e.g. Vec3d v = m.row(1);.
bool eq(const Mat3 &m, T eps=1.0e-8) const
Return true if this matrix is equivalent to m within a tolerance of eps.
Mat3(const Mat3< Source > &m)
Conversion constructor.
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
bool cwiseLessThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
const Mat3< T > & operator+=(const Mat3< S > &m1)
Add each element of the given matrix to the corresponding element of this matrix. ...
T det() const
Determinant of matrix.
Mat3 adjoint() const
Return the adjoint of this matrix, i.e., the transpose of its cofactor.
GLboolean GLboolean GLboolean b
static const Mat3< T > & zero()
Predefined constant for zero matrix.
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
const Mat3< T > & operator*=(S scalar)
Multiplication operator, e.g. M = scalar * M;.
void setSkew(const Vec3< T > &v)
Set the matrix as cross product of the given vector.
GLfloat GLfloat GLfloat GLfloat h
void setRow(int i, const Vec3< T > &v)
Set ith row to vector v.
void setSymmetric(const Vec3< T > &vdiag, const Vec3< T > &vtri)
Set diagonal and symmetric triangular components.
Mat3 timesDiagonal(const Vec3< T > &diag) const
Treat diag as a diagonal matrix and return the product of this matrix with diag (from the right)...
T * asPointer()
Direct access to the internal data.
T trace() const
Trace of matrix.
static unsigned numElements()
const Mat3 & operator=(const Mat3< Source > &m)
Assignment operator.
void setIdentity()
Set this matrix to identity.
T & operator()(int i, int j)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE constexpr T abs(T a) IMATH_NOEXCEPT
Vec3< T0 > pretransform(const Vec3< T0 > &v) const
Mat3< T > powLerp(const Mat3< T0 > &m1, const Mat3< T0 > &m2, T t)
const Mat3< T > & operator*=(const Mat3< S > &m1)
Multiply this matrix by the given matrix.
MatType snapMatBasis(const MatType &source, Axis axis, const Vec3< typename MatType::value_type > &direction)
This function snaps a specific axis to a specific direction, preserving scaling.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Vec3< typename promote< T, MT >::type > operator*(const Mat3< MT > &_m, const Vec3< T > &_v)
Multiply _m by _v and return the resulting vector.
MatType skew(const Vec3< typename MatType::value_type > &skew)
Return a matrix as the cross product of the given vector.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
T operator()(int i, int j) const
#define OPENVDB_THROW(exception, message)
Mat3 cofactor() const
Return the cofactor matrix of this matrix.
void powSolve(const MatType &aA, MatType &aB, double aPower, double aTol=0.01)
const Mat3< T > & operator-=(const Mat3< S > &m1)
Subtract each element of the given matrix from the corresponding element of this matrix.