# c4d.Matrix¶

class `c4d.``Matrix`

Warning

The `Matrix` type does not support the function copy.copy().

Instead use the `Matrix` constructor

```import c4d

def main():
if op is None:
return

mat = op.GetMg()
print "Matrix:", id(mat), mat

ref = mat
print "Reference:", id(ref), ref

copy = c4d.Matrix(mat)
print "Copy:", id(copy), copy

if __name__=='__main__':
main()
```

Attributes

`Matrix.``v1`

The X axis of a left-handed coordinate system.

Type: `Vector`

`Matrix.``v2`

The Y axis of a left-handed coordinate system.

Type: `Vector`

`Matrix.``v3`

The Z axis of a left-handed coordinate system.

Type: `Vector`

`Matrix.``off`

The translation vector.

Type: `Vector`

Methods Signatures

 `Matrix.__init__(self[, off, v1, v2, v3])` Initializes a new `Matrix`. `Matrix.__str__(self)` Returns the Matrix as string. Called if str() is wrapped around an instance of `Matrix`. (See __str__) `Matrix.__add__(self, other)` Adds two matrices. `Matrix.__sub__(self, other)` Subtracts two matrices. `Matrix.__mul__(self, other)` Multiplies a matrix or vector by the matrix. Can also scale each vector of the matrix by a scalar. `Matrix.__div__(self, other)` Divides each element in the matrix by a scalar. `Matrix.__invert__(self)` Inverts the matrix. `Matrix.__eq__(self, other)` Checks if two matrices are equal. `Matrix.__ne__(self, other)` Checks if two matrices are not equal. `Matrix.__ge__(self, other)` raise NotImplemented. `Matrix.__gt__(self, other)` raise NotImplemented. `Matrix.__le__(self, other)` raise NotImplemented. `Matrix.__lt__(self, other)` raise NotImplemented.
 `Matrix.Normalize(self)` Normalizes the matrix. `Matrix.GetNormalized(self)` Calculates the normalized matrix. `Matrix.Mul(self, v)` Multiply the vector by the matrix, this includes any translation in the matrix. `Matrix.MulV(self, v)` Multiply the vector by the matrix, this does not include any translation. `Matrix.GetTensorMatrix(self)` Returns the matrix’ tensor. `Matrix.Scale(self, v)` Performs uniform matrix scaling (float) or non-uniform matrix scaling (vector). `Matrix.GetScale(self)` Returns the scale stored by the matrix.

Methods Documentation

`Matrix.``__init__`(self, off=Vector(0), v1=Vector(1, 0, 0), v2=Vector(0, 1, 0), v3=Vector(0, 0, 1))
Initializes a new `Matrix`.
All arguments are optional so it is possible to create a new matrix without any arguments. All components are simply set to:
• off = Vector(0)

• v1 = Vector(1,0,0)

• v2 = Vector(0,1,0)

• v3 = Vector(0,0,1)

```mat = c4d.Matrix()
# => Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (0, 0, 0))

mat = c4d.Matrix()
mat.off = c4d.Vector(100,0,0)

v1 = c4d.Vector(3)
v2 = c4d.Vector(12,4,9.3)
v3 = c4d.Vector(9,80,3)
off = c4d.Vector(v1+v2)
mat = c4d.Matrix(off,v1,v2,v3)
```
Parameters
• off (c4d.Vector) – The translation vector.

• v1 (c4d.Vector) – The X axis of a left-handed coordinate system.

• v2 (c4d.Vector) – The Y axis of a left-handed coordinate system.

• v3 (c4d.Vector) – The Z axis of a left-handed coordinate system.

Return type

c4d.Matrix

Returns

A new matrix.

`Matrix.``__str__`(self)

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

```v1 = c4d.Vector(3)
v2 = c4d.Vector(12,4,9.3)
v3 = c4d.Vector(9,80,3)
off = c4d.Vector(v1+v2)
mat = c4d.Matrix(off,v1,v2,v3)
print mat
# => 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)

Parameters

other (c4d.Matrix) – The other matrix.

Return type

c4d.Matrix

Returns

The result matrix.

`Matrix.``__sub__`(self, other)

Subtracts two matrices.

Parameters

other (c4d.Matrix) – The other matrix.

Return type

c4d.Matrix

Returns

The result matrix.

`Matrix.``__mul__`(self, other)
Multiplies a matrix or vector by the matrix. Can also scale each vector of the matrix by a scalar.

If both objects are of type `Matrix`, multiplies the left hand matrix by the right hand matrix.
If the left object is of type `Matrix` and the right one of type `Vector`, multiplies the vector by the matrix including any translation in the matrix.
If the left object is of type `Vector` and the right one of type `Matrix`, multiplies the vector by the matrix including any translation in the matrix.
If the right object is a number, multiplies each vector of the matrix by it.
Parameters

other (Union[c4d.Vector, int, float]) – The other argument.

Return type

c4d.Vector

Returns

The result matrix or vector.

`Matrix.``__div__`(self, other)

Divides each element in the matrix by a scalar.

Parameters

other (float) – The scalar.

Return type

c4d.Matrix

Returns

The result matrix.

`Matrix.``__invert__`(self)

Inverts the matrix.

Return type

c4d.Matrix

Returns

The inverted matrix.

`Matrix.``__eq__`(self, other)

Checks if two matrices are equal.

Parameters

other (c4d.Matrix) – The other matrix.

Return type

bool

Returns

True if matrices are equal.

`Matrix.``__ne__`(self, other)

Checks if two matrices are not equal.

Parameters

other (c4d.Matrix) – The other matrix.

Return type

bool

Returns

True if matrices are not equal.

`Matrix.``__ge__`(self, other)

raise NotImplemented.

`Matrix.``__gt__`(self, other)

raise NotImplemented.

`Matrix.``__le__`(self, other)

raise NotImplemented.

`Matrix.``__lt__`(self, other)

raise NotImplemented.

`Matrix.``Normalize`(self)

Normalizes the matrix.

`Matrix.``GetNormalized`(self)

Calculates the normalized matrix.

Return type

c4d.Matrix

Returns

The normalized matrix.

`Matrix.``Mul`(self, v)

Multiply the vector by the matrix, this includes any translation in the matrix.

Parameters

v (c4d.Vector) – The vector to multiply.

Return type

c4d.Vector

Returns

The result vector.

`Matrix.``MulV`(self, v)

Multiply the vector by the matrix, this does not include any translation.

Parameters

v (c4d.Vector) – The vector to multiply.

Return type

c4d.Vector

Returns

The result vector.

`Matrix.``GetTensorMatrix`(self)

Returns the matrix’ tensor.

Return type

c4d.Matrix

Returns

The tensor matrix.

`Matrix.``Scale`(self, v)

Performs uniform matrix scaling (float) or non-uniform matrix scaling (vector).

Parameters

v (Union[c4d.Vector, float]) – The scaling scalar.

`Matrix.``GetScale`(self)

Returns the scale stored by the matrix.

Returns

The scale.

Return type

c4d.Vector