Module Mathutils :: Class Vector
[frames] | no frames]

Class Vector

The Vector object

This object gives access to Vectors in Blender.


Notes:

Attention: Vector data can be wrapped or non-wrapped. When a object is wrapped it means that the object will give you direct access to the data inside of blender. Modification of this object will directly change the data inside of blender. To copy a wrapped object you need to use the object's constructor. If you copy and object by assignment you will not get a second copy but a second reference to the same data. Only certain functions will return wrapped data. This will be indicated in the method description. Example:

   wrappedObject = Object.getAttribute() #this is wrapped data
   print wrappedObject.wrapped #prints 'True'
   copyOfObject = wrappedObject.copy() #creates a copy of the object
   secondPointer = wrappedObject #creates a second pointer to the same data
   print wrappedObject.attribute #prints '5'
   secondPointer.attribute = 10
   print wrappedObject.attribute #prints '10'
   print copyOfObject.attribute #prints '5'

Instance Methods
Vector object.
__init__(list=None)
Create a new 2d, 3d, or 4d Vector object from a list of floating point numbers.
 
copy()
Returns a copy of this vector
 
zero()
Set all values to zero.
 
normalize()
Normalize the vector, making the length of the vector always 1.0
 
negate()
Set all values to their negative.
 
resize2D()
Resize the vector to 2d.
 
resize3D()
Resize the vector to 3d.
 
resize4D()
Resize the vector to 4d.
Quaternion
toTrackQuat(track, up)
Return a quaternion rotation from the vector and the track and up axis.
Vector object matching the size of this vector.
reflect(mirror)
Return the reflection vector from the mirror vector argument.
Vector
cross(other)
Return the cross product of this vector and another.
float
dot(other)
Return the dot product of this vector and another.
Instance Variables
  length
The magnitude of the vector.
  magnitude
This is a synonym for length.
  wrapped
Whether or not this item is wrapped data
    Axises
  w
The w value (if any).
  x
The x value.
  y
The y value.
  z
The z value (if any).
Method Details

__init__(list=None)
(Constructor)

 

Create a new 2d, 3d, or 4d Vector object from a list of floating point numbers.

Parameters:
  • list (PyList of float or int) - The list of values for the Vector object. Can be a sequence or raw numbers. Must be 2, 3, or 4 values. The list is mapped to the parameters as [x,y,z,w].
Returns: Vector object.
It depends wheter a parameter was passed:
  • (list): Vector object initialized with the given values;
  • (): An empty 3 dimensional vector.

Note: that python uses higher precission floating point numbers, so values assigned to a vector may have some rounding error.

Example:

 v = Vector(1,0,0)
 v = Vector(myVec)
 v = Vector(list)

copy()

 

Returns a copy of this vector

Returns:
a copy of itself

zero()

 

Set all values to zero.

Returns:
an instance of itself

normalize()

 

Normalize the vector, making the length of the vector always 1.0

Returns:
an instance of itself
Notes:
  • Normalize works for vectors of all sizes, however 4D Vectors w axis is left untouched.
  • Normalizing a vector where all values are zero results in all axis having a nan value (not a number).

negate()

 

Set all values to their negative.

Returns:
an instance of its self

resize2D()

 

Resize the vector to 2d.

Returns:
an instance of itself

resize3D()

 

Resize the vector to 3d. New axis will be 0.0.

Returns:
an instance of itself

resize4D()

 

Resize the vector to 4d. New axis will be 0.0. The last component will be 1.0, to make multiplying 3d vectors by 4x4 matrices easier.

Returns:
an instance of itself

toTrackQuat(track, up)

 

Return a quaternion rotation from the vector and the track and up axis.

Parameters:
  • track (String.) - Possible values:
    • "x - x-axis up"
    • "y - y-axis up"
    • "z - z-axis up"
    • "-x - negative x-axis up"
    • "-y - negative y-axis up"
    • "-z - negative z-axis up"
  • up (String.) - Possible values:
    • "x - x-axis up"
    • "y - y-axis up"
    • "z - z-axis up"
Returns: Quaternion
Return a quaternion rotation from the vector and the track and up axis.

reflect(mirror)

 

Return the reflection vector from the mirror vector argument.

Parameters:
  • mirror (Vector object) - This vector could be a normal from the reflecting surface.
Returns: Vector object matching the size of this vector.
The reflected vector.

cross(other)

 

Return the cross product of this vector and another.

Parameters:
  • other (Vector object) - The other vector to perform the cross product with.
Returns: Vector
The cross product.

Note: both vectors must be 3D.

dot(other)

 

Return the dot product of this vector and another.

Parameters:
  • other (Vector object) - The other vector to perform the dot product with.
Returns: float
The dot product.

Note: both vectors must be the same size.