Matrices¶
Matrix33¶
Represents a 3x3 Matrix.
The Matrix33 class provides a number of convenient functions and conversions.
import numpy as np
from pyrr import Quaternion, Matrix33, Matrix44, Vector3
m = Matrix33()
m = Matrix33([[1.,0.,0.],[0.,1.,0.],[0.,0.,1.]])
# copy constructor
m = Matrix44(Matrix44())
# explicit creation
m = Matrix33.identity()
m = Matrix33.from_matrix44(Matrix44())
# inferred conversions
m = Matrix33(Quaternion())
m = Matrix33(Matrix44())
# multiply matricies together
m = Matrix33() * Matrix33()
m = Matrix33() * Matrix44()
# extract a quaternion from a matrix
q = m.quaternion
# convert from quaternion back to matrix
m = q.matrix33
m = Matrix33(q)
# rotate a matrix by a quaternion
m = Matrix33.identity() * Quaternion()
# rotate a vector 3 by a matrix
v = Matrix33.from_x_rotation(np.pi) * Vector3([1.,2.,3.])
# undo a rotation
m = Matrix33.from_x_rotation(np.pi)
v = m * Vector3([1.,1.,1.])
# ~m is the same as m.inverse
v = ~m * v
# access specific parts of the matrix
# first row
m1 = m.m1
# first element, first row
m11 = m.m11
# third element, third row
m33 = m.m33
# first row, same as m1
r1 = m.r1
# first column
c1 = m.c1
-
class
pyrr.objects.matrix33.
Matrix33
¶ -
c1
¶
-
c2
¶
-
c3
¶
-
classmethod
from_matrix44
(matrix, dtype=None)¶ Creates a Matrix33 from a Matrix44.
The Matrix44 translation will be lost.
-
m1
¶
-
m11
¶
-
m12
¶
-
m13
¶
-
m2
¶
-
m21
¶
-
m22
¶
-
m23
¶
-
m3
¶
-
m31
¶
-
m32
¶
-
m33
¶
-
matrix33
¶ Returns the Matrix33.
This can be handy if you’re not sure what type of Matrix class you have but require a Matrix33.
-
matrix44
¶ Returns a Matrix44 representing this matrix.
-
quaternion
¶ Returns a Quaternion representing this matrix.
-
r1
¶
-
r2
¶
-
r3
¶
-
Matrix44¶
Represents a 4x4 Matrix.
The Matrix44 class provides a number of convenient functions and conversions.
import numpy as np
from pyrr import Quaternion, Matrix33, Matrix44, Vector4
m = Matrix44()
m = Matrix44([[1.,0.,0.,0.],[0.,1.,0.,0.],[0.,0.,1.,0.],[0.,0.,0.,1.]])
# copy constructor
m = Matrix44(Matrix44())
# explicit creation
m = Matrix44.identity()
m = Matrix44.from_matrix44(Matrix44())
# inferred conversions
m = Matrix44(Quaternion())
m = Matrix44(Matrix33())
# multiply matricies together
m = Matrix44() * Matrix44()
# extract a quaternion from a matrix
q = m.quaternion
# convert from quaternion back to matrix
m = q.matrix44
m = Matrix44(q)
# rotate a matrix by a quaternion
m = Matrix44.identity() * Quaternion()
# rotate a vector 4 by a matrix
v = Matrix44.from_x_rotation(np.pi) * Vector4([1.,2.,3.,1.])
# undo a rotation
m = Matrix44.from_x_rotation(np.pi)
v = m * Vector4([1.,1.,1.,1.])
# ~m is the same as m.inverse
v = ~m * v
# access specific parts of the matrix
# first row
m1 = m.m1
# first element, first row
m11 = m.m11
# fourth element, fourth row
m44 = m.m44
# first row, same as m1
r1 = m.r1
# first column
c1 = m.c1
-
class
pyrr.objects.matrix44.
Matrix44
¶ -
c1
¶
-
c2
¶
-
c3
¶
-
c4
¶
-
decompose
()¶ Decomposes an affine transformation matrix into its scale, rotation and translation components.
Parameters: m (numpy.array) – A matrix. Returns: tuple (scale, rotation, translation) Vector3 scale Quaternion rotation Vector3 translation
-
classmethod
from_matrix33
(matrix, dtype=None)¶ Creates a Matrix44 from a Matrix33.
-
classmethod
from_translation
(translation, dtype=None)¶ Creates a Matrix44 from the specified translation.
-
classmethod
look_at
(eye, target, up, dtype=None)¶ Creates a Matrix44 for use as a lookAt matrix.
-
m1
¶
-
m11
¶
-
m12
¶
-
m13
¶
-
m14
¶
-
m2
¶
-
m21
¶
-
m22
¶
-
m23
¶
-
m24
¶
-
m3
¶
-
m31
¶
-
m32
¶
-
m33
¶
-
m34
¶
-
m4
¶
-
m41
¶
-
m42
¶
-
m43
¶
-
m44
¶
-
matrix33
¶ Returns a Matrix33 representing this matrix.
-
matrix44
¶ Returns the Matrix44.
This can be handy if you’re not sure what type of Matrix class you have but require a Matrix44.
-
classmethod
orthogonal_projection
(left, right, top, bottom, near, far, dtype=None)¶ Creates a Matrix44 for use as an orthogonal projection matrix.
-
classmethod
perspective_projection
(fovy, aspect, near, far, dtype=None)¶ Creates a Matrix44 for use as a perspective projection matrix.
-
classmethod
perspective_projection_bounds
(left, right, top, bottom, near, far, dtype=None)¶ Creates a Matrix44 for use as a perspective projection matrix.
-
quaternion
¶ Returns a Quaternion representing this matrix.
-
r1
¶
-
r2
¶
-
r3
¶
-
r4
¶
-