0 | module Data.NumIdr.Transform.Rotation
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 | import Data.NumIdr.Transform.Orthonormal
17 | Rotation : Nat -> Type -> Type
18 | Rotation = Transform TRotation
23 | isRotation' : FieldCmp a => Matrix' n a -> Bool
24 | isRotation' mat = isOrthonormal' mat && det mat == 1
28 | fromMatrix : FieldCmp a => Matrix' n a -> Maybe (Rotation n a)
29 | fromMatrix mat = if isRotation' mat then Just (unsafeMkTrans $
matrixToH mat)
34 | isRotation : FieldCmp a => HMatrix' n a -> Bool
35 | isRotation {n} mat with (viewShape mat)
36 | _ | Shape [S n, S n] = isHMatrix mat && all (==0) (mat !!.. [EndBound last, One last])
37 | && isRotation' (getMatrix mat)
40 | fromHMatrix : FieldCmp a => HMatrix' n a -> Maybe (Rotation n a)
41 | fromHMatrix mat = if isRotation mat then Just (unsafeMkTrans mat)
46 | rotate2D : Num a => Double -> Rotation 2 Double
47 | rotate2D = unsafeMkTrans . rotate2DH
57 | rotate3DX : Double -> Rotation 3 Double
58 | rotate3DX = unsafeMkTrans . rotate3DXH
62 | rotate3DY : Double -> Rotation 3 Double
63 | rotate3DY = unsafeMkTrans . rotate3DYH
67 | rotate3DZ : Double -> Rotation 3 Double
68 | rotate3DZ = unsafeMkTrans . rotate3DZH
76 | faceTowards : (dir, up : Vector 3 Double) -> Rotation 3 Double
77 | faceTowards dir up = let z = normalize dir
78 | x = normalize (up `cross` z)
79 | y = normalize (z `cross` x)
80 | in unsafeMkTrans $
matrixToH $
hstack [x,y,z]