Graphmath.Mat44
This is the 3D mathematics library for graphmath.
This submodule handles 4x4 matrices using tuples of floats.
Summary
add(a, b) |
|
apply(a, v) |
|
apply_left(v, a) |
|
apply_left_transpose(v, a) |
|
apply_transpose(a, v) |
|
at(a, i, j) |
|
column0(a) |
|
column1(a) |
|
column2(a) |
|
column3(a) |
|
diag(a) |
|
identity() |
|
make_rotate_x(theta) |
|
make_rotate_y(theta) |
|
make_rotate_z(theta) |
|
make_scale(k) |
|
make_scale(sx, sy, sz, sw) |
|
make_translate(tx, ty, tz) |
|
multiply(a, b) |
|
multiply_transpose(a, b) |
|
round(a, sigfigs) |
|
row0(a) |
|
row1(a) |
|
row2(a) |
|
row3(a) |
|
scale(a, k) |
|
subtract(a, b) |
|
transform_point(a, v) |
|
transform_vector(a, v) |
|
zero() |
|
Types ↑
mat44 :: {float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float}
vec4 :: {float, float, float, float}
vec3 :: {float, float, float}
Functions
Specs:
add(a,b)
adds one mat44
to another mat44
.
a
is the first mat44
.
b
is the second mat44
.
This returns a mat44
which is the element-wise sum of a
and b
.
Specs:
apply( a, v )
transforms a vec4
by a mat44
.
a
is the mat44
to transform by.
v
is the vec4
to be transformed.
This returns a vec4
representing A**v**.
This is the “full” application of a matrix, and uses all elements.
Specs:
apply_left( v, a )
transforms a vec4
by a mat44
, applied on the left.
a
is the mat44
to transform by.
v
is the vec4
to be transformed.
This returns a vec4
representing v**A**.
This is the “full” application of a matrix, and uses all elements.
Specs:
apply_left_transpose( v, a )
transforms a vec3
by a transposed mat33
, applied on the left.
a
is the mat44
to transform by.
v
is the vec4
to be transformed.
This returns a vec4
representing v**A**T.
This is the “full” application of a matrix, and uses all elements.
Specs:
apply_transpose( a, v )
transforms a vec4
by a a transposed mat44
.
a
is the mat44
to transform by.
v
is the vec4
to be transformed.
This returns a vec4
representing ATv.
This is the “full” application of a matrix, and uses all elements.
Specs:
- at(mat44, Integer, Integer) :: float
at( a, i, j)
selects an element of a mat44
.
a
is the mat44
to index.
i
is the row integer index [0,3].
j
is the column integer index [0,3].
This returns a float from the matrix at row i
and column j
.
Specs:
column0( a )
selects the first column of a mat44
.
a
is the mat44
to take the first column of.
This returns a vec4
representing the first column of a
.
Specs:
column1( a )
selects the second column of a mat44
.
a
is the mat44
to take the second column of.
This returns a vec4
representing the second column of a
.
Specs:
column2( a )
selects the third column of a mat44
.
a
is the mat44
to take the third column of.
This returns a vec4
representing the third column of a
.
Specs:
column3( a )
selects the fourth column of a mat44
.
a
is the mat44
to take the fourth column of.
This returns a vec4
representing the fourth column of a
.
Specs:
diag( a )
selects the diagonal of a mat44
.
a
is the mat44
to take the diagonal of.
This returns a vec4
representing the diagonal of a
.
Specs:
- make_rotate_x(float) :: mat44
make_rotate_x( theta )
creates a mat44
that rotates a vec3
by theta
radians about the +X axis.
theta
is the float of the number of radians of rotation the matrix will provide.
This returns a mat44
which rotates by theta
radians about the +X axis.
Specs:
- make_rotate_y(float) :: mat44
make_rotate_y( theta )
creates a mat44
that rotates a vec3
by theta
radians about the +Y axis.
theta
is the float of the number of radians of rotation the matrix will provide.
This returns a mat44
which rotates by theta
radians about the +Y axis.
Specs:
- make_rotate_z(float) :: mat44
make_rotate_Z( theta )
creates a mat44
that rotates a vec3
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 mat44
which rotates by theta
radians about the +Z axis.
Specs:
- make_scale(float) :: mat44
make_scale( k )
creates a mat44
that uniformly scales.
k
is the float value to scale by.
This returns a mat44
whose diagonal is all k
s.
Specs:
- make_scale(float, float, float, float) :: mat44
make_scale( sx, sy, sz, sw )
creates a mat44
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.
sw
is a float for scaling the w-axis.
This returns a mat44
whose diagonal is { sx, sy, sz, sw }
.
Note that, when used with vec3
s via the transform methods, sw
will have no effect.
Specs:
- make_translate(float, float, float) :: mat44
make_translate( tx, ty, tz )
creates a mat44 that translates a point by tx, ty, and tz.
make_translate( tx, ty, tz )
creates a mat44 that translates a vec3 by (tx, ty, tz).
tx
is a float for translating along the x-axis.
ty
is a float for translating along the y-axis.
tz
is a float for translating along the z-axis.
This returns a mat44
which translates by a vec3
{ tx, ty, tz }
.
Specs:
multiply( a, b )
multiply two matrices a and b together.
a
is the mat44
multiplicand.
b
is the mat44
multiplier.
This returns the mat44
product of the a
and b
.
Specs:
multiply_transpose( a, b )
multiply two matrices a and bT together.
a
is the mat44
multiplicand.
b
is the mat44
multiplier.
This returns the mat44
product of the a
and b
T.
Specs:
round( a, sigfigs )
rounds every element of a mat44
to some number of decimal places.
a
is the mat44
to round.
sigfigs
is an integer on [0,15] of the number of decimal places to round to.
This returns a mat44
which is the result of rounding a
.
Specs:
row0( a )
selects the first row of a mat44
.
a
is the mat44
to take the first row of.
This returns a vec4
representing the first row of a
.
Specs:
row1( a )
selects the second row of a mat44
.
a
is the mat44
to take the second row of.
This returns a vec4
representing the second row of a
.
Specs:
row2( a )
selects the third row of a mat44
.
a
is the mat44
to take the third row of.
This returns a vec4
representing the third row of a
.
Specs:
row3( a )
selects the fourth row of a mat44
.
a
is the mat44
to take the fourth row of.
This returns a vec4
representing the fourth row of a
.
Specs:
scale( a, k )
scales every element in a mat44
by a coefficient k.
a
is the mat44
to scale.
k
is the float to scale by.
This returns a mat44
a
scaled element-wise by k
.
Specs:
subtract(a,b)
subtracts one mat44
from another mat44
.
a
is the minuend.
b
is the subtraherd.
This returns a mat44
formed by the element-wise subtraction of b
from a
.
Specs:
transform_point( a, v )
transforms a vec3
point by a mat44
.
a
is a mat44
used to transform the point.
v
is a vec3
to be transformed.
This returns a vec3
representing the application of a
to v
.
The point a
is internally treated as having a fourth coordinate equal to 1.0.
Note that transforming a point will work for all transforms.
Specs:
transform_vector( a, v )
transforms a vec3
vector by a mat44
.
a
is a mat44
used to transform the point.
v
is a vec3
to be transformed.
This returns a vec3
representing the application of a
to v
.
The point a
is internally treated as having a fourth coordinate equal to 0.0.
Note that transforming a vector will work for only rotations, scales, and shears.