SBDTypePhysicalMatrix33< Quantity > Class Template Reference

This template class is used to describe 3x3 physical matrices. More...

## Constructors

SBDTypePhysicalMatrix33 ()
Constructs a physical matrix with all components set to zero.

SBDTypePhysicalMatrix33 (const SBDTypePhysicalVector3< Quantity > &d)
Constructs the diagonal physical matrix with diagonal [ d.v[0] d.v[1] d.v[2] ].

SBDTypePhysicalMatrix33 (const SBDTypePhysicalVector3< Quantity > &c0, const SBDTypePhysicalVector3< Quantity > &c1, const SBDTypePhysicalVector3< Quantity > &c2)
Constructs the physical matrix with columns c0, c1 and c2.

SBDTypePhysicalMatrix33 (const Quantity &v)
Constructs the physical matrix with all components set to v.

SBDTypePhysicalMatrix33 (Quantity mat[3][3])
Constructs the physical matrix from the quantity array mat.

SBDTypePhysicalMatrix33 (const Quantity &m00, const Quantity &m01, const Quantity &m02, const Quantity &m10, const Quantity &m11, const Quantity &m12, const Quantity &m20, const Quantity &m21, const Quantity &m22)
Constructs the physical matrix from components m00, m01, m02, m10, m11, m12, m20, m21 and m22.

SBDTypePhysicalMatrix33 (double d)
Constructs the dimensionless physical matrix with all components set to d.

SBDTypePhysicalMatrix33 (double mat[3][3])
Constructs the dimensionless physical matrix from double array mat.

