View Source Graphmath.Mat33 (graphmath v3.0.0)
3x3 matrices for 3D linear algebra and 2D affine transformations.
Matrices use tuples of floats. Reflection and shear constructors explicitly name the spatial dimension:
_2dconstructors act on{x, y, w}, wherewis a homogeneous coordinate. Usetransform_point/2for points (w = 1) andtransform_vector/2for directions (w = 0)._3dconstructors act on full spatial vectors{x, y, z}. Useapply_left/2; all three coordinates participate in the linear transform.
For 3D affine transformations, including translation, use Graphmath.Mat44.
Tuples store matrix rows in order: {a11,a12,a13,a21,a22,a23,a31,a32,a33}.
apply(a, v) computes the column-vector product A**v. Graphics
constructors use row vectors: transform_point/2 and transform_vector/2
multiply {x,y,1} and {x,y,0} by A** from the left, then drop the third
coordinate. Use apply_left(v, a) or apply_transpose(a, v) for the
corresponding full three-component product.
For full vectors, apply_left(v, multiply(a, b)) applies a first, then b.
Summary
Functions
add(a,b) adds one mat33 to another mat33.
apply( a, v ) transforms a vec3 by a mat33.
apply_left( v, a ) transforms a vec3 by a mat33, applied on the left.
apply_left_transpose( v, a ) transforms a vec3 by a transposed mat33, applied on the left.
apply_transpose( a, v ) transforms a vec3 by a a transposed mat33.
at( a, i, j) selects an element of a mat33.
Returns the signed minor at zero-based row i and column j.
column0( a ) selects the first column of a mat33.
column1( a ) selects the second column of a mat33.
column2( a ) selects the third column of a mat33.
Returns the determinant of a.
diag( a ) selects the diagonal of a mat33.
identity() creates an identity mat33.
inverse(a) calculates the inverse matrix
Creates a 2D affine reflection across nx*x + ny*y = offset.
Creates a 3D linear reflection across the plane through the origin
with normal {nx, ny, nz}.
make_rotate( theta ) creates a mat33 that rotates a vec2 by theta radians about the +Z axis.
make_scale( k ) creates a mat33 that uniformly scales.
make_scale( sx, sy, sz ) creates a mat33 that scales each axis independently.
Creates a 2D affine X shear: x' = x + k*y.
Creates a 3D linear X shear: x' = x + ky*y + kz*z.
Creates a 2D affine Y shear: y' = y + k*x.
Creates a 3D linear Y shear: y' = y + kx*x + kz*z.
Creates a 3D linear Z shear: z' = z + kx*x + ky*y.
make_translate( tx, ty ) creates a mat33 that translates a vec2 by (tx, ty).
multiply( a, b ) multiply two matrices a and b together.
multiply_transpose( a, b ) multiply two matrices a and b<sup>T</sup> together.
Orthonormalizes the three rows of a, returning floating-point entries.
round( a, sigfigs ) rounds every element of a mat33 to some number of decimal places.
row0( a ) selects the first row of a mat33.
row1( a ) selects the second row of a mat33.
row2( a ) selects the third row of a mat33.
scale( a, k ) scales every element in a mat33 by a coefficient k.
Returns the Graphmath.Mat22 obtained by deleting row i and column j.
subtract(a,b) subtracts one mat33 from another mat33.
Returns the trace, the sum of the diagonal entries.
Transforms a 2D point {x, y} using the row-vector product {x, y, 1.0} a.
Transforms a 2D direction {x, y} using the row-vector product {x, y, 0.0} a.
zero() creates a zeroed mat33.
Types
Functions
add(a,b) adds one mat33 to another mat33.
a is the first mat33.
b is the second mat33.
This returns a mat33 which is the element-wise sum of a and b.
apply( a, v ) transforms a vec3 by a mat33.
a is the mat33 to transform by.
v is the vec3 to be transformed.
This returns a vec3 representing A**v**.
This is the "full" application of a matrix, and uses all elements.
apply_left( v, a ) transforms a vec3 by a mat33, applied on the left.
a is the mat33 to transform by.
v is the vec3 to be transformed.
This returns a vec3 representing v**A**.
This is the "full" application of a matrix, and uses all elements.
apply_left_transpose( v, a ) transforms a vec3 by a transposed mat33, applied on the left.
a is the mat33 to transform by.
v is the vec3 to be transformed.
This returns a vec3 representing v**A**<sup>T</sup>.
This is the "full" application of a matrix, and uses all elements.
apply_transpose( a, v ) transforms a vec3 by a a transposed mat33.
a is the mat33 to transform by.
v is the vec3 to be transformed.
This returns a vec3 representing A<sup>T</sup>v.
This is the "full" application of a matrix, and uses all elements.
at( a, i, j) selects an element of a mat33.
a is the mat33 to index.
i is the row integer index [0,2].
j is the column integer index [0,2].
This returns a float from the matrix at row i and column j.
Returns the signed minor at zero-based row i and column j.
This is the determinant of submatrix(a, i, j), negated when i + j
is odd. Indices must be integers from 0 through 2; invalid indices raise
FunctionClauseError.
column0( a ) selects the first column of a mat33.
a is the mat33 to take the first column of.
This returns a vec3 representing the first column of a.
column1( a ) selects the second column of a mat33.
a is the mat33 to take the second column of.
This returns a vec3 representing the second column of a.
column2( a ) selects the third column of a mat33.
a is the mat33 to take the third column of.
This returns a vec3 representing the third column of a.
Returns the determinant of a.
diag( a ) selects the diagonal of a mat33.
a is the mat33 to take the diagonal of.
This returns a vec3 representing the diagonal of a.
@spec identity() :: mat33()
identity() creates an identity mat33.
This returns an identity mat33.
inverse(a) calculates the inverse matrix
a is a mat33 to be inverted
Returs a mat33 representing a<sup>-1</sup>
Raises an error when you try to calculate inverse of a matrix whose determinant is zero
Creates a 2D affine reflection across nx*x + ny*y = offset.
The normal may have any nonzero length. offset is the line equation
constant; it is a signed distance only when the normal has unit length.
Scaling the normal and offset by the same nonzero factor leaves the mirror
unchanged. A zero normal raises ArithmeticError.
Use transform_point/2 for points and transform_vector/2 for directions.
The homogeneous coordinate is preserved; translation affects only points.
Creates a 3D linear reflection across the plane through the origin
with normal {nx, ny, nz}.
The normal may have any nonzero length; a zero normal raises ArithmeticError.
Apply using apply_left/2 with a full 3-component vector.
make_rotate( theta ) creates a mat33 that rotates a vec2 by theta radians about the +Z axis.
theta is the float of the number of radians of rotation the matrix will provide.
This returns a mat33 which rotates by theta radians about the +Z axis.
make_scale( k ) creates a mat33 that uniformly scales.
k is the float value to scale by.
This returns a mat33 whose diagonal is all ks.
make_scale( sx, sy, sz ) creates a mat33 that scales each axis independently.
sx is a float for scaling the x-axis.
sy is a float for scaling the y-axis.
sz is a float for scaling the z-axis.
This returns a mat33 whose diagonal is { sx, sy, sz }.
Note that, when used with vec2s via the transform methods, sz will have no effect.
Creates a 2D affine X shear: x' = x + k*y.
The other spatial coordinates and homogeneous coordinate are unchanged.
Use transform_point/2 or transform_vector/2 with 2 spatial components.
Creates a 3D linear X shear: x' = x + ky*y + kz*z.
The other spatial coordinates are unchanged.
Apply using apply_left/2 with a full 3-component vector.
Creates a 2D affine Y shear: y' = y + k*x.
The other spatial coordinates and homogeneous coordinate are unchanged.
Use transform_point/2 or transform_vector/2 with 2 spatial components.
Creates a 3D linear Y shear: y' = y + kx*x + kz*z.
The other spatial coordinates are unchanged.
Apply using apply_left/2 with a full 3-component vector.
Creates a 3D linear Z shear: z' = z + kx*x + ky*y.
The other spatial coordinates are unchanged.
Apply using apply_left/2 with a full 3-component vector.
make_translate( tx, ty ) creates a mat33 that translates a vec2 by (tx, ty).
tx is a float for translating along the x-axis.
ty is a float for translating along the y-axis.
This returns a mat33 which translates by a vec2 { tx, ty }.
multiply( a, b ) multiply two matrices a and b together.
a is the mat33 multiplicand.
b is the mat33 multiplier.
This returns the mat33 product of the a and b.
multiply_transpose( a, b ) multiply two matrices a and b<sup>T</sup> together.
a is the mat33 multiplicand.
b is the mat33 multiplier.
This returns the mat33 product of the a and b<sup>T</sup>.
Orthonormalizes the three rows of a, returning floating-point entries.
Uses modified Gram-Schmidt with a second orthogonalization pass. Rows are processed in order: the first row keeps its direction, the second has its component along the first removed, and the third has its components along both removed. The resulting rows have unit length and are mutually perpendicular, preserving the input's handedness (including reflections).
Each input row is normalized before removing projections, so the result
does not depend on positive scaling of individual rows. Raises
ArithmeticError for a zero row or when a remaining perpendicular component
has length at most 1.0e-12, treating nearly dependent rows as degenerate.
This treats all three rows as a 3D basis, following the row-vector convention. It is order-dependent and does not preserve 2D homogeneous translation.
Examples
iex> Graphmath.Mat33.orthonormalize({2.0, 0.0, 0.0, 1.0, 3.0, 0.0, 4.0, 5.0, 6.0})
{1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}
round( a, sigfigs ) rounds every element of a mat33 to some number of decimal places.
a is the mat33 to round.
sigfigs is an integer on [0,15] of the number of decimal places to round to.
This returns a mat33 which is the result of rounding a.
row0( a ) selects the first row of a mat33.
a is the mat33 to take the first row of.
This returns a vec3 representing the first row of a.
row1( a ) selects the second row of a mat33.
a is the mat33 to take the second row of.
This returns a vec3 representing the second row of a.
row2( a ) selects the third row of a mat33.
a is the mat33 to take the third row of.
This returns a vec3 representing the third row of a.
scale( a, k ) scales every element in a mat33 by a coefficient k.
a is the mat33 to scale.
k is the float to scale by.
This returns a mat33 a scaled element-wise by k.
@spec submatrix(mat33(), 0..2, 0..2) :: Graphmath.Mat22.mat22()
Returns the Graphmath.Mat22 obtained by deleting row i and column j.
The remaining entries retain their row-major order. Indices are zero-based
integers from 0 through 2; invalid indices raise FunctionClauseError.
This returns a matrix. Its determinant is the corresponding scalar minor.
subtract(a,b) subtracts one mat33 from another mat33.
a is the minuend.
b is the subtraherd.
This returns a mat33 formed by the element-wise subtraction of b from a.
Returns the trace, the sum of the diagonal entries.
Transforms a 2D point {x, y} using the row-vector product {x, y, 1.0} a.
Returns the first two coordinates, including the effect of translation.
Use with 2D affine matrices. No perspective division is performed.
For a full 3D linear transformation, use apply_left/2 with {x, y, z}.
Transforms a 2D direction {x, y} using the row-vector product {x, y, 0.0} a.
Returns the first two coordinates. The zero homogeneous coordinate excludes
translation; rotations, scales, reflections and shears still affect the vector.
For a full 3D linear transformation, use apply_left/2 with {x, y, z}.
@spec zero() :: mat33()
zero() creates a zeroed mat33.
This returns a zeroed mat33.