This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.Vector – a vector class

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.

\emph{The textual representation of a vector: }  \overrightarrow{v} \emph{=}
\begin{pmatrix}
  { x } &
  { y } &
  { z }
\end{pmatrix}

Here is an example how to use:

vec  = Vector(30, 40, 1.5) #new instance of the vector with the passed arguments
vec1 = Vector(vec.x) #new instance of the vector with all components of value vec.x
vec2 = Vector(vec) #copy constructor for vector
vec3 = vec * vec1 / vec2 #simple calculations
class c4d.Vector

Public variable
Parameters:
  • x (float) – The X component.
  • y (float) – The Y component.
  • z (float) – The Z component.

Methods

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 string. Called if str() is wrapped around an instance of Vector. (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.

Return type:Vector
Returns:The absolute vector.
Vector.__add__(self, other)
Vector.__radd__(self, other)

Add a scalar or Vector to the Vector.

Parameter:other (Vector or number) – The scalar or Vector.
Vector.__sub__(self, other)
Vector.__rsub__(self, other)

Subtract a scalar or vector to the vector

Parameter: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.

:param other : Multiply with self. :rtype: Vector :return: Returns a new vector, if other is of type float.

Returns a float value if other is of type Vector.
Vector.__div__(self, other)
Vector.__rdiv__(self, other)

Divide the vector.

Divide each vector component by a scalar.

:param other : The scalar. :rtype: Vector :return: The vector.

Vector.__mod__(self, other)
Vector.__rmod__(self, other)

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

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.

Param:The other argument.
Return type:Vector
Returns:The cross product.
Vector.__invert__(self)

Get the negative of the vector.

Return type:Vector
Returns:The vector.
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.

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

Check if two vectors are unidentical.

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

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

Parameter: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.GetNormalized()

Returns a new normalized vector.

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

Code

Limit the magnitude of a Vector:

def LimitVector(v, max):
    """
    This function limit the
    magnitude of a Vector
    """

    if v.GetLength()>max:
        v.Normalize()
        v *= max

Table Of Contents

This Page