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 four rows and four columns, i.e. they have the dimension 4x4. 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:

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, 1.5. 2)
v_3    = Vector(0)
offset = Vector() #Vector with components: 0
mat    = Matrix(v_1, v_2, v_3, offset)
print mat.v1.x #return 30
class c4d.Matrix

Comparisons

Operation Notes
!= Check if all elements in the matrix are not identical.
== Check if all elements in the matrix are identical.

Math operations

Operation self ? x Notes
+ Matrix Add the two matrices together.
- Matrix Subtract the two matrices from each other.
* Matrix Mulitply each element in the matrix by the scalar.
* Real Multiply the vector by the matrix, this does not include any translation.
/ Matrix Divide each element in the matrix by the scalar.
~ Matrix Returns a new normalized Matrix.

Public variable

Member  
v1 X-Axis
v2 Y-Axis
v3 Z-Axis
off Position

Methods

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

Matrix or None

Returns:

Returns a reference to a new object of type Matrix or None if allocation failed.

Matrix.normalize()
Normalize the Matrix

Comments

Add comment
Align matrix to target position, written by Sebastian on September 19,2009

This is an example how to align a matrix to a position:
import c4d
from c4d import tools

def align_mat(mat, target):
    """Just pass a matrix and a target.
    The return value is of type c4d.Matrix"""

    local = mat.off * (~c4d.Matrix()) - target
    hpb = tools.vector_to_hpb(local)
    rot = tools.matrix_to_hpb(mat)
    hpb.z = rot.z
    
    return tools.hpb_to_matrix(hpb)
Have fun!
Comments-System by Sebastian Rath (c) 2009

Table Of Contents

This Page