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

Class Vector

source code

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 = Object(wrappedObject) #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 [hide private]
Vector object.
__init__(list=None)
Create a new 2d, 3d, or 4d Vector object from a list of floating point numbers.
source code
 
copy()
Returns a copy of this vector
source code
 
zero()
Set all values to zero.
source code
 
normalize()
Normalize the vector, making the length of the vector always 1.0
source code
 
negate()
Set all values to their negative.
source code
 
resize2D()
Resize the vector to 2d.
source code
 
resize3D()
Resize the vector to 3d.
source code
 
resize4D()
Resize the vector to 4d.
source code
Quaternion
toTrackQuat(track, up)
Return a quaternion rotation from the vector and the track and up axis.
source code
Vector object matching the size of this vector.
reflect(mirror)
Return the reflection vector from the mirror vector argument.
source code
Instance Variables [hide private]
  length
The magnitude of the vector.
  magnitude
This is a synonym for length.
  w
The w value (if any).
  wrapped
Whether or not this item is wrapped data
  x
The x value.
  y
The y value.
  z
The z value (if any).
Method Details [hide private]

__init__(list=None)
(Constructor)

source code 

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()

source code 

Returns a copy of this vector

Returns:
a copy of itself

zero()

source code 

Set all values to zero.

Returns:
an instance of itself

normalize()

source code 

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()

source code 

Set all values to their negative.

Returns:
an instance of its self

resize2D()

source code 

Resize the vector to 2d.

Returns:
an instance of itself

resize3D()

source code 

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

Returns:
an instance of itself

resize4D()

source code 

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)

source code 

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)

source code 

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.