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). Cinema 4D also uses vectors 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.

Warning

The Vector type does not support the function copy.copy() .

Instead use the Vector constructor:

import c4d
vec = c4d.Vector(42, 39, 7)
print "Vector:", id(vec), vec
ref = vec
print "Reference:", id(ref), ref
copy = c4d.Vector(vec)
print "Copy:", id(copy), copy
					

Definition

class c4d. Vector

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 ] ] )
Initalizes a new Vector . All arguments are optional so it is possible to create a new vector without any arguments. All components are simply 0 . Otherwise x can be a Vector so all components of the passed vector will be copied to the new vector. If only a number is passed, all components will be set to this.
c4d.Vector()
# => Vector(0,0,0)
c4d.Vector(100)
# => Vector(100,100,100)
v = c4d.Vector(100,100,100)
c4d.Vector(v)
# => Vector(100,100,100)
c4d.Vector(1,2,3)
# => Vector(1,2,3)
							
Parameters:
  • x (number or Vector ) – If x is a number and is the only passed argument, set this to all components. If x is a vector, clone it. Otherwise set the X component.
  • y ( number ) – Set the Y component.
  • z ( number ) – Set the Z component.
Return type:

c4d.Vector

Returns:

A new vector.

Vector. __str__ ( )

Returns a string representation of the vector. Called if str() is wrapped around a vector object. (See __str__ ):

vec = Vector(30.0, 40.0, 2)
print vec
# => Vector(30.0, 40.0, 2.0)
							
Return type: str
Returns: The Vector as string.
Vector. __getitem__ ( self , key )

New in version R14.014.

Retrieves X, Y and Z components by index:

v = c4d.Vector(1,2,3)
x = v[0]
y = v[1]
z = v[2]
print x, y, z
# => 1.0 2.0 3.0
							
Parameters: key ( int ) – The component index.
Raises: IndexError – If the index key is out of range : 0<=key<2 .
Return type: float
Returns: The vector component.
Vector. __setitem__ ( self , key , value )

New in version R14.014.

Assigns X, Y and Z components by index:

v = c4d.Vector(1,2,3)
v[0] = 0
print v
# => Vector(0, 2, 3)
							

Note

The Vector objects does not support item deletion. For instance by calling del(v[0]) .

Parameters:
  • key ( int ) – The component index.
  • value ( float ) – The new vector component.
Raises:

IndexError – If the index key is out of range : 0<=key<2 .

Vector. __add__ ( self , other )

Adds a scalar or vector to the vector:

c4d.Vector(1,2,3)+1
# => Vector(2,3,4)
c4d.Vector(1,2,3)+c4d.Vector(2,3,4)
# => Vector(3,5,7)
							
Parameters: other ( c4d.Vector or number ) – The other argument.
Return type: c4d.Vector
Returns: The result vector.
Vector. __sub__ ( self , other )

Subtracts a scalar or vector from the vector:

c4d.Vector(1,2,3)-1
# => Vector(0,1,2)
c4d.Vector(1,2,3)-c4d.Vector(2,3,4)
# => Vector(-1,-1,-1)
							
Parameters: other ( c4d.Vector or number ) – The other argument.
Return type: c4d.Vector
Returns: The result vector.
Vector. __mul__ ( self , other )
If other is a vector, calculates the dot product of the vectors. If other is a float, it multiplies each vector component by the scalar. If other is a matrix, the vector is transformed by it.
c4d.Vector(1,2,3)*c4d.Vector(2,3,4)
# => 20
c4d.Vector(1,2,3)*5
# => Vector(5,10,15)
c4d.Vector(1,2,3)*c4d.Matrix(v1=c4d.Vector(2,0,0))
# => Vector(2,2,3)
							
Parameters: other ( c4d.Matrix ) – The other argument.
Return type: c4d.Vector or float
Returns: A float if other is of type Vector . A vector, if other is of type float or Matrix .
Vector. __div__ ( self , other )

Divides each vector component by the scalar:

c4d.Vector(1,2,3)/5
# => Vector(0.2, 0.4, 0.6)
							
Parameters: other ( number ) – The other argument.
Return type: c4d.Vector
Returns: The result vector.
Vector. __mod__ ( self , other )

Calculates the cross product of vectors:

c4d.Vector(1,2,3)%c4d.Vector(2,3,4)
# => Vector(-1, 2, -1)
							
Parameters: other ( c4d.Vector ) – The other argument.
Return type: c4d.Vector
Returns: The result vector.
Vector. __xor__ ( self , other )
Multiplies vectors component-wise if other is a vector. If other is a matrix then the vector is transformed by it.
c4d.Vector(1,2,3)^c4d.Vector(2,3,4)
# => Vector(2,6,12)
c4d.Vector(1,2,3)^c4d.Matrix(v1=c4d.Vector(2,0,0))
# => Vector(2,2,3)
							
Parameters: other ( c4d.Matrix ) – The other argument.
Return type: c4d.Vector
Returns: The result vector.
Vector. __abs__ ( self )

Returns a vector with the absolute (positive) value of each component:

abs(c4d.Vector(-1, -2, -3))
# => Vector(1,2,3)
							
Return type: c4d.Vector
Returns: The absolute vector.
Vector. __neg__ ( )

Returns the negative of the vector:

-c4d.Vector(1,2,3)
# => Vector(-1,-2,-3)
							
Return type: c4d.Vector
Returns: The negative vector.
Vector. __invert__ ( )

Returns the normalized vector:

~c4d.Vector(1,2,3)
# => Vector(0.267,0.535,0.802)
							
Return type: c4d.Vector
Returns: The normalized vector.
Vector. __eq__ ( self , other )

Checks if two vectors are equal.

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

Check if two vectors are not equal.

Parameters: other ( c4d.Vector ) – The other vector.
Return type: bool
Returns: True if both vectors are not equal.
Vector. Dot ( v2 )

Calculates the dot product of the vector and vector v2 .

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

Calculates the cross product of the vector and vector v2 .

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

Calculates the length of the vector.

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

Calculates the squared length of the vector.

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

Calculates the normalized vector, so that GetLength() returns 1.0 .

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

Normalizes the vector, so that GetLength() returns 1.0 .

Table Of Contents