A module with various simple matrix operations to augment the vector stuff.

The Num instances implement proper matrix multiplication as you would expect (not element-wise multiplication).

- type Matrix22' a = SquareMatrix Pair a
- type Matrix33' a = SquareMatrix Triple a
- type Matrix44' a = SquareMatrix Quad a
- newtype SquareMatrix c a = SquareMatrix (c (c a))
- class Matrix m where
- matrixComponents :: m a -> [[a]]
- fromMatrixComponents :: Num a => [[a]] -> m a
- transpose :: m a -> m a

- identityMatrix :: (Num a, Matrix m) => m a
- multMatrix :: (Foldable c, Applicative c, Num a, IsomorphicVectors c p, IsomorphicVectors p c) => SquareMatrix c a -> p a -> p a
- multMatrixGen :: (Coord p, Matrix m, Num a) => m a -> p a -> p a
- translate2D :: (Num a, IsomorphicVectors p Pair) => p a -> Matrix33' a
- translate3D :: (Num a, IsomorphicVectors p Triple) => p a -> Matrix44' a
- rotateXaxis :: (Floating a, Matrix m) => a -> m a
- rotateYaxis :: (Floating a, Matrix m) => a -> m a
- rotateZaxis :: (Floating a, Matrix m) => a -> m a

# Documentation

type Matrix22' a = SquareMatrix Pair aSource

type Matrix33' a = SquareMatrix Triple aSource

type Matrix44' a = SquareMatrix Quad aSource

newtype SquareMatrix c a Source

A square matrix. You will almost certainly want to use `Matrix22'`

and similar
instead of this directly. It does have a variety of useful instances though,
especially `Functor`

, `Num`

and `Matrix`

.

Its definition is based on a square matrix being, for example, a pair of pairs or a triple of triples.

SquareMatrix (c (c a)) |

Functor c => Functor (SquareMatrix c) | |

Applicative c => Applicative (SquareMatrix c) | |

Foldable c => Foldable (SquareMatrix c) | |

Traversable c => Traversable (SquareMatrix c) | |

(Applicative c, Foldable c, Traversable c, Functor c) => Matrix (SquareMatrix c) | |

(Foldable c, Applicative c, Eq a) => Eq (SquareMatrix c a) | |

(Num a, Traversable c, Foldable c, Functor c, Applicative c) => Num (SquareMatrix c a) | |

(Read a, Num a, Applicative c, Traversable c) => Read (SquareMatrix c a) | |

(Applicative c, Foldable c, Traversable c, Functor c, Show a) => Show (SquareMatrix c a) |

The class that all matrices belong to.

matrixComponents :: m a -> [[a]]Source

Gives back the matrix as a list of rows.

fromMatrixComponents :: Num a => [[a]] -> m aSource

Creates a matrix from a list of rows. Any missing entries are filled
in with the relevant entries from the identity matrix, hence the identity
matrix is equivalent to `fromMatrixComponents []`

.

Transposes a matrix

(Applicative c, Foldable c, Traversable c, Functor c) => Matrix (SquareMatrix c) |

identityMatrix :: (Num a, Matrix m) => m aSource

The identity matrix.

multMatrix :: (Foldable c, Applicative c, Num a, IsomorphicVectors c p, IsomorphicVectors p c) => SquareMatrix c a -> p a -> p aSource

Matrix multiplication where the size of the vector matches the dimensions of the matrix. The complicated type just means that this function will work for any combination of matrix types and vectors where the width of the square matrix is the same as the number of dimensions in the vector.

multMatrixGen :: (Coord p, Matrix m, Num a) => m a -> p a -> p aSource

Matrix multiplication. There is no requirement that the size of the matrix matches the size of the vector:

- If the vector is too small for the matrix (e.g. multiplying a 4x4 matrix by a 3x3 vector), 1 will be used for the missing vector entries.
- If the matrix is too small for the vector (e.g. multiplying a 2x2 matrix by a 3x3 vector), the other components of the vector will be left untouched.

This allows you to do tricks such as multiplying a 4x4 matrix by a 3D vector, and doing translation (a standard 3D graphics trick).

translate2D :: (Num a, IsomorphicVectors p Pair) => p a -> Matrix33' aSource

Given a 2D relative vector, produces a matrix that will translate by that much (when you multiply a 2D point with it using multMatrixGen)

translate3D :: (Num a, IsomorphicVectors p Triple) => p a -> Matrix44' aSource

Given a 3D relative vector, produces a matrix that will translate by that much (when you multiply a 3D point with it using multMatrixGen)

rotateXaxis :: (Floating a, Matrix m) => a -> m aSource

Given an angle in *radians*, produces a matrix that rotates anti-clockwise
by that angle around the X axis. Note that this can be used to produce a 2x2,
3x3 or 4x4 matrix, but if you produce a 2x2 matrix, odd things will happen!

rotateYaxis :: (Floating a, Matrix m) => a -> m aSource

Given an angle in *radians*, produces a matrix that rotates anti-clockwise
by that angle around the Y axis. Note that this can be used to produce a 2x2,
3x3 or 4x4 matrix, but if you produce a 2x2 matrix, odd things will happen!

rotateZaxis :: (Floating a, Matrix m) => a -> m aSource

Given an angle in *radians*, produces a matrix that rotates anti-clockwise
by that angle around the Z axis. Note that this can be used to produce a 2x2
(in which case it is a rotation around the origin), 3x3 or 4x4 matrix.