c4d.Vector¶
-
class
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 of an RGB (Red, Green, Blue) color model.The vector class can also represent a direction, an arrow pointing from the origin of the coordinates, such as (0,0,0), to an endpoint3.
Note
Cinema 4D uses a left-handed coordinate system.
Attributes
Methods Signatures
Initializes a new
Vector . |
|
Returns a string representation of the vector.
|
|
Retrieves X, Y and Z components by index |
|
Assigns X, Y and Z components by index |
|
Adds a scalar or vector to the vector |
|
Subtracts a scalar or vector from the vector |
|
If other is a vector, calculates the dot product of the vectors.
|
|
Divides each vector component by the scalar |
|
Calculates the cross product of vectors |
|
Multiplies vectors component-wise if other is a vector.
|
|
Returns a vector with the absolute (positive) value of each component |
|
Returns the negative of the vector |
|
Returns the normalized vector |
|
Checks if two vectors are equal. |
|
Check if two vectors are not equal. |
|
raise NotImplemented. |
|
raise NotImplemented. |
|
raise NotImplemented. |
|
raise NotImplemented. |
Calculates the dot product of the vector and vector v2. |
|
Calculates the cross product of the vector and vector v2. |
|
Calculates the length of the vector. |
|
Retrieve the distance between two vectors. |
|
Calculates the squared length of the vector. |
|
Calculates the normalized vector, so that |
|
Normalizes the vector, so that |
Methods Documentation
-
Vector.
__init__
(self, x=0.0, y=0.0, z=0.0)¶ - Initializes 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 aVector
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 (Union[int, float, c4d.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
- Returns
A new vector.
-
Vector.
__str__
(self)¶ - Returns a string representation of the vector.
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)¶ Retrieves X, Y and Z components by index
New in version R14.014.
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)¶ Assigns X, Y and Z components by index
New in version R14.014.
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 (Union[c4d.Vector, int, float]) – The other argument.
- Return type
- 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 (Union[c4d.Vector, int, float]) – The other argument.
- Return type
- 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 orMatrix
.
-
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
- 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
- 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
- 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
- Returns
The absolute vector.
-
Vector.
__neg__
(self)¶ Returns the negative of the vector
-c4d.Vector(1,2,3) # => Vector(-1,-2,-3)
- Return type
- Returns
The negative vector.
-
Vector.
__invert__
(self)¶ Returns the normalized vector
~c4d.Vector(1,2,3) # => Vector(0.267,0.535,0.802)
- Return type
- 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.
__ge__
(self, other)¶ raise NotImplemented.
-
Vector.
__gt__
(self, other)¶ raise NotImplemented.
-
Vector.
__le__
(self, other)¶ raise NotImplemented.
-
Vector.
__lt__
(self, other)¶ raise NotImplemented.
-
Vector.
Dot
(self, 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
(self, v2)¶ Calculates the cross product of the vector and vector v2.
- Parameters
v2 (c4d.Vector) – The other vector.
- Return type
- Returns
The result.
-
Vector.
GetLength
(self)¶ Calculates the length of the vector.
- Return type
float
- Returns
The length.
-
Vector.
GetDistance
(self, v1, v2)¶ Retrieve the distance between two vectors.
- Parameters
v1 (c4d.Vector) – The first vector.
v2 (c4d.Vector) – The second vector.
- Returns
the distance from v1 to v2.
- Return type
float
-
Vector.
GetLengthSquared
(self)¶ Calculates the squared length of the vector.
- Return type
float
- Returns
The squared length.
-
Vector.
GetNormalized
(self)¶ Calculates the normalized vector, so that
GetLength()
returns 1.0.- Return type
- Returns
The normalized vector.
-
Vector.
Normalize
(self)¶ Normalizes the vector, so that
GetLength()
returns 1.0.