mat3 - a 3x3 matrix
A mat3 represents a 3x3 matrix which can be used to store linear
transformations (if you want to store translations or perspective
transformations, you have to use a mat4).
You can construct a mat3 by several ways:
# all components are set to zero
M = mat3()
[ 0.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000]
# identity matrix
M = mat3(1.0)
[ 1.0000, 0.0000, 0.0000]
[ 0.0000, 1.0000, 0.0000]
[ 0.0000, 0.0000, 1.0000]
# The elements on the diagonal are set to 2.5
M = mat3(2.5)
[ 2.5000, 0.0000, 0.0000]
[ 0.0000, 2.5000, 0.0000]
[ 0.0000, 0.0000, 2.5000]
# All elements are explicitly set (values must be given in row-major order)
M = mat3(a,b,c,d,e,f,g,h,i)
M = mat3([a,b,c,d,e,f,g,h,i])
[ a, b, c]
[ d, e, f]
[ g, h, i]
# Create a copy of matrix N (which also has to be a mat3)
M = mat3(N)
# Specify the 3 columns of the matrix (as vec3's or sequences with 3 elements)
M = mat3(a,b,c)
[ a[0], b[0], c[0] ]
[ a[1], b[1], c[1] ]
[ a[2], b[2], c[2] ]
# All elements are explicitly set and are stored inside a string
M = mat3("1,2,3,4,5,6,7,8,9")
[ 1.0000, 2.0000, 3.0000]
[ 4.0000, 5.0000, 6.0000]
[ 7.0000, 8.0000, 9.0000]
Mathematical operations:
The mathematical operators are supported with the following combination
of types:
mat3 = mat3 + mat3
mat3 = mat3 - mat3
mat3 = mat3 * mat3
vec3 = mat3 * vec3
vec3 = vec3 * mat3
mat3 = float * mat3
mat3 = mat3 * float
mat3 = mat3 / float
mat3 = mat3 % float # each component
mat3 = -mat3
vec3 = mat3[i] # get or set column i (as vec3)
float = mat3[i,j] # get or set element in row i and column j
Additionally, you can compare vectors with == and !=.
Methods:
- getColumn(index)
- Return column index (0-based) as a vec3.
- setColumn(index, value)
- Set column index (0-based) to value which
has to be a sequence with 3 floats (this includes vec3).
- getRow(index)
- Return row index (0-based) as a vec3.
- setRow(index, value)
- Set row index (0-based) to value which
has to be a sequence with 3 floats (this includes vec3).
- toList([rowmajor])
- Returns a list containing the matrix elements.
By default the list is in column-major order. If you set the optional argument
rowmajor to 1, you'll get the list in row-major order.
- identity()
- Returns the identity matrix.
[1 0 0]
[0 1 0]
[0 0 1]
- transpose()
- Returns the transpose of the matrix.
- determinant()
- Returns the determinant of the matrix.
- inverse()
- Returns the inverse of the matrix.
- scaling(s)
- Returns a scaling transformation. The scaling vector
s must be a 3-sequence (e.g. a vec3).
[s.x 0 0 ]
[0 s.y 0 ]
[0 0 s.z]
- rotation(angle, axis)
- Returns a rotation transformation. The angle must be
given in radians, axis has to be a 3-sequence (e.g. a vec3).
- scale(s)
- Concatenates a scaling transformation and returns self. The scaling vector
s must be a 3-sequence (e.g. a vec3).
- rotate(angle, axis)
- Concatenates a rotation transformation and returns self.
The angle must be given in radians, axis has to be
a 3-sequence (e.g. a vec3).
- ortho()
- Returns a matrix with orthogonal base vectors.
- decompose()
- Decomposes the matrix into a rotation and scaling part.
The method returns a tuple (rotation, scaling). The scaling part is given
as a
vec3
, the rotation is still a mat3
.
Copyright © 2002 Matthias Baas
(baas@ira.uka.de)