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.
X component of the vector.
Type: float
Y component of the vector.
Type: float
Z component of the vector.
Type: float
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: |
|
---|---|
Return type: | |
Returns: |
A new vector. |
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. |
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. |
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. |
---|
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. |
---|
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. |
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. |
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. |
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. |
Get the normalized vector.
Return type: | Vector |
---|---|
Returns: | The normalized vector. |
Check if two vectors are identical.
Parameters: | other (Vector) – The vector to check. |
---|---|
Return type: | bool |
Returns: | True if both vectors are identical. |
Check if two vectors are unidentical.
Parameters: | other (Vector) – The vector to check. |
---|---|
Return type: | bool |
Returns: | True if both vectors are unidentical. |
Returns the dot product of this vector and vector v2.
Parameters: | v2 (Vector) – The second vector. |
---|---|
Return type: | float |
Returns: | The dot product |
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. |
Returns the length of the vector.
Return type: | float |
---|---|
Returns: | The length. |
Returns the squared length of the vector. This is faster than GetLength()
Return type: | float |
---|---|
Returns: | The squared length. |
Returns a new normalized vector.
Return type: | Vector |
---|---|
Returns: | The normalized vector. |
Normalize the vector.