This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.Matrix – a matrix class

Single precision matrix mathematics. A matrix is basically an array of number arranged in a rectangular pattern. The matrices used in CINEMA 4D, represented by the class Matrix, consist of three rows and four columns, i.e. they have the dimension 3x4. The first row is always “1, 0, 0, 0”, which means that there are 12 numbers that are used. These numbers are grouped into four vectors, one for the remaining numbers in each column. The four vectors are called off, v1, v2 and v3, together these four vectors can be used to represent the coordinate system for a CINEMA 4D object. A coordinate system consists of three axes, one for each coordinate (X, Y and Z). The system also has a base position, from which the three axes originate. This base position is stored in off, and the three axis vectors are stored in v1, v2 and v3 respectively. Also check out Matrix fundamentals.

\emph{
    The representation of a Matrix:
}
\textbf{M= }
\bordermatrix{ & \textbf{\scriptsize v1} &  \textbf{\scriptsize v2} & \textbf{\scriptsize v3} & \textbf{\scriptsize off} \\ \textbf{\scriptsize x} & {1} & {0} & {0} & {t_x} \\ \textbf{\scriptsize y} & {0} & {1} & {0} & {t_y} \\ \textbf{\scriptsize z} & {0} & {0} & {1} & {t_z} }

Note

CINEMA 4D uses a left-handed coordinate system.

Here is a small example how to use the type Matrix:

v_1    = Vector(30)
v_2    = Vector(1.5, 9.87, 2)
v_3    = Vector(0)
off    = Vector() #Vector with components: 0
mat    = Matrix(off, v_1, v_2, v_3) #create new instance of Matrix
print mat.v1.x #return 30
class c4d.Matrix

Public variable
Parameters:
  • v1 (Vector) – The v1 component.
  • v2 (Vector) – The v2 component.
  • v3 (Vector) – The v3 component.
  • off (Vector) – The off component.

Methods

Matrix.__init__([off=Vector(0)[, v1=Vector(1, 0, 0)[, v2=Vector(0, 1, 0)[, v3=Vector(0, 0, 1)]]]])
Parameters:
Return type:

Matrix

Returns:

A new matrix.

Matrix.__str__()

Returns the Matrix as string. Called if str() is wrapped around an instance of Matrix. (see __str__).:

import c4d
v1 = c4d.Vector(3)
v2 = c4d.Vector(12,4, 9.3)
v3 = c4d.Vector(9,80,3)
off = c4d.Vector(v1+v2)
vec = c4d.Matrix(off, v1, v2, v3)
print vec                # output 'Matrix(v1: (3, 3, 3); v2: (12, 4, 9.3); v3: (12, 4, 9.3); off: (15, 7, 12.3))'
Return type:str
Returns:The Vector as string.
Matrix.__add__(self, other)
Matrix.__radd__(self, other)

Add the two matrices together.

Parameter:other (Matrix) – The other matrix.
Matrix.__sub__(self, other)
Matrix.__rsub__(self, other)

Subtract the two matrices from each other.

Parameter:other (Matrix) – The other matrix.
Matrix.__mul__(self, other)
Matrix.__rmul__(self, other)

If both objects are of type Matrix, it multiplies the left hand matrix by the right hand matrix. Is the left object of type Matrix and the right one of Vector so multiply the vector by the matrix, this includes any translation in the matrix. In the last case, the left object can be of type Vector and the right one of type Matrix so it multiplies the vector by the matrix, this does not include any translation.

Parameter:other (Matrix or Vector) – Check the description above.
Matrix.__div__(self, other)

Divide each element in the matrix by the scalar.

Parameter:other (float) – The scalar.
Matrix.__invert__()

Invert the matrix.

Return type:Matrix
Returns:Returns a copy of the inverted matrix.
Vector.__eq__(other)

Check if two matrices are identical.

Parameter:other (Matrix) – The matrix to check.
Return type:bool
Returns:Returns True if both matrices are identical.
Vector.__ne__(self, other)

Check if two vectors are unidentical.

Parameter:other (Matrix) – The matrix to check.
Return type:bool
Returns:Returns True if both matrices are unidentical.
Matrix.Normalize()
Normalize the matrix.
Matrix.GetNormalized()

Returns a new copy of this matrix, which is normalized.

Return type:Matrix
Returns:The matrix.

Table Of Contents

This Page