View Source Graphmath.Mat44 (graphmath v2.6.0)

This is the 3D mathematics.

This submodule handles 4x4 matrices using tuples of floats.

Summary

Functions

add(a,b) adds one mat44 to another mat44.

apply( a, v ) transforms a vec4 by a mat44.

apply_left( v, a ) transforms a vec4 by a mat44, 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 vec4 by a a transposed mat44.

at( a, i, j) selects an element of a mat44.

column0( a ) selects the first column of a mat44.

column1( a ) selects the second column of a mat44.

column2( a ) selects the third column of a mat44.

column3( a ) selects the fourth column of a mat44.

diag( a ) selects the diagonal of a mat44.

identity() creates an identity mat44.

inverse(a) calculates the inverse matrix

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

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

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

make_scale( k ) creates a mat44 that uniformly scales.

make_scale( sx, sy, sz, sw ) creates a mat44 that scales each axis independently.

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

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

multiply_transpose( a, b ) multiply two matrices a and b<sup>T</sup> together.

round( a, sigfigs ) rounds every element of a mat44 to some number of decimal places.

row0( a ) selects the first row of a mat44.

row1( a ) selects the second row of a mat44.

row2( a ) selects the third row of a mat44.

row3( a ) selects the fourth row of a mat44.

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

subtract(a,b) subtracts one mat44 from another mat44.

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

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

zero() creates a zeroed mat44.

Types

@type mat44() ::
  {float(), float(), float(), float(), float(), float(), float(), float(),
   float(), float(), float(), float(), float(), float(), float(), float()}
@type vec3() :: {float(), float(), float()}
@type vec4() :: {float(), float(), float(), float()}

Functions

@spec add(mat44(), mat44()) :: mat44()

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.

@spec apply(mat44(), vec4()) :: vec4()

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.

@spec apply_left(vec4(), mat44()) :: vec4()

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.

Link to this function

apply_left_transpose(arg1, arg2)

View Source
@spec apply_left_transpose(vec4(), mat44()) :: vec4()

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**<sup>T</sup>.

This is the "full" application of a matrix, and uses all elements.

Link to this function

apply_transpose(arg1, arg2)

View Source
@spec apply_transpose(mat44(), vec4()) :: vec4()

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 A<sup>T</sup>v.

This is the "full" application of a matrix, and uses all elements.

@spec at(mat44(), non_neg_integer(), non_neg_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.

@spec column0(mat44()) :: vec4()

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.

@spec column1(mat44()) :: vec4()

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.

@spec column2(mat44()) :: vec4()

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.

@spec column3(mat44()) :: vec4()

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.

@spec diag(mat44()) :: vec4()

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.

@spec identity() :: mat44()

identity() creates an identity mat44.

This returns an identity mat44.

@spec inverse(mat44()) :: mat44()

inverse(a) calculates the inverse matrix

a is a mat44 to be inverted

Returs a mat44 representing a<sup>-1</sup>

Raises an error when you try to calculate inverse of a matrix whose determinant is zero

@spec 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.

@spec 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.

@spec 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.

@spec 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 ks.

Link to this function

make_scale(sx, sy, sz, sw)

View Source
@spec 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 vec3s via the transform methods, sw will have no effect.

Link to this function

make_translate(tx, ty, tz)

View Source
@spec 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 }.

@spec multiply(mat44(), mat44()) :: mat44()

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.

Link to this function

multiply_transpose(arg1, arg2)

View Source
@spec multiply_transpose(mat44(), mat44()) :: mat44()

multiply_transpose( a, b ) multiply two matrices a and b<sup>T</sup> together.

a is the mat44 multiplicand.

b is the mat44 multiplier.

This returns the mat44 product of the a and b<sup>T</sup>.

@spec round(mat44(), 0..15) :: mat44()

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.

@spec row0(mat44()) :: vec4()

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.

@spec row1(mat44()) :: vec4()

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.

@spec row2(mat44()) :: vec4()

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.

@spec row3(mat44()) :: vec4()

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.

@spec scale(mat44(), float()) :: mat44()

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.

@spec subtract(mat44(), mat44()) :: mat44()

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.

Link to this function

transform_point(arg1, arg2)

View Source
@spec transform_point(mat44(), vec3()) :: vec3()

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.

Link to this function

transform_vector(arg1, arg2)

View Source
@spec transform_vector(mat44(), vec3()) :: vec3()

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.

@spec zero() :: mat44()

zero() creates a zeroed mat44.

This returns a zeroed mat44.