Vectors

Vector3

Represents a 3 dimensional Vector.

The Vector3 class provides a number of convenient functions and conversions.

import numpy as np
from pyrr import Quaternion, Matrix33, Matrix44, Vector3

v = Vector3()
v = Vector3([1.,2.,3.])

# copy constructor
v = Vector3(Vector3())

# add / subtract vectors
v = Vector3([1.,2.,3.]) + Vector3([4.,5.,6.])

# rotate a vector by a Matrix
v = Matrix33.identity() * Vector3([1.,2.,3.])
v = Matrix44.identity() * Vector3([1.,2.,3.])

# rotate a vector by a Quaternion
v = Quaternion() * Vector3([1.,2.,3.])

# get the dot-product of 2 vectors
d = Vector3([1.,0.,0.]) | Vector3([0.,1.,0.])

# get the cross-product of 2 vectors
x = Vector3([1.,0.,0.]) ^ Vector3([0.,1.,0.])

# access specific parts of the vector
# x value
x,y,z = v.x, v.y, v.z

# access groups of values as np.ndarray's
xy = v.xy
xz = v.xz
xyz = v.xyz
class pyrr.objects.vector3.Vector3
classmethod from_vector4(vector, dtype=None)

Create a Vector3 from a Vector4.

Returns the Vector3 and the W component as a tuple.

inverse

Returns the opposite of this vector.

vector3
x
xy
xyz
xz
y
z

Vector4

Represents a 4 dimensional Vector.

The Vector4 class provides a number of convenient functions and conversions.

import numpy as np
from pyrr import Quaternion, Matrix33, Matrix44, Vector4

v = Vector4()
v = Vector4([1.,2.,3.])

# explicit creation
v = Vector4.from_vector3(Vector3([1.,2.,3.]), w=1.0)

# copy constructor
v = Vector4(Vector4())

# add / subtract vectors
v = Vector4([1.,2.,3.,4.]) + Vector4([4.,5.,6.,7.])

# rotate a vector by a Matrix
v = Matrix44.identity() * Vector4([1.,2.,3.,4.])

# rotate a vector by a Quaternion
v = Quaternion() * Vector4([1.,2.,3.,4.])

# get the dot-product of 2 vectors
d = Vector4([1.,0.,0.,0.]) | Vector4([0.,1.,0.,0.])

# access specific parts of the vector
# x value
x,y,z,w = v.x, v.y, v.z, v.w

# access groups of values as np.ndarray's
xy = v.xy
xyz = v.xyz
xyzw = v.xyzw
xz = v.xz
xw = v.xw
xyw = v.xyw
xzw = v.xzw
class pyrr.objects.vector4.Vector4
classmethod from_vector3(vector, w=0.0, dtype=None)

Create a Vector4 from a Vector3.

By default, the W value is 0.0.

inverse

Returns the opposite of this vector.

vector3

Returns a Vector3 and the W component as a tuple.

w
x
xw
xy
xyw
xyz
xyzw
xz
xzw
y
z