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

Class Vector


The Vector object

This object gives access to Vectors in Blender.

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'

Notes:

Method Summary
Vector object. __init__(list)
Create a new 2d, 3d, or 4d Vector object from a list of floating point numbers.
  copy()
Returns a copy of this vector
  negate()
Set all values to their negative.
  normalize()
Normalize the vector, making the length of the vector always 1.0
  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.
  zero()
Set all values to zero.

Instance Variable Summary
  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

__init__(list=None)
(Constructor)

Create a new 2d, 3d, or 4d Vector object from a list of floating point numbers.
Parameters:
list - 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].
           (type=PyList of float or int)
Returns:
It depends wheter a parameter was passed:
  • (list): Vector object initialized with the given values;
  • (): An empty 3 dimensional vector.

           (type=Vector object.)

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

negate()

Set all values to their negative.
Returns:
an instance of its self

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

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 - 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"

           (type=String.)
up - Possible values:
  • "x - x-axis up"
  • "y - y-axis up"
  • "z - z-axis up"

           (type=String.)
Returns:
Return a quaternion rotation from the vector and the track and up axis.
           (type=Quaternion)

zero()

Set all values to zero.
Returns:
an instance of itself

Instance Variable Details

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

Generated by Epydoc 2.1 on Thu May 10 20:32:00 2007 http://epydoc.sf.net