0 | module Data.NumIdr.Transform.Linear
 1 |
 2 | import Data.Vect
 3 | import Data.NumIdr.Interfaces
 4 | import Data.NumIdr.Array
 5 | import Data.NumIdr.Vector
 6 | import Data.NumIdr.Matrix
 7 | import Data.NumIdr.Homogeneous
 8 | import Data.NumIdr.Transform.Point
 9 | import Data.NumIdr.Transform.Transform
10 |
11 | %default total
12 |
13 |
14 | ||| A linear transform can contain any invertible linear map.
15 | public export
16 | Linear : Nat -> Type -> Type
17 | Linear = Transform TLinear
18 |
19 |
20 | ||| Determine if a homogeneous matrix represents a linear transform.
21 | export
22 | isLinear : FieldCmp a => HMatrix' n a -> Bool
23 | isLinear mat = isHMatrix mat && invertible (getMatrix mat)
24 |                     && all (==0) (getTranslationVector mat)
25 |
26 | ||| Try to construct a linear transform from a homogeneous matrix.
27 | export
28 | fromHMatrix : FieldCmp a => HMatrix' n a -> Maybe (Linear n a)
29 | fromHMatrix mat = if isLinear mat then Just (unsafeMkTrans mat) else Nothing
30 |
31 | ||| Try to construct a linear transform from a matrix.
32 | ||| This will fail if the matrix is not invertible.
33 | export
34 | fromMatrix : FieldCmp a => Matrix' n a -> Maybe (Linear n a)
35 | fromMatrix mat = if invertible mat then Just (unsafeMkTrans (matrixToH mat))
36 |                                    else Nothing
37 |