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(value=None, w=0.0, dtype=None)[source]¶
- classmethod from_vector4(vector, dtype=None)[source]¶
Create a Vector3 from a Vector4.
Returns the Vector3 and the W component as a tuple.
- property inverse¶
Returns the opposite of this vector.
- property vector3¶
- x¶
The X value of this Vector.
- xy¶
The X,Y values of this Vector as a numpy.ndarray.
- xyz¶
The X,Y,Z values of this Vector as a numpy.ndarray.
- xz¶
The X,Z values of this Vector as a numpy.ndarray.
- y¶
The Y value of this Vector.
- z¶
The Z value of this Vector.
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(value=None, dtype=None)[source]¶
- classmethod from_vector3(vector, w=0.0, dtype=None)[source]¶
Create a Vector4 from a Vector3.
By default, the W value is 0.0.
- property inverse¶
Returns the opposite of this vector.
- property vector3¶
Returns a Vector3 and the W component as a tuple.
- w¶
The W value of this Vector.
- x¶
The X value of this Vector.
- xw¶
The X,W values of this Vector as a numpy.ndarray.
- xy¶
The X,Y values of this Vector as a numpy.ndarray.
- xyw¶
The X,Y,W values of this Vector as a numpy.ndarray.
- xyz¶
The X,Y,Z values of this Vector as a numpy.ndarray.
- xyzw¶
The X,Y,Z,W values of this Vector as a numpy.ndarray.
- xz¶
The X,Z values of this Vector as a numpy.ndarray.
- xzw¶
The X,Z,W values of this Vector as a numpy.ndarray.
- y¶
The Y value of this Vector.
- z¶
The Z value of this Vector.