module Quaternion
    ( rotateToZ
    , vToQuat
    , module Linear.Quaternion
    ) where
import Geometry.Data
import Geometry.Vector3D
import qualified Linear.Quaternion as Q
import Linear.Quaternion

-- apply a rotation as if the z axis moves to the new point.
-- i think this may instead do as if the new point moves to be on z axis
rotateToZ :: Point3 -> Point3 -> Point3
rotateToZ z1
    | cprod == V3 0 0 0 = id
    | otherwise = Q.rotate $ Q.axisAngle cprod (angleVV3 z1 (V3 0 0 1))
  where
    cprod = crossProd z1 (V3 0 0 1)

vToQuat :: Point3 -> Point3 -> Q.Quaternion Float
vToQuat a b 
    | cprod == V3 0 0 0 = Q.axisAngle (V3 0 0 1) 0
    | otherwise = Q.axisAngle cprod (angleVV3 a b)
  where
    cprod = crossProd a b
