Graphmath.Mat44

This is the 3D mathematics library for graphmath.

This submodule handles 4x4 matrices using tuples of floats.

Summary

add(a, b)

add(a,b) adds one 4x4 matrix to another

apply(a, v)

apply( a, v ) transforms a vector v by a 4x4 matrix a

apply_left(v, a)

apply_left( v, a ) transforms a vector v by a 4x4 matrix a

apply_left_transpose(v, a)

apply_left_transpose( v, a ) transforms a vector v by a 4x4 matrix a transposed

apply_transpose(a, v)

apply_transpose( a, v ) transforms a vector v by a 4x4 matrix a transposed

at(a, i, j)

at( a, i, j) selects the element of a 4x4 matrix at row i and column j

column0(a)

column0( a ) selects the first column from a matrix 4x4 as a vec4

column1(a)

column1( a ) selects the second column from a matrix 4x4 as a vec4

column2(a)

column2( a ) selects the third column from a matrix 4x4 as a vec4

column3(a)

column3( a ) selects the fourth column from a matrix 4x4 as a vec4

diag(a)

diag( a ) selects the diagonal from a matrix 4x4 as a vec4

identity()

identity() creates a 4x4 identity matrix

make_rotate_x(theta)

make_rotate_x( theta ) creates a mat44 that rotates a vec3 by theta radians about the X axis

make_rotate_y(theta)

make_rotate_y( theta ) creates a mat44 that rotates a vec3 by theta radians about the Y axis

make_rotate_z(theta)

make_rotate_z( theta ) creates a mat44 that rotates a vec3 by theta radians about the Z axis

make_scale(k)

make_scale( k ) creates a mat44 that uniformly scales by a value k

make_scale(sx, sy, sz, sw)

make_scale( sx, sy, sz, sw ) creates a mat44 that scales by sx, sy, sz, and sz

make_translate(tx, ty, tz)

make_translate( tx, ty, tz ) creates a mat44 that translates a point by tx, ty, and tz

multiply(a, b)

multiply( a, b ) multiply two matrices a and b together

multiply_transpose(a, b)

multiply_transpose( a, b ) multiply two matrices a and b transpose together

round(a, sigfigs)

round( a, sigfigs ) rounds every element of a supplied mat44 a to number of digits sigfigs

row0(a)

row0( a ) selects the first row from a matrix 4x4 as a vec4

row1(a)

row1( a ) selects the second row from a matrix 4x4 as a vec4

row2(a)

row2( a ) selects the third row from a matrix 4x4 as a vec4

row3(a)

row3( a ) selects the fourth row from a matrix 4x4 as a vec4

scale(a, k)

scale( a, k ) scales every element in a matrix a by coefficient k

subtract(a, b)

subtract(a,b) subtracts one 4x4 matrix from another

transform_point(a, v)

transform_point( a, v ) transforms a vec3 point v by a matrix a

transform_vector(a, v)

transform_vector( a, v ) transforms a vec3 vector v by a matrix a

zero()

zero() creates a 4x4 zero matrix

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

add(a, b)

Specs:

add(a,b) adds one 4x4 matrix to another.

apply(a, v)

Specs:

apply( a, v ) transforms a vector v by a 4x4 matrix a.

apply_left(v, a)

Specs:

apply_left( v, a ) transforms a vector v by a 4x4 matrix a.

apply_left_transpose(v, a)

Specs:

apply_left_transpose( v, a ) transforms a vector v by a 4x4 matrix a transposed.

apply_transpose(a, v)

Specs:

apply_transpose( a, v ) transforms a vector v by a 4x4 matrix a transposed.

at(a, i, j)

Specs:

  • at(mat44, Integer, Integer) :: float

at( a, i, j) selects the element of a 4x4 matrix at row i and column j.

column0(a)

Specs:

column0( a ) selects the first column from a matrix 4x4 as a vec4.

column1(a)

Specs:

column1( a ) selects the second column from a matrix 4x4 as a vec4.

column2(a)

Specs:

column2( a ) selects the third column from a matrix 4x4 as a vec4.

column3(a)

Specs:

column3( a ) selects the fourth column from a matrix 4x4 as a vec4.

diag(a)

Specs:

diag( a ) selects the diagonal from a matrix 4x4 as a vec4.

identity()

Specs:

identity() creates a 4x4 identity matrix.

make_rotate_x(theta)

Specs:

  • make_rotate_x(float) :: mat44

make_rotate_x( theta ) creates a mat44 that rotates a vec3 by theta radians about the X axis.

make_rotate_y(theta)

Specs:

  • make_rotate_y(float) :: mat44

make_rotate_y( theta ) creates a mat44 that rotates a vec3 by theta radians about the Y axis.

make_rotate_z(theta)

Specs:

  • make_rotate_z(float) :: mat44

make_rotate_z( theta ) creates a mat44 that rotates a vec3 by theta radians about the Z axis.

make_scale(k)

Specs:

  • make_scale(float) :: mat44

make_scale( k ) creates a mat44 that uniformly scales by a value k.

make_scale(sx, sy, sz, sw)

Specs:

  • make_scale(float, float, float, float) :: mat44

make_scale( sx, sy, sz, sw ) creates a mat44 that scales by sx, sy, sz, and sz.

make_translate(tx, ty, tz)

Specs:

  • make_translate(float, float, float) :: mat44

make_translate( tx, ty, tz ) creates a mat44 that translates a point by tx, ty, and tz.

multiply(a, b)

Specs:

multiply( a, b ) multiply two matrices a and b together.

multiply_transpose(a, b)

Specs:

multiply_transpose( a, b ) multiply two matrices a and b transpose together.

round(a, sigfigs)

Specs:

round( a, sigfigs ) rounds every element of a supplied mat44 a to number of digits sigfigs.

row0(a)

Specs:

row0( a ) selects the first row from a matrix 4x4 as a vec4.

row1(a)

Specs:

row1( a ) selects the second row from a matrix 4x4 as a vec4.

row2(a)

Specs:

row2( a ) selects the third row from a matrix 4x4 as a vec4.

row3(a)

Specs:

row3( a ) selects the fourth row from a matrix 4x4 as a vec4.

scale(a, k)

Specs:

scale( a, k ) scales every element in a matrix a by coefficient k.

subtract(a, b)

Specs:

subtract(a,b) subtracts one 4x4 matrix from another..

transform_point(a, v)

Specs:

transform_point( a, v ) transforms a vec3 point v by a matrix a.

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.

transform_vector(a, v)

Specs:

transform_vector( a, v ) transforms a vec3 vector v by a matrix a.

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.

zero()

Specs:

zero() creates a 4x4 zero matrix.