Matrix33¶
The Matrix33
class template represents a 3x3 matrix, with
predefined typedefs for float
and double
.
There are also various utility functions that operate on matrices
defined in ImathMatrixAlgo.h
and described in Matrix
Functions.
Individual components of a matrix M
may be referenced as either
M[j][i]
or M.x[j][i]
. While the latter is a little awkward, it has an
advantage when used in loops that may be auto-vectorized or explicitly
vectorized by #pragma omp simd
or other such hints, because the function
call and pointer casting of operator[]
can confuse the compiler just
enough to prevent vectorization of the loop, whereas directly addressing the
real underlying array (M.x[j][i]
) does not.
Example:
#include <Imath/ImathMatrix.h>
#include <Imath/ImathMatrixAlgo.h>
#include <cassert>
void
matrix33_example()
{
Imath::M33f M (Imath::UNINITIALIZED); // uninitialized
M.makeIdentity();
assert (M[0][0] == 1.0f);
assert (M[0][1] == 0.0f);
Imath::M33f Minv = M.inverse();
Imath::M33f R;
assert (R == Imath::identity33f);
R.rotate (M_PI/4);
M = R * M;
Imath::V3f v3 (1.0f, 0.0f, 0.0f);
Imath::V3f r3 = v3 * M;
assert (r3.equalWithAbsError (Imath::V3f (0.707107f, 0.7071070f, 0.0f), 1e-6f));
}
-
typedef Matrix33<float>
Imath
::
M33f
¶ 3x3 matrix of float
-
typedef Matrix33<double>
Imath
::
M33d
¶ 3x3 matrix of double
-
template<class
T
>
classMatrix33
¶ 3x3 transformation matrix
Direct access to elements
-
template<>
Tx
[3][3]¶ Matrix elements.
Constructors and Assignment
-
Matrix33
(Uninitialized)¶ Uninitialized.
-
constexpr
Matrix33
()¶ Default constructor: initialize to identity 1 0 0 0 1 0 0 0 1.
-
constexpr
Matrix33
(T a)¶ Initialize to scalar constant a a a a a a a a a.
-
constexpr
Matrix33
(const T a[3][3])¶ Construct from 3x3 array a[0][0] a[0][1] a[0][2] a[1][0] a[1][1] a[1][2] a[2][0] a[2][1] a[2][2].
-
constexpr
Matrix33
(T a, T b, T c, T d, T e, T f, T g, T h, T i)¶ Construct from given scalar values a b c d e f g h i.
-
template<class
S
>
constexprMatrix33
(const Matrix33<S> &v)¶ Construct from Matrix33 of another base type.
-
constexpr const Matrix33<T> &
operator=
(const Matrix33 &v)¶ Assignment operator.
-
constexpr const Matrix33<T> &
operator=
(T a)¶ Assignment from scalar.
-
~Matrix33
()¶ Destructor.
Compatibility with Sb
-
T *
getValue
()¶ Return a raw pointer to the array of values.
-
const T *
getValue
() const¶ Return a raw pointer to the array of values.
Arithmetic and Comparison
-
constexpr bool
operator==
(const Matrix33 &v) const¶ Equality.
-
constexpr bool
operator!=
(const Matrix33 &v) const¶ Inequality.
-
constexpr bool
equalWithAbsError
(const Matrix33<T> &v, T e) const¶ Compare two matrices and test if they are “approximately equal”:
- Return
- True if the coefficients of this and
m
are the same with an absolute error of no more than e, i.e., for all i, j:abs (this[i][j] - m[i][j]) <= e
-
constexpr bool
equalWithRelError
(const Matrix33<T> &v, T e) const¶ Compare two matrices and test if they are “approximately equal”:
- Return
- True if the coefficients of this and m are the same with a relative error of no more than e, i.e., for all i, j:
abs (this[i] - v[i][j]) <= e * abs (this[i][j])
-
constexpr const Matrix33<T> &
operator+=
(const Matrix33 &v)¶ Component-wise addition.
-
constexpr const Matrix33<T> &
operator+=
(T a)¶ Component-wise addition.
-
constexpr Matrix33<T>
operator+
(const Matrix33 &v) const¶ Component-wise addition.
-
constexpr const Matrix33<T> &
operator-=
(const Matrix33 &v)¶ Component-wise subtraction.
-
constexpr const Matrix33<T> &
operator-=
(T a)¶ Component-wise subtraction.
-
constexpr Matrix33<T>
operator-
(const Matrix33 &v) const¶ Component-wise subtraction.
-
constexpr Matrix33<T>
operator-
() const¶ Component-wise multiplication by -1.
-
constexpr const Matrix33<T> &
negate
()¶ Component-wise multiplication by -1.
-
constexpr const Matrix33<T> &
operator*=
(T a)¶ Component-wise multiplication.
-
constexpr Matrix33<T>
operator*
(T a) const¶ Component-wise multiplication.
-
constexpr const Matrix33<T> &
operator/=
(T a)¶ Component-wise division.
-
constexpr Matrix33<T>
operator/
(T a) const¶ Component-wise division.
-
constexpr const Matrix33<T> &
operator*=
(const Matrix33 &v)¶ Matrix-matrix multiplication.
-
constexpr Matrix33<T>
operator*
(const Matrix33 &v) const¶ Matrix-matrix multiplication.
Maniplation
-
void
makeIdentity
()¶ Set to the identity matrix.
-
constexpr const Matrix33<T> &
transpose
()¶ Transpose.
-
constexpr Matrix33<T>
transposed
() const¶ Return the transpose.
-
constexpr const Matrix33<T> &
invert
(bool singExc)¶ Invert in place using the determinant.
- Return
- const reference to this
- Parameters
singExc
: If true, throw an exception if the matrix cannot be inverted.
-
constexpr const Matrix33<T> &
invert
()¶ Invert in place using the determinant.
- Return
- const reference to this
-
constexpr Matrix33<T>
inverse
(bool singExc) const¶ Return the inverse using the determinant, leaving this unmodified.
- Parameters
singExc
: If true, throw an exception if the matrix cannot be inverted.
-
constexpr Matrix33<T>
inverse
() const¶ Return the inverse using the determinant, leaving this unmodified.
-
const Matrix33<T> &
gjInvert
(bool singExc)¶ Invert in place using the Gauss-Jordan method.
Significantly slower but more accurate than invert().
- Return
- const reference to this
- Parameters
singExc
: If true, throw an exception if the matrix cannot be inverted.
-
const Matrix33<T> &
gjInvert
()¶ Invert in place using the Gauss-Jordan method.
Significantly slower but more accurate than invert().
- Return
- const reference to this
-
Matrix33<T>
gjInverse
(bool singExc) const¶ Return the inverse using the Gauss-Jordan method, leaving this unmodified.
Significantly slower but more accurate than inverse().
-
Matrix33<T>
gjInverse
() const¶ Return the inverse using the Gauss-Jordan method.
Significantly slower, leaving this unmodified. Slower but more accurate than inverse().
-
constexpr T
minorOf
(const int r, const int c) const¶ Calculate the matrix minor of the (r,c) element.
-
constexpr T
fastMinor
(const int r0, const int r1, const int c0, const int c1) const¶ Build a minor using the specified rows and columns.
-
constexpr T
determinant
() const¶ Determinant.
-
constexpr T
trace
() const¶ Trace.
-
template<class
S
>
const Matrix33 &setRotation
(S r)¶ Set matrix to rotation by r (in radians)
- Return
- const referenced to this
-
constexpr const Matrix33<T> &
setScale
(T s)¶ Set matrix to scale by given uniform factor.
- Return
- const referenced to this
-
template<class
S
>
constexpr const Matrix33 &setScale
(const Vec2<S> &s)¶ Set matrix to scale by given vector.
- Return
- const referenced to this
-
template<class
S
>
constexpr const Matrix33 &scale
(const Vec2<S> &s)¶ Scale the matrix by s.
- Return
- const referenced to this
-
template<class
S
>
constexpr const Matrix33 &setTranslation
(const Vec2<S> &t)¶ Set matrix to translation by given vector.
- Return
- const referenced to this
-
constexpr Vec2<T>
translation
() const¶ Return the translation component.
-
template<class
S
>
constexpr const Matrix33 &translate
(const Vec2<S> &t)¶ Translate the matrix by t.
- Return
- const referenced to this
-
template<class
S
>
constexpr const Matrix33 &setShear
(const S &h)¶ Set matrix to shear x for each y coord.
by given factor xy
- Return
- const referenced to this
-
template<class
S
>
constexpr const Matrix33 &setShear
(const Vec2<S> &h)¶ Set matrix to shear x for each y coord.
by given factor h.x and to shear y for each x coord. by given factor h.y
- Return
- const referenced to this
Numeric Limits
-
static constexpr T
baseTypeLowest
()¶ Largest possible negative value.
-
static constexpr T
baseTypeMax
()¶ Largest possible positive value.
-
static constexpr T
baseTypeSmallest
()¶ Smallest possible positive value.
-
static constexpr T
baseTypeEpsilon
()¶ Smallest possible e for which 1+e != 1.
Public Types
-
typedef T
BaseType
¶ The base type: In templates that accept a parameter
V
(could be a Color4), you can refer toT
asV::BaseType
-
typedef Vec3<T>
BaseVecType
¶ The base vector type.
Public Static Functions
-
static constexpr unsigned int
dimensions
()¶ Return the number of the row and column dimensions, i.e. 3.
-
template<>
Warning
doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments (std::ostream& s, const Matrix33<T>& m) in doxygen xml output for project “Imath” from directory: /build/ilmbase-TFRjEc/ilmbase-3.1.11/obj-x86_64-linux-gnu/website/doxygen/xml. Potential matches:
- std::ostream &operator<<(std::ostream&, Imath::half)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Color4<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Euler<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Interval<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Line3<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix22<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix33<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix44<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Plane3<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Quat<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Shear6<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec2<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec3<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec4<T>&)