matrix/mat3f

3x3 matrices of floats

Types

Mat3f is a 3x3 column-major matrix of Floats.

pub type Mat3f =
  vec3.Vec3(vec3.Vec3(Float))

Values

pub fn absolute_value(
  mat: vec3.Vec3(vec3.Vec3(Float)),
) -> vec3.Vec3(vec3.Vec3(Float))

Takes the absolute value of each element in the Mat3f.

pub fn add(
  a: vec3.Vec3(vec3.Vec3(Float)),
  b: vec3.Vec3(vec3.Vec3(Float)),
) -> vec3.Vec3(vec3.Vec3(Float))

Adds two Mat3f together.

pub fn determinant(mat: vec3.Vec3(vec3.Vec3(Float))) -> Float

Returns the determinant for the Mat3f.

pub fn divide(
  a: vec3.Vec3(vec3.Vec3(Float)),
  b: vec3.Vec3(vec3.Vec3(Float)),
) -> Result(vec3.Vec3(vec3.Vec3(Float)), Nil)

Divides one Mat3f by another. Equivalent to multiplying the inverse of the second matrix.

pub fn from_angle(angle: Float) -> vec3.Vec3(vec3.Vec3(Float))

Creates an affine transformation matrix from the given 2D rotation angle (in radians).

The resulting matrix can be used to transform 2D points and vectors.

pub fn from_axis_angle(
  axis: vec3.Vec3(Float),
  angle: Float,
) -> vec3.Vec3(vec3.Vec3(Float))

Creates a 3D rotation matrix from a normalized rotation axis and angle (in radians).

