CVBpy 14.1
Matrix3D Class Reference

Double precision 3x3 matrix class. More...

Inherits object.

Public Member Functions

float at (self, int row, int column)
 Index based element access. More...
 
cvb.Matrix3D create ()
 Creates a 3x3 matrix without any parameters. More...
 
cvb.Matrix3D create (float alpha, float beta, float gamma)
 Creates a rotation matrix from the given Euler angles. More...
 
cvb.Matrix3D create (float alpha, float beta, float gamma, cvb.Factors3D scale)
 Creates a transformation matrix from the given Euler angles and scaling. More...
 
cvb.Matrix3D create (List[float] values)
 Creates a 3x3 matrix passing all matrix elements. More...
 
cvb.Matrix3D identity ()
 The identity element. More...
 
None inverse (self)
 Gets the inverse of this matrix if possible. More...
 
None invert (self)
 Inverts this matrix in-place if possible. More...
 

Properties

 det = property
 float: Matrix determinant.
 
 precision = property
 float: Precision of approximation. More...
 
 roll_pitch_yaw = property
 Tuple[float, float, float]: Roll, pitch and yaw values in degrees. More...
 
 rotation_angles = property
 Tuple[float, float, float]: Rotation angles alpha, beta and gamma in degrees. More...
 
 scale = property
 cvb.Factors3D: Scaling factors in x, y and z. More...
 

Detailed Description

Double precision 3x3 matrix class.

An object of this class can be constructed using rotation angles and scale. Then the matrix will be computed via (scale is optional):

where
alpha, beta, gamma are the rotation angles around x, y, z,
sx, sy, sz are the scaling factors for x, y, z.

Returning the properties Matrix3D.rotation_angles and Matrix3D.scale of this class, they are always calculated from the matrix. As you can create a Matrix3D also by passing the values of the matrix elements, the matrix is not necessarily a valid rotation matrix. In this case an approximation is calculated. Then the rotation angles and scaling factors are estimated using the Nelder-Mead algorithm. Therefore a cost function is set up and minimized over several iterations. The minimum value after the iteration stopped is stored to Matrix3D.precision. If the given matrix is valid and not noisy, the Matrix3D.precision will be very low. Note, that this estimation does not work for large scaling factors or if all scaling factors are negative. In this case the output Matrix3D.precision will be large (in general greater 1). Then please norm your matrix first by dividing all matrix elements by a matrix norm (e.g. the Frobenius norm or other).
If the matrix only contains rotation and scaling, i.e. it is not noisy, then rotation angles and scaling factors are calculated directly (without approximation). Then Matrix3D.precision is equal -1. Note, that angles and scale are computed from the normed matrix and threfore positive as a start. If the determinant of the normed matrix is -1, the scaling factor in z is set to a negative value.

Note
If one of the rotation angles is outside the range ]-90° .. 90°[ or one of the scaling factors is negative, the computation of the Euler angles and the scaling factors is ambiguous (rotation direction may be inversed, negative scaling is the same as rotation about 180 degree).

Supports the same arguments as cvb.Matrix3D.create.

Parameters

*args : Any Parameters like cvb.Matrix3D.create.

**kwargs : Any Parameters like cvb.Matrix3D.create.

Member Function Documentation

◆ at()

float at (   self,
int  row,
int  column 
)

Index based element access.

Parameters

row : int The row to access.

column : int The column to access.

Returns

float The matrix element.

◆ create() [1/4]

cvb.Matrix3D create ( )

Creates a 3x3 matrix without any parameters.

Returns

cvb.Matrix3D A 3D 3x3 matrix.

◆ create() [2/4]

cvb.Matrix3D create ( float  alpha,
float  beta,
float  gamma 
)

Creates a rotation matrix from the given Euler angles.

The rotation matrix R is computed via:

where
alpha, beta, gamma are the rotation angles around x, y, z.

Parameters

alpha : float Angle around x in degrees.

beta : float Angle around y axis in degrees.

gamma : float Angle around z axis in degrees.

Returns

cvb.Matrix3D A 3D 3x3 matrix.

◆ create() [3/4]

cvb.Matrix3D create ( float  alpha,
float  beta,
float  gamma,
cvb.Factors3D  scale 
)

Creates a transformation matrix from the given Euler angles and scaling.

Note, that the scaling is applied before rotation:

where
alpha, beta, gamma are the rotation angles around x, y, z,
sx, sy, sz are the scaling factors for x, y, z.

Parameters

alpha : float Angle around x in degrees.

beta : float Angle around y axis in degrees.

gamma : float Angle around z axis in degrees.

scale : cvb.Factors3D Scaling factors for x, y and z.

Returns

cvb.Matrix3D A 3D 3x3 matrix.

◆ create() [4/4]

cvb.Matrix3D create ( List[float]  values)

Creates a 3x3 matrix passing all matrix elements.

Parameters

values : List[float] Containing exactly 9 elements.

Returns

cvb.Matrix3D A 3D 3x3 matrix.

◆ identity()

cvb.Matrix3D identity ( )

The identity element.

Returns

cvb.Matrix3D An identity matrix.

◆ inverse()

None inverse (   self)

Gets the inverse of this matrix if possible.

Might cause division by zero.

◆ invert()

None invert (   self)

Inverts this matrix in-place if possible.

Might cause division by zero.

Property Documentation

◆ precision

precision = property
static

float: Precision of approximation.

If rotation angles and scale are calculated directly without approximation, this value is -1, otherwise it is greater/equal zero. For details see also description of Matrix3D.

◆ roll_pitch_yaw

roll_pitch_yaw = property
static

Tuple[float, float, float]: Roll, pitch and yaw values in degrees.

For roll, pitch, yaw, the rotation matrix is defined after the z-y'-x''convention (see https://en.wikipedia.org/wiki/Euler_angles). The rotation matrix is interpreted as:

R = Rz * Ry * Rx
where Rx, Ry, Rz is the rotation around x'', y', z.

◆ rotation_angles

rotation_angles = property
static

Tuple[float, float, float]: Rotation angles alpha, beta and gamma in degrees.

The matrix is interpreted as:

where
alpha, beta, gamma are the rotation angles around x, y, z.

For details see also description of Matrix3D.

◆ scale

scale = property
static

cvb.Factors3D: Scaling factors in x, y and z.

The matrix is interpreted as:

where
alpha, beta, gamma are the rotation angles around x, y, z.
sx, sy, sz are the scaling factors for x, y, z.

For details see also description of Matrix3D.