Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | Edward Kmett <[email protected]> |
Safe Haskell | None |
Linear.Matrix
Description
Simple matrix operation for low-dimensional primitives.
- (!*!) :: (Functor m, Foldable r, Apply r, Distributive n, Num a) => m (r a) -> r (n a) -> m (n a)
- (!+!) :: (Additive m, Additive n, Num a) => m (n a) -> m (n a) -> m (n a)
- (!-!) :: (Additive m, Additive n, Num a) => m (n a) -> m (n a) -> m (n a)
- (!*) :: (Functor m, Metric r, Num a) => m (r a) -> r a -> m a
- (*!) :: (Metric r, Distributive n, Num a) => r a -> r (n a) -> n a
- (!!*) :: (Functor m, Functor r, Num a) => m (r a) -> a -> m (r a)
- (*!!) :: (Functor m, Functor r, Num a) => a -> m (r a) -> m (r a)
- adjoint :: (Functor m, Distributive n, Conjugate a) => m (n a) -> n (m a)
- type M22 a = V2 (V2 a)
- type M33 a = V3 (V3 a)
- type M44 a = V4 (V4 a)
- type M43 a = V4 (V3 a)
- m33_to_m44 :: Num a => M33 a -> M44 a
- m43_to_m44 :: Num a => M43 a -> M44 a
- det22 :: Num a => M22 a -> a
- det33 :: Num a => M33 a -> a
- inv22 :: (Epsilon a, Floating a) => M22 a -> Maybe (M22 a)
- inv33 :: (Epsilon a, Floating a) => M33 a -> Maybe (M33 a)
- eye3 :: Num a => M33 a
- eye4 :: Num a => M44 a
- trace :: (Monad f, Foldable f, Num a) => f (f a) -> a
- translation :: (R3 t, R4 v, Functor f, Functor t) => (V3 a -> f (V3 a)) -> t (v a) -> f (t a)
- fromQuaternion :: Num a => Quaternion a -> M33 a
- mkTransformation :: Num a => Quaternion a -> V3 a -> M44 a
- mkTransformationMat :: Num a => M33 a -> V3 a -> M44 a
Documentation
(!*!) :: (Functor m, Foldable r, Apply r, Distributive n, Num a) => m (r a) -> r (n a) -> m (n a)Source
Matrix product. This can compute mixed dense-dense, sparse-dense and sparse-sparse matrix products.
>>>
V2 (V3 1 2 3) (V3 4 5 6) !*! V3 (V2 1 2) (V2 3 4) (V2 4 5)
V2 (V2 19 25) (V2 43 58)
>>>
V2 (fromList [(1,2)]) (fromList [(2,3)]) !*! fromList [(1,V3 0 0 1), (2, V3 0 0 5)]
V2 (V3 0 0 2) (V3 0 0 15)
(!+!) :: (Additive m, Additive n, Num a) => m (n a) -> m (n a) -> m (n a)Source
Entry-wise matrix addition.
>>>
V2 (V3 1 2 3) (V3 4 5 6) !+! V2 (V3 7 8 9) (V3 1 2 3)
V2 (V3 8 10 12) (V3 5 7 9)
(!-!) :: (Additive m, Additive n, Num a) => m (n a) -> m (n a) -> m (n a)Source
Entry-wise matrix subtraction.
>>>
V2 (V3 1 2 3) (V3 4 5 6) !-! V2 (V3 7 8 9) (V3 1 2 3)
V2 (V3 (-6) (-6) (-6)) (V3 3 3 3)
(!*) :: (Functor m, Metric r, Num a) => m (r a) -> r a -> m aSource
Matrix * column vector
>>>
V2 (V3 1 2 3) (V3 4 5 6) !* V3 7 8 9
V2 50 122
(*!) :: (Metric r, Distributive n, Num a) => r a -> r (n a) -> n aSource
Row vector * matrix
>>>
V2 1 2 *! V2 (V3 3 4 5) (V3 6 7 8)
V3 15 18 21
(!!*) :: (Functor m, Functor r, Num a) => m (r a) -> a -> m (r a)Source
Matrix-scalar product
>>>
V2 (V2 1 2) (V2 3 4) !!* 5
V2 (V2 5 10) (V2 15 20)
(*!!) :: (Functor m, Functor r, Num a) => a -> m (r a) -> m (r a)Source
Scalar-matrix product
>>>
5 *!! V2 (V2 1 2) (V2 3 4)
V2 (V2 5 10) (V2 15 20)
adjoint :: (Functor m, Distributive n, Conjugate a) => m (n a) -> n (m a)Source
Hermitian conjugate or conjugate transpose
>>>
adjoint (V2 (V2 (1 :+ 2) (3 :+ 4)) (V2 (5 :+ 6) (7 :+ 8)))
V2 (V2 (1.0 :+ (-2.0)) (5.0 :+ (-6.0))) (V2 (3.0 :+ (-4.0)) (7.0 :+ (-8.0)))
m33_to_m44 :: Num a => M33 a -> M44 aSource
Convert a 3x3 matrix to a 4x4 matrix extending it with 0's in the new row and column.
m43_to_m44 :: Num a => M43 a -> M44 aSource
Convert from a 4x3 matrix to a 4x4 matrix, extending it with the [ 0 0 0 1 ]
column vector
det22 :: Num a => M22 a -> aSource
2x2 matrix determinant.
>>>
det22 (V2 (V2 a b) (V2 c d))
a * d - b * c
det33 :: Num a => M33 a -> aSource
3x3 matrix determinant.
>>>
det33 (V3 (V3 a b c) (V3 d e f) (V3 g h i))
a * (e * i - f * h) - d * (b * i - c * h) + g * (b * f - c * e)
inv22 :: (Epsilon a, Floating a) => M22 a -> Maybe (M22 a)Source
2x2 matrix inverse.
>>>
inv22 $ V2 (V2 1 2) (V2 3 4)
Just (V2 (V2 (-2.0) 1.0) (V2 1.5 (-0.5)))
inv33 :: (Epsilon a, Floating a) => M33 a -> Maybe (M33 a)Source
3x3 matrix inverse.
>>>
inv33 $ V3 (V3 1 2 4) (V3 4 2 2) (V3 1 1 1)
Just (V3 (V3 0.0 0.5 (-1.0)) (V3 (-0.5) (-0.75) 3.5) (V3 0.5 0.25 (-1.5)))
4x4 identity matrix.
>>>
eye4
V4 (V4 1 0 0 0) (V4 0 1 0 0) (V4 0 0 1 0) (V4 0 0 0 1)
trace :: (Monad f, Foldable f, Num a) => f (f a) -> aSource
Compute the trace of a matrix
>>>
trace (V2 (V2 a b) (V2 c d))
a + d
translation :: (R3 t, R4 v, Functor f, Functor t) => (V3 a -> f (V3 a)) -> t (v a) -> f (t a)Source
Extract the translation vector (first three entries of the last column) from a 3x4 or 4x4 matrix
fromQuaternion :: Num a => Quaternion a -> M33 aSource
Build a rotation matrix from a unit Quaternion
.
mkTransformation :: Num a => Quaternion a -> V3 a -> M44 aSource
Build a transformation matrix from a rotation expressed as a
Quaternion
and a translation vector.