Module

Linear.Matrix

Package
purescript-linear
Repository
afcondon/purescript-linear

Matrix types and operations.

Matrices are represented as vectors of row vectors, following Haskell's linear. This module provides type aliases and operations for common matrix sizes.

#M22 Source

type M22 a = V2 (V2 a)

2x2 matrix (2 rows, 2 columns)

#M23 Source

type M23 a = V2 (V3 a)

2x3 matrix

#M24 Source

type M24 a = V2 (V4 a)

2x4 matrix

#M32 Source

type M32 a = V3 (V2 a)

3x2 matrix

#M33 Source

type M33 a = V3 (V3 a)

3x3 matrix

#M34 Source

type M34 a = V3 (V4 a)

3x4 matrix

#M42 Source

type M42 a = V4 (V2 a)

4x2 matrix

#M43 Source

type M43 a = V4 (V3 a)

4x3 matrix

#M44 Source

type M44 a = V4 (V4 a)

4x4 matrix (commonly used for 3D transformations)

#identity22 Source

identity22 :: forall a. Semiring a => M22 a

2x2 identity matrix.

#identity33 Source

identity33 :: forall a. Semiring a => M33 a

3x3 identity matrix.

#identity44 Source

identity44 :: forall a. Semiring a => M44 a

4x4 identity matrix.

#fromQuaternion Source

fromQuaternion :: Quaternion Number -> M33 Number

Convert a unit quaternion to a 3x3 rotation matrix.

fromQuaternion (Quaternion 1.0 (V3 0.0 0.0 0.0)) = identity33

#mkTransformation Source

mkTransformation :: Quaternion Number -> V3 Number -> M44 Number

Build a 4x4 transformation matrix from a quaternion rotation and translation.

The resulting matrix applies rotation first, then translation.

mkTransformation identity (V3 1.0 2.0 3.0) -- pure translation
mkTransformation rotation (V3 0.0 0.0 0.0) -- pure rotation

#mkTransformationMat Source

mkTransformationMat :: M33 Number -> V3 Number -> M44 Number

Build a 4x4 transformation matrix from a 3x3 rotation matrix and translation.

#mulMV Source

mulMV :: forall a. Semiring a => M33 a -> V3 a -> V3 a

Multiply a matrix by a column vector (M * v).

mulMV identity33 v = v

#mulVM Source

mulVM :: forall a. Semiring a => V3 a -> M33 a -> V3 a

Multiply a row vector by a matrix (v * M).

#mulMM Source

mulMM :: forall a. Semiring a => M33 a -> M33 a -> M33 a

Matrix multiplication.

mulMM identity33 m = m
mulMM m identity33 = m

#transpose22 Source

transpose22 :: forall a. M22 a -> M22 a

Transpose a 2x2 matrix.

#transpose33 Source

transpose33 :: forall a. M33 a -> M33 a

Transpose a 3x3 matrix.

#transpose44 Source

transpose44 :: forall a. M44 a -> M44 a

Transpose a 4x4 matrix.

#(!*) Source

Operator alias for Linear.Matrix.mulMV (left-associative / precedence 7)

#(*!) Source

Operator alias for Linear.Matrix.mulVM (left-associative / precedence 7)

#(!*!) Source

Operator alias for Linear.Matrix.mulMM (left-associative / precedence 7)

#det22 Source

det22 :: forall a. Ring a => M22 a -> a

Determinant of a 2x2 matrix.

#det33 Source

det33 :: forall a. Ring a => M33 a -> a

Determinant of a 3x3 matrix.

#det44 Source

det44 :: forall a. Ring a => M44 a -> a

Determinant of a 4x4 matrix.

#inv22 Source

inv22 :: M22 Number -> Maybe (M22 Number)

Inverse of a 2x2 matrix, if it exists.

#inv33 Source

inv33 :: M33 Number -> Maybe (M33 Number)

Inverse of a 3x3 matrix, if it exists.

#inv44 Source

inv44 :: M44 Number -> Maybe (M44 Number)

Inverse of a 4x4 matrix, if it exists.

#diagonal33 Source

diagonal33 :: forall a. M33 a -> V3 a

Extract the diagonal of a 3x3 matrix.

#trace33 Source

trace33 :: forall a. Semiring a => M33 a -> a

Compute the trace (sum of diagonal) of a 3x3 matrix.