0 | module Data.NumIdr.Transform.Orthonormal
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
17 | Orthonormal : Nat -> Type -> Type
18 | Orthonormal = Transform TOrthonormal
23 | isOrthonormal' : Eq a => Num a => Matrix' n a -> Bool
24 | isOrthonormal' {n} mat with (viewShape mat)
25 | _ | Shape [n,n] = identity == fromFunction [n,n] (\[i,j] => getColumn i mat `dot` getColumn j mat)
29 | fromMatrix : Eq a => Num a => Matrix' n a -> Maybe (Orthonormal n a)
30 | fromMatrix mat = if isOrthonormal' mat then Just (unsafeMkTrans (matrixToH mat))
36 | isOrthonormal : Eq a => Num a => HMatrix' n a -> Bool
37 | isOrthonormal {n} mat with (viewShape mat)
38 | _ | Shape [S n, S n] = isHMatrix mat && all (==0) (mat !!.. [EndBound last, One last])
39 | && isOrthonormal' (getMatrix mat)
42 | fromHMatrix : Eq a => Num a => HMatrix' n a -> Maybe (Orthonormal n a)
43 | fromHMatrix mat = if isOrthonormal mat then Just (unsafeMkTrans mat) else Nothing
53 | reflect : {n : _} -> Neg a => Fin n -> Orthonormal n a
54 | reflect = unsafeMkTrans . reflectH
58 | reflectX : {n : _} -> Neg a => Orthonormal (1 + n) a
59 | reflectX = reflect 0
63 | reflectY : {n : _} -> Neg a => Orthonormal (2 + n) a
64 | reflectY = reflect 1
68 | reflectZ : {n : _} -> Neg a => Orthonormal (3 + n) a
69 | reflectZ = reflect 2
75 | reflectNormal : (Neg a, Fractional a) => Vector n a -> Orthonormal n a
76 | reflectNormal {n} v with (viewShape v)
77 | _ | Shape [n] = unsafeMkTrans $
matrixToH $
identity - (2 / normSq v) *. outer v v