pub fn from_cols(
  a: vec3.Vec3(Float),
  b: vec3.Vec3(Float),
  c: vec3.Vec3(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Constructs a Mat3f from its three columns.

| ax  bx  cx |
| ay  by  cy |
| az  bz  cz |
pub fn from_diagonal(
  diag: vec3.Vec3(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Constructs a Mat3f with the given diagonal and all other entries set to 0.

| x    0.0  0.0 |
| 0.0  y    0.0 |
| 0.0  0.0  z   |
pub fn from_quaternion(
  q: vec4.Vec4(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Constructs a 3D rotation matrix from the given quaternion, represented as a vec4.Vec4(Float).

pub fn from_rotation_x(
  angle: Float,
) -> vec3.Vec3(vec3.Vec3(Float))

Creates a 3D rotation matrix from angle in radians around the x axis.

pub fn from_rotation_y(
  angle: Float,
) -> vec3.Vec3(vec3.Vec3(Float))

Creates a 3D rotation matrix from angle in radians around the y axis.

pub fn from_rotation_z(
  angle: Float,
) -> vec3.Vec3(vec3.Vec3(Float))

Creates a 3D rotation matrix from angle in radians around the z axis.

pub fn from_scale(
  scale: vec2.Vec2(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Creates an affine transformation matrix from teh given non-uniform 2D scale.

The resulting matrix can be used to transform 2D points and vectors.

pub fn from_scale_angle_translation(
  scale: vec2.Vec2(Float),
  angle: Float,
  translation: vec2.Vec2(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Creates an affine transformation matrix from the given 2D scale, rotation angle (in radians), and translation.

The resulting matrix can be used to transform 2D points and vectors.

pub fn from_translation(
  translation: vec2.Vec2(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Creates an affine transformation matrix from the given 2D translation.

The resulting matrix can be used to transform 2D points and vectors.

pub const identity: vec3.Vec3(vec3.Vec3(Float))

A Mat3f representing the identity, i.e. 1.0 is on the diagonal.

pub fn inverse(
  mat: vec3.Vec3(vec3.Vec3(Float)),
) -> Result(vec3.Vec3(vec3.Vec3(Float)), Nil)

Inverts the Mat3f, returning an error if the determinant is zero.

pub fn look_at_lh(
  eye: vec3.Vec3(Float),
  center: vec3.Vec3(Float),
  up: vec3.Vec3(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Creates a left-handed view matrix using a camera position, a focal point and an up direction.

For a view coordinate system with +X=right, +Y=up and +Z=forward.

pub fn look_at_rh(
  eye: vec3.Vec3(Float),
  center: vec3.Vec3(Float),
  up: vec3.Vec3(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Creates a right-handed view matrix using a camera position, a focal point and an up direction.

For a view coordinate system with +X=right, +Y=up and +Z=back.

pub fn look_to_lh(
  dir: vec3.Vec3(Float),
  up: vec3.Vec3(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Creates a left-handed view matrix using a facing direction and an up direction.

For a view coordinate system with +X=right, +Y=up, and +Z=forward.

pub fn look_to_rh(
  dir: vec3.Vec3(Float),
  up: vec3.Vec3(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Creates a right-handed view matrix using a facing direction and an up direction.

For a view coordinate system with +X=right, +Y=up and +Z=back.

pub fn mul_transpose_vec3(
  mat: vec3.Vec3(vec3.Vec3(Float)),
  rhs: vec3.Vec3(Float),
) -> vec3.Vec3(Float)

Transforms a Vec3f by the transpose of this Mat3f.

pub fn mul_vec3(
  mat: vec3.Vec3(vec3.Vec3(Float)),
  rhs: vec3.Vec3(Float),
) -> vec3.Vec3(Float)

Transforms a Vec3f by this Mat3f.

pub fn multiply(
  a: vec3.Vec3(vec3.Vec3(Float)),
  b: vec3.Vec3(vec3.Vec3(Float)),
) -> vec3.Vec3(vec3.Vec3(Float))

Multiplies two Mat3f together.

pub fn negate(
  mat: vec3.Vec3(vec3.Vec3(Float)),
) -> vec3.Vec3(vec3.Vec3(Float))

Negates all elements of the Mat3f

pub fn new(
  a: Float,
  b: Float,
  c: Float,
  d: Float,
  e: Float,
  f: Float,
  g: Float,
  h: Float,
  i: Float,
) -> vec3.Vec3(vec3.Vec3(Float))

Constructs a Mat3f from its components:

| a  d  g |
| b  e  h |
| c  f  i |
pub fn product(
  mats: List(vec3.Vec3(vec3.Vec3(Float))),
) -> vec3.Vec3(vec3.Vec3(Float))

Multiplies a list of Mat3fs.

pub fn reciprocal(
  mat: vec3.Vec3(vec3.Vec3(Float)),
) -> Result(vec3.Vec3(vec3.Vec3(Float)), Nil)

Returns a matrix containing the reciprocal of each element of the Mat3f.

If any of the elements is zero, an error is returned.

pub fn scale(
  mat: vec3.Vec3(vec3.Vec3(Float)),
  scale: Float,
) -> vec3.Vec3(vec3.Vec3(Float))

Scales the Mat3f by a Float factor.

pub fn scale_diagonal(
  mat: vec3.Vec3(vec3.Vec3(Float)),
  scale: vec3.Vec3(Float),
) -> vec3.Vec3(vec3.Vec3(Float))

Scales the Mat3f by a Vec3f.

This is faster than creating a diagonal scaling matrix and then multiplying that.

pub fn subtract(
  a: vec3.Vec3(vec3.Vec3(Float)),
  b: vec3.Vec3(vec3.Vec3(Float)),
) -> vec3.Vec3(vec3.Vec3(Float))

Subtracts one Mat3f from the other.

pub fn sum(
  mats: List(vec3.Vec3(vec3.Vec3(Float))),
) -> vec3.Vec3(vec3.Vec3(Float))

Sums a list of Mat3fs.

pub fn transform_point2(
  mat: vec3.Vec3(vec3.Vec3(Float)),
  rhs: vec2.Vec2(Float),
) -> vec2.Vec2(Float)

Transforms the given 2D vector as a point.

This is the equivalent of multiplying rhs as a 3D vector where z is 1.

This function assumes that mat contains a valid affine transform.

pub fn transform_vector2(
  mat: vec3.Vec3(vec3.Vec3(Float)),
  rhs: vec2.Vec2(Float),
) -> vec2.Vec2(Float)

Rotates the given 2D vector.

This is the equivalent of multiplying rhs as a 3D vector where z is 0.

pub fn transpose(
  mat: vec3.Vec3(vec3.Vec3(Float)),
) -> vec3.Vec3(vec3.Vec3(Float))

Transposes the Mat3f along the diagonal.

pub const zero: vec3.Vec3(vec3.Vec3(Float))

A Mat3f with all elements set to 0.0

Search Document