SBDTypePhysicalMatrix33 (double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
Constructs the dimensionless physical matrix from components m00, m01, m02, m10, m11, m12, m20, m21 and m22.

## Serialization

void serialize (SBCSerializer *serializer, const SBVersionNumber &sdkVersionNumber=SB_SDK_VERSION_NUMBER) const
Serializes the physical matrix using the provided serializer.

void unserialize (SBCSerializer *serializer, const SBVersionNumber &sdkVersionNumber=SB_SDK_VERSION_NUMBER)
Unserializes the physical matrix using the provided serializer.

## Accessors

SBDTypePhysicalVector3< Quantity > getE1 () const
Returns the first column of this physical matrix.

void setE1 (const SBDTypePhysicalVector3< Quantity > &v)
Sets the first column of this physical matrix.

SBDTypePhysicalVector3< Quantity > getE2 () const
Returns the second column of this physical matrix.

void setE2 (const SBDTypePhysicalVector3< Quantity > &v)
Sets the second column of this physical matrix.

SBDTypePhysicalVector3< Quantity > getE3 () const
Returns the third column of this physical matrix.

void setE3 (const SBDTypePhysicalVector3< Quantity > &v)
Sets the third column of this physical matrix.

SBDTypePhysicalMatrix33< SBQuantity::dimensionlessgetValue () const
Returns a dimensionless physical matrix whose components are equal to those of this physical matrix.

void setValue (const SBDTypePhysicalMatrix33< SBQuantity::dimensionless > &u)
Sets the components of this physical matrix equal to those of the dimensionless physical matrix u.

## Operators

SBDTypePhysicalMatrix33< Quantity > operator+ (const SBDTypePhysicalMatrix33< Quantity > &mat) const
Returns the sum of this physical matrix with physical matrix mat.

SBDTypePhysicalMatrix33< Quantity > operator- (const SBDTypePhysicalMatrix33< Quantity > &mat) const
Returns the difference of this physical matrix with physical matrix mat.

template<typename QuantityB >
SBDTypePhysicalMatrix33< typename SBQuantityProduct2< Quantity, QuantityB >::Type > operator* (const SBDTypePhysicalMatrix33< QuantityB > &mat) const
Returns the product of this physical matrix with physical matrix mat.

SBDTypePhysicalMatrix33< Quantity > operator* (double d) const
Returns the product of this physical matrix with double d.

void operator+= (const SBDTypePhysicalMatrix33< Quantity > &mat)
Adds physical matrix mat to this physical matrix.

void operator-= (const SBDTypePhysicalMatrix33< Quantity > &mat)
Subtracts physical matrix mat from this physical matrix.

SBDTypePhysicalMatrix33< Quantity > operator- () const
Returns the opposite of this physical matrix.

template<typename QuantityB >
SBDTypePhysicalMatrix33< Quantity > & operator*= (QuantityB d)
Multiplies this physical matrix with physical quantity d.

template<typename QuantityB >
SBDTypePhysicalMatrix33< Quantity > & operator/= (QuantityB d)
Divides this physical matrix by physical quantity d.

template<typename QuantityB >
SBDTypePhysicalVector3< typename SBQuantityProduct2< Quantity, QuantityB >::Type > operator* (const SBDTypePhysicalVector3< QuantityB > &v) const
Returns the product of this physical matrix with physical vector v.

bool operator== (const SBDTypePhysicalMatrix33< Quantity > &mat) const
Returns true if this physical matrix is equal to physical matrix mat (component-wise)

bool operator!= (const SBDTypePhysicalMatrix33< Quantity > &mat) const
Returns true if this physical matrix is different from physical matrix mat (component-wise)

## Useful functions

Quantity m [3][3]
The components of the physical matrix.

static const SBDTypePhysicalMatrix33< Quantity > zero
The zero physical matrix.

static const SBDTypePhysicalMatrix33< Quantity > identity
The identity physical matrix.

Quantity trace () const
Returns the trace m[0][0] + m[1][1] + m[2][2] of this physical matrix.

void print () const
Prints this physical matrix.

void setIdentity ()
Sets this physical matrix to the identity matrix.

void setZero ()
Sets this physical matrix to zero.

SBDTypePhysicalMatrix33< Quantity > transpose () const
Returns the transpose of this physical matrix.

void toQuaternion (SBQuantity::dimensionless &w, SBQuantity::dimensionless &x, SBQuantity::dimensionless &y, SBQuantity::dimensionless &z) const
Computes the quaternion [ w x y z ] corresponding to this physical matrix.

void toRotationVector (SBVector3 &rotationVector) const
Computes the rotation vector corresponding to this dimensionless physical matrix.

void orthonormalize ()
Orthonormalizes this dimensionless physical matrix.

void quasiStaticUpdate (const SBQuantity::dimensionless &wx, const SBQuantity::dimensionless &wy, const SBQuantity::dimensionless &wz, SBQuantity::dimensionless &rotAngle, SBVector3 &rotAxis, SBDTypePhysicalMatrix33< Quantity > &rotA, SBDTypePhysicalMatrix33< Quantity > &rotB, SBDTypePhysicalMatrix33< Quantity > &rotC)
Performs a quasi-static update of this dimensionless physical matrix using the rotation vector [ wx wy wz ]. More...

void computeEulerDecompositionZYZ (SBQuantity::dimensionless &phi, SBQuantity::dimensionless &theta, SBQuantity::dimensionless &psi)
Computes a ZYZ Euler decomposition of this physical matrix. More...

void revoluteJointZAxisMatrix (const SBVector3 &axis)
Sets this physical matrix to an orthonormal matrix whose third column is axis.

void diagonalize (SBDTypePhysicalVector3< Quantity > &ev, SBDTypePhysicalMatrix33< SBQuantity::dimensionless > &p)
Computes the eigenvalues ev and the eigenvectors p of this physical matrix. More...

SBQuantityProduct3< Quantity, Quantity, Quantity >::Type det () const
Returns the determinant of this physical matrix.

Quantity norm () const
Returns the 2-norm of this physical matrix.

Quantity cosphi () const
Returns the cosine of the rotation angle of this rotation matrix. More...

SBDTypePhysicalMatrix33< typename SBQuantityInverse< Quantity >::Type > inverse () const
Returns the inverse of this physical matrix. More...

void makeEulerRotationZYZ (const SBQuantity::dimensionless &phi, const SBQuantity::dimensionless &theta, const SBQuantity::dimensionless &psi)
This function sets this physical matrix from ZYZ Euler angles phi, theta and psi. More...

void swapColumns (unsigned int i, unsigned int j)
Swaps columns i and j.

void swapRows (unsigned int i, unsigned int j)
Swaps rows i and j.

static SBDTypePhysicalMatrix33< SBQuantity::dimensionlessfromQuaternion (const SBQuantity::dimensionless &w, const SBQuantity::dimensionless &x, const SBQuantity::dimensionless &y, const SBQuantity::dimensionless &z)
Returns the dimensionless physical matrix corresponding to quaternion [ w x y z ].

static SBDTypePhysicalMatrix33< SBQuantity::dimensionlessfromAxisAngle (const SBVector3 &axis, const SBQuantity::dimensionless &angle)
Returns the dimensionless physical matrix corresponding to rotation axis axis and rotation angle angle (in radians)

static SBDTypePhysicalMatrix33< SBQuantity::dimensionlessfromAxisAnglePi (const SBVector3 &axis)
Returns the dimensionless physical matrix corresponding to rotation axis axis and a rotation angle equal to Pi.

static SBDTypePhysicalMatrix33< SBQuantity::dimensionlessfromAlignment (const SBVector3 &from, const SBVector3 &to)
Returns the dimensionless physical matrix that transforms vector from into vector to. Precisely, left-multiplying vector from by the resulting matrix produces vector to.

## Detailed Description

### template<typename Quantity> class SBDTypePhysicalMatrix33< Quantity >

Template Parameters
 Quantity The quantity type of the interval

This template class describes 3x3 physical matrices.

Physical matrices are physical quantities, and thus use SAMSON's unit system. In a physical matrix (e.g. an inertia tensor), all components have the same unit, so that physical matrices are defined by only one unit, and the SBDTypePhysicalMatrix33 template class is parameterized by only one type: Quantity.

Most of the time, developers of SAMSON Elements do not have to use this template, but may directly use some predefined types that correspond to specific instantiations of this template class, e.g. SBMatrix33 (dimensionless matrix), SBMass33 (mass matrix), SBInertiaTensor33 (inertia tensor), etc.

Dimensionless 3x3 matrices (SBMatrix33) are especially useful since they are used to represent 3D reference frames, rotation matrices, rigid-body transforms, etc.

Short name: SBPhysicalInterval

SAMSON's unit system
The SBDType library
SBDTypePhysicalVector3
SBDTypeSpatialTransform

## ◆ computeEulerDecompositionZYZ()

template<typename Quantity >
 void SBDTypePhysicalMatrix33< Quantity >::computeEulerDecompositionZYZ ( SBQuantity::dimensionless & phi, SBQuantity::dimensionless & theta, SBQuantity::dimensionless & psi )
inline
Parameters
 phi The first Z rotation angle theta The Y rotation angle psi The second Z rotation angle

This function computes a ZYZ Euler decomposition of this physical matrix:

$$\mathbf{M}=\mathbf{R}(z,psi)\mathbf{R}(y,theta)\mathbf{R}(z,phi)$$

where $$\mathbf{M}$$ denotes this physical matrix, $$\mathbf{R}(z,phi)$$ denotes the first rotation around the Z axis, $$\mathbf{R}(y,theta)$$ denotes the rotation around the Y axis, and $$\mathbf{R}(z,psi)$$ denotes the second rotation around the Z axis.

Note that this function may only be used with dimensionless physical matrices.

## ◆ cosphi()

template<typename Quantity >
 Quantity SBDTypePhysicalMatrix33< Quantity >::cosphi ( ) const
inline

This function assumes this physical matrix is a rotation matrix, and returns the cosine of the corresponding rotation angle

## ◆ diagonalize()

template<typename Quantity >
 void SBDTypePhysicalMatrix33< Quantity >::diagonalize ( SBDTypePhysicalVector3< Quantity > & ev, SBDTypePhysicalMatrix33< SBQuantity::dimensionless > & p )
inline
Parameters
 ev Stores the eigenvalues when this function returns p Stores the eigenvectors when this function returns

This function computes the eigenvalues ev and the eigenvectors p of this physical matrix. Note that the eigenvalues have the same units as the physical matrix, while the eigenvectors are stored in a dimensionless matrix.

SAMSON's unit system

## ◆ inverse()

template<typename Quantity >
 SBDTypePhysicalMatrix33< typename SBQuantityInverse::Type > SBDTypePhysicalMatrix33< Quantity >::inverse ( ) const
inline

This function assumes the physical matrix is invertible and returns its inverse.

## ◆ makeEulerRotationZYZ()

template<typename Quantity >
 void SBDTypePhysicalMatrix33< Quantity >::makeEulerRotationZYZ ( const SBQuantity::dimensionless & phi, const SBQuantity::dimensionless & theta, const SBQuantity::dimensionless & psi )
inline
Parameters
 phi The first Z rotation angle theta The Y rotation angle psi The second Z rotation angle

This function sets this physical matrix from ZYZ Euler angles:

$$\mathbf{M}=\mathbf{R}(z,psi)\mathbf{R}(y,theta)\mathbf{R}(z,phi)$$

where $$\mathbf{M}$$ denotes this physical matrix, $$\mathbf{R}(z,phi)$$ denotes the first rotation around the Z axis, $$\mathbf{R}(y,theta)$$ denotes the rotation around the Y axis, and $$\mathbf{R}(z,psi)$$ denotes the second rotation around the Z axis.

Note that this function may only be used with dimensionless physical matrices.

## ◆ quasiStaticUpdate()

template<typename Quantity >
 void SBDTypePhysicalMatrix33< Quantity >::quasiStaticUpdate ( const SBQuantity::dimensionless & wx, const SBQuantity::dimensionless & wy, const SBQuantity::dimensionless & wz, SBQuantity::dimensionless & rotAngle, SBVector3 & rotAxis, SBDTypePhysicalMatrix33< Quantity > & rotA, SBDTypePhysicalMatrix33< Quantity > & rotB, SBDTypePhysicalMatrix33< Quantity > & rotC )
inline
Parameters
 wx The first component of the rotation vector wy The second component of the rotation vector wz The third component of the rotation vector rotAngle The rotation angle rotAxis The rotation axis rotA The rotation axis rotB The rotation axis rotC The rotation axis

This function performs a quasi-static update of this dimensionless physical matrix using the rotation vector [ wx wy wz ]. During the update, The rotation vector [ wx wy wz ] is converted to a rotation angle and rotation axis, respectively stored into rotAngle and rotAxis. If $$\mathbf{M}$$ denotes the original matrix, the final matrix is $$\cos(w)\mathbf{A}+\sin(w)\mathbf{B}+\mathbf{C}$$, where $$\mathbf{A}$$, $$\mathbf{B}$$ and $$\mathbf{C}$$ are physical matrices computed from $$\mathbf{M}$$ and the rotation axis $$\mathbf{v}$$, and $$w$$ is the rotation angle:

• $$\mathbf{A}=(\mathbf{I}-\mathbf{v}\mathbf{v}^T)\mathbf{M}$$
• $$\mathbf{B}=\tilde{\mathbf{v}}\mathbf{M}$$
• $$\mathbf{C}=\mathbf{v}\mathbf{v}^T\mathbf{M}$$

where $$\tilde{\mathbf{v}}$$ is the matrix such that $$\tilde{\mathbf{v}}\mathbf{x}=\mathbf{v}\times\mathbf{x}$$ for any $$\mathbf{x}$$.

When the function returns, $$\mathbf{A}$$, $$\mathbf{B}$$ and $$\mathbf{C}$$ are stored into rotA, rotB and rotC, respectively.

Note that this function may only be used with dimensionless physical matrices.