View Source Graphmath.Mat22 (graphmath v3.0.0)
2x2 matrices and linear transformations of 2D vectors.
Matrices store rows in a flat tuple {a11, a12, a21, a22}:
a11 a12
a21 a22The matrix and vector types use floating-point entries. Integer and mixed
numeric inputs are also accepted, following Elixir's numeric promotion rules;
round/2 and inverse/1 return floats.
As in Graphmath.Mat33, apply(a, v) computes the column-vector product
A**v. Graphics constructors use row vectors: transform_vector(a, v)
and apply_left(v, a) compute v**A, as does apply_transpose(a, v).
For row vectors, multiply(a, b) applies a first, then b.
These matrices support scale, rotation, reflection, and shear. Use
Graphmath.Mat33 for 2D transformations that also include translation.
Summary
Functions
Adds corresponding entries of a and b.
Returns the column-vector product A**v**.
Returns the row-vector product v**A**.
Returns v**A**<sup>T</sup>, equivalent to apply(a, v).
Returns A<sup>T</sup>v, equivalent to apply_left(v, a).
Returns the entry at zero-based row i and column j.
Returns the first column, {a11, a21}.
Returns the second column, {a12, a22}.
Returns the determinant, a11 * a22 - a12 * a21.
Returns the diagonal entries, {a11, a22}.
Returns the identity matrix {1.0, 0.0, 0.0, 1.0}.
Returns the inverse matrix, with floating-point entries.
Creates a 2D linear reflection across the line through the origin
with normal {nx, ny}.
Returns a matrix that rotates row vectors counterclockwise by theta radians
about +Z. Apply it with transform_vector/2 or apply_left/2.
Returns a matrix that uniformly scales both vector coordinates by k.
Returns a matrix that scales X by sx and Y by sy.
Creates a 2D linear X shear: x' = x + k*y.
Creates a 2D linear Y shear: y' = y + k*x.
Returns the matrix product A**B**.
Returns A**B**<sup>T</sup>, multiplying a by the transpose of b.
Rounds every entry to sigfigs decimal places, returning floats.
Returns the first row, {a11, a12}.
Returns the second row, {a21, a22}.
Multiplies every entry of a by the scalar k.
Subtracts each entry of b from the corresponding entry of a.
Returns the trace, the sum of the diagonal entries a11 + a22.
Transforms a 2D vector using the row-vector convention, computing v**A**.
Returns the zero matrix {0.0, 0.0, 0.0, 0.0}.
Types
Functions
Adds corresponding entries of a and b.
Returns the column-vector product A**v**.
Returns the row-vector product v**A**.
Returns v**A**<sup>T</sup>, equivalent to apply(a, v).
Returns A<sup>T</sup>v, equivalent to apply_left(v, a).
Returns the entry at zero-based row i and column j.
Both indices must be 0 or 1; invalid indices raise FunctionClauseError.
Returns the first column, {a11, a21}.
Returns the second column, {a12, a22}.
Returns the determinant, a11 * a22 - a12 * a21.
Returns the diagonal entries, {a11, a22}.
@spec identity() :: mat22()
Returns the identity matrix {1.0, 0.0, 0.0, 1.0}.
Returns the inverse matrix, with floating-point entries.
Raises ArithmeticError when the determinant is zero.
Creates a 2D linear reflection across the line through the origin
with normal {nx, ny}.
The normal may have any nonzero length; a zero normal raises ArithmeticError.
Apply using transform_vector/2 with a full 2-component vector.
Returns a matrix that rotates row vectors counterclockwise by theta radians
about +Z. Apply it with transform_vector/2 or apply_left/2.
Returns a matrix that uniformly scales both vector coordinates by k.
Returns a matrix that scales X by sx and Y by sy.
Creates a 2D linear X shear: x' = x + k*y.
The other spatial coordinates are unchanged.
Apply using transform_vector/2 with a full 2-component vector.
Creates a 2D linear Y shear: y' = y + k*x.
The other spatial coordinates are unchanged.
Apply using transform_vector/2 with a full 2-component vector.
Returns the matrix product A**B**.
Returns A**B**<sup>T</sup>, multiplying a by the transpose of b.
Rounds every entry to sigfigs decimal places, returning floats.
sigfigs must be an integer from 0 through 15, as required by Float.round/2.
Returns the first row, {a11, a12}.
Returns the second row, {a21, a22}.
Multiplies every entry of a by the scalar k.
Subtracts each entry of b from the corresponding entry of a.
Returns the trace, the sum of the diagonal entries a11 + a22.
Transforms a 2D vector using the row-vector convention, computing v**A**.
This agrees with the scale and rotation constructors and is equivalent to
apply_left(v, a).
@spec zero() :: mat22()
Returns the zero matrix {0.0, 0.0, 0.0, 0.0}.