c4d.Vector

Single precision vector mathematics. A vector class represents a point, a color, a direction, an HPB-angle or a simple coordinate in a 3D space using the Cartesian coordinates x, y and z. The values are stored in the members x, y and z. For example, positions are stored in the order (X position; Y position; Z position) and rotations in the order (H angle; P angle; B angle). In CINEMA 4D you can also use a vector to store colors and their values. The vector class can also represent a direction, an arrow pointing from the origin of the coordinates, such as (0,0,0), to an endpoint; or a floating-point component of an RGB (Red, Green, Blue) color model.

Note

CINEMA 4D uses a left-handed coordinate system.

Members

Vector.x

X component of the vector.

Type: float

Vector.y

Y component of the vector.

Type: float

Vector.z

Z component of the vector.

Type: float

Vector.__init__([x[, y, z]])

All arguments are optional so you can create a new vector without any arguments. All components are simply 0. Otherwise x could be a Vector. In this case, all components of the passed vector will be copied to the new vector. If you just pass a number, all components will be set to this. The last way is to set all compoents which have to be of numeric type.

Parameters:
  • x (number or Vector) – If x is a number, set this number to all components. If x is a Vector, clone it.
  • y (number) – Set the y component.
  • z (number) – Set the z component.
Return type:

Vector

Returns:

A new vector.

Vector.__str__()

Returns the Vector as a string. Called if str() is wrapped around a vector object: (see __str__).:

vec = Vector(30.0, 40.0, 2)
print vec                   # output 'Vector(30.0, 40.0, 2.0)'
Return type: str
Returns: The Vector as string.
Vector.__abs__(self)

Get the absolute (positive) value of each component:

import c4d
v_abs = abs(c4d.Vector(-1, -2, -3))
#v_abs => Vector(1,2,3)
Return type: Vector
Returns: The absolute vector.
Vector.__add__(self, other)
Vector.__radd__(self, other)

Add a scalar or Vector to the Vector:

import c4d
v_result = c4d.Vector(1,2,3)+c4d.Vector(2,3,4)
#v_result => Vector(3,5,7)
Parameters: other (Vector or number) – The scalar or Vector.
Vector.__sub__(self, other)
Vector.__rsub__(self, other)

Subtract a scalar or vector to the vector:

import c4d
v_result = c4d.Vector(1,2,3)-c4d.Vector(2,3,4)
#v_result => Vector(-1,-1,-1)
Parameters: other (Vector or number) – The scalar or Vector.
Vector.__mul__(self, other)
Vector.__rmul__(self, other)

In the case, other is a Vector it takes the dot product of the left hand operand with the right. If the argument is a float, it multiplies each vector component by a scalar and set the vector equal to a result:

import c4d
v_result = c4d.Vector(1,2,3)*c4d.Vector(2,3,4)
#v_result => 20

v_result = c4d.Vector(1,2,3)*5
#v_result => Vector(5,10,15)
Parameters: other (Vector or float.) – Multiply with self.
Return type: Vector or float
Returns: A new vector, if other is of type float. A float if other is of type Vector.
Vector.__div__(self, other)
Vector.__rdiv__(self, other)

Divide each vector component by a scalar:

import c4d
v_result = c4d.Vector(1,2,3)/5
#v_result => Vector(0.2, 0.4, 0.6)
Parameters: other (float) – The scalar.
Return type: Vector
Returns: The vector.
Vector.__mod__(self, other)
Vector.__rmod__(self, other)

Take the cross product of the left hand operand with the right:

import c4d
v_result = c4d.Vector(1,2,3)%c4d.Vector(2,3,4)
#v_result => Vector(-1, 2, -1)
Param : The other argument.
Return type: Vector
Returns: The cross product.
Vector.__xor__(self, other)
Vector.__rxor__(self, other)

Multiplies two vectors together componentwise and set the left hand vector to the result:

import c4d
v_result = c4d.Vector(1,2,3)%c4d.Vector(2,3,4)
#v_result => Vector(2,6,12)
Param : The other argument.
Return type: Vector
Returns: The cross product.
Vector.__neg__(self)

Get the negative of the vector.

Return type: Vector
Returns: The vector.
Vector.__invert__(self)

Get the normalized vector.

Return type: Vector
Returns: The normalized vector.
Vector.__eq__(self, other)

Check if two vectors are identical.

Parameters: other (Vector) – The vector to check.
Return type: bool
Returns: True if both vectors are identical.
Vector.__ne__(self, other)

Check if two vectors are unidentical.

Parameters: other (Vector) – The vector to check.
Return type: bool
Returns: True if both vectors are unidentical.
Vector.Dot(v2)

Returns the dot product of this vector and vector v2.

Parameters: v2 (Vector) – The second vector.
Return type: float
Returns: The dot product
Vector.Cross(v2)

This method takes the cross product of the left hand operand with the right.

Parameters: v2 (Vector) – The other vector.
Return type: Vector
Returns: The result.
Vector.GetLength()

Returns the length of the vector.

Return type: float
Returns: The length.
Vector.GetLengthSquared()

Returns the squared length of the vector. This is faster than GetLength()

Return type: float
Returns: The squared length.
Vector.GetNormalized()

Returns a new normalized vector.

Return type: Vector
Returns: The normalized vector.
Vector.Normalize()

Normalize the vector.

Table Of Contents