{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE Safe #-}
module Physics.Learn.SimpleVec
( Vec
, R
, xComp
, yComp
, zComp
, vec
, (^+^)
, (^-^)
, (*^)
, (^*)
, (^/)
, (<.>)
, (><)
, magnitude
, zeroV
, negateV
, sumV
, iHat
, jHat
, kHat
)
where
import Physics.Learn.CommonVec
( Vec(..)
, vec
, iHat
, jHat
, kHat
, (><)
)
infixl 6 ^+^
infixl 6 ^-^
infixl 7 *^
infixl 7 ^*
infixl 7 ^/
infixl 7 <.>
type R = Double
zeroV :: Vec
zeroV = vec 0 0 0
negateV :: Vec -> Vec
negateV (Vec ax ay az) = Vec (-ax) (-ay) (-az)
sumV :: [Vec] -> Vec
sumV = foldr (^+^) zeroV
(^+^) :: Vec -> Vec -> Vec
Vec ax ay az ^+^ Vec bx by bz
= Vec (ax+bx) (ay+by) (az+bz)
(^-^) :: Vec -> Vec -> Vec
Vec ax ay az ^-^ Vec bx by bz = Vec (ax-bx) (ay-by) (az-bz)
(*^) :: R -> Vec -> Vec
c *^ Vec ax ay az = Vec (c*ax) (c*ay) (c*az)
(^*) :: Vec -> R -> Vec
Vec ax ay az ^* c = Vec (c*ax) (c*ay) (c*az)
(^/) :: Vec -> R -> Vec
Vec ax ay az ^/ c = Vec (ax/c) (ay/c) (az/c)
(<.>) :: Vec -> Vec -> R
Vec ax ay az <.> Vec bx by bz = ax*bx + ay*by + az*bz
magnitude :: Vec -> R
magnitude v = sqrt(v <.> v)