{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
module AstroData
(
OrbitBody(..)
, obPos
, obVel
, updateSvecs
, formatDoubleOB
) where
import PhysicsVectors
import Text.Printf(printf)
import GHC.Generics (Generic)
import Control.DeepSeq(NFData)
data OrbitBody f = OrbitBody { bid :: String, bGM :: f, brv :: Vec2 f, epoch :: f}
deriving (Eq, Show, Generic, NFData)
obPos :: Floating f => OrbitBody f -> Vec3 f
obPos = r . brv
obVel :: Floating f => OrbitBody f -> Vec3 f
obVel = v . brv
updateSvecs :: Floating f => OrbitBody f -> f -> Vec2 f -> OrbitBody f
updateSvecs body dt rvn = OrbitBody (bid body) (bGM body) rvn (epoch body + dt)
formatDoubleOB :: OrbitBody Double -> String
formatDoubleOB (OrbitBody bid' _ (Vec2 r' v') t) = printf "%v, %v, %v, %v" bid' t (formatVec r') (formatVec v')
where
formatVec :: Vec3 Double -> String
formatVec (Vec3 a b c) = printf "%v, %v, %v" a b c