Add radius

This commit is contained in:
Dimitri Lozeve 2017-07-19 15:34:44 +02:00
parent 01d5e8640f
commit 0576d02811

View file

@ -2,6 +2,7 @@ module Lib (
gravity, gravity,
Body, Body,
bodyName, bodyName,
bodyRadius,
bodyMass, bodyMass,
bodyPosition, bodyPosition,
bodySpeed, bodySpeed,
@ -34,6 +35,7 @@ gravity = 6.67408e-11
-- Body -- Body
data Body = Body { data Body = Body {
bodyName :: String, bodyName :: String,
bodyRadius :: Double, -- [m]
bodyMass :: Double, -- [kg] bodyMass :: Double, -- [kg]
bodyPosition :: Point V3 Double, -- [m] bodyPosition :: Point V3 Double, -- [m]
bodySpeed :: V3 Double -- [m/s] bodySpeed :: V3 Double -- [m/s]
@ -71,9 +73,9 @@ acceleration body = foldr f (fromInteger 0)
-- Update speed and position with using a timestep dt -- Update speed and position with using a timestep dt
update :: Double -> Body -> [Body] -> Body update :: Double -> Body -> [Body] -> Body
update dt (Body name m pos speed) neighbours = update dt (Body name r m pos speed) neighbours =
Body name m newpos newspeed Body name r m newpos newspeed
where accel = acceleration (Body name m pos speed) neighbours where accel = acceleration (Body name r m pos speed) neighbours
newspeed = speed + dt *^ accel newspeed = speed + dt *^ accel
newpos = pos + dt *^ P newspeed newpos = pos + dt *^ P newspeed
@ -92,17 +94,17 @@ updateAll dt bodies = aux [] [] bodies
-- EXAMPLES -- EXAMPLES
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
b1 = Body "b1" 42e12 (P $ V3 0 0 0) (V3 0 0 0) b1 = Body "b1" 1 42e12 (P $ V3 0 0 0) (V3 0 0 0)
b2 = Body "b2" 11e12 (P $ V3 1 2 3) (V3 0 3e3 0) b2 = Body "b2" 1 11e12 (P $ V3 1 2 3) (V3 0 3e3 0)
b3 = Body "b3" 5e12 (P $ V3 5 2 1) (V3 3e3 1e3 0) b3 = Body "b3" 1 5e12 (P $ V3 5 2 1) (V3 3e3 1e3 0)
-- Astronomical Unit [m] -- Astronomical Unit [m]
au :: Double au :: Double
au = 149597870700 au = 149597870700
sun = Body "Sun" 1.98855e30 (P $ V3 0 0 0) (V3 0 0 0) sun = Body "Sun" 695700000 1.98855e30 (P $ V3 0 0 0) (V3 0 0 0)
earth = Body "Earth" 8.97237e24 (P $ V3 au 0 0) (V3 0 29.78e3 0) earth = Body "Earth" 6.371e6 8.97237e24 (P $ V3 au 0 0) (V3 0 29.78e3 0)
moon = Body "Moon" 7.342e22 (P $ V3 (au+384399e3) 0 0) (V3 0 (29.78e3+1022) 0) moon = Body "Moon" 1.7371e6 7.342e22 (P $ V3 (au+384399e3) 0 0) (V3 0 (29.78e3+1022) 0)
mercury = Body "Mercury" 3.3011e23 (P $ V3 57909050000 0 0) (V3 0 47362 0) mercury = Body "Mercury" 2.4397e6 3.3011e23 (P $ V3 57909050000 0 0) (V3 0 47362 0)
venus = Body "Venus" 4.8675e24 (P $ V3 108208000000 0 0) (V3 0 35.02e3 0) venus = Body "Venus" 6.0518e6 4.8675e24 (P $ V3 108208000000 0 0) (V3 0 35.02e3 0)
mars = Body "Mars" 6.4171e23 (P $ V3 227.9392e9 0 0) (V3 0 24.077e3 0) mars = Body "Mars" 3.3895e6 6.4171e23 (P $ V3 227.9392e9 0 0) (V3 0 24.077e3 0)