From 0576d028115379350379582922ba2f81bcd1f4ef Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Wed, 19 Jul 2017 15:34:44 +0200 Subject: [PATCH] Add radius --- src/Lib.hs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Lib.hs b/src/Lib.hs index 2c8c0d6..d851fb6 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -2,6 +2,7 @@ module Lib ( gravity, Body, bodyName, + bodyRadius, bodyMass, bodyPosition, bodySpeed, @@ -34,6 +35,7 @@ gravity = 6.67408e-11 -- Body data Body = Body { bodyName :: String, + bodyRadius :: Double, -- [m] bodyMass :: Double, -- [kg] bodyPosition :: Point V3 Double, -- [m] 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 :: Double -> Body -> [Body] -> Body -update dt (Body name m pos speed) neighbours = - Body name m newpos newspeed - where accel = acceleration (Body name m pos speed) neighbours +update dt (Body name r m pos speed) neighbours = + Body name r m newpos newspeed + where accel = acceleration (Body name r m pos speed) neighbours newspeed = speed + dt *^ accel newpos = pos + dt *^ P newspeed @@ -92,17 +94,17 @@ updateAll dt bodies = aux [] [] bodies -- EXAMPLES -------------------------------------------------------------------------------- -b1 = Body "b1" 42e12 (P $ V3 0 0 0) (V3 0 0 0) -b2 = Body "b2" 11e12 (P $ V3 1 2 3) (V3 0 3e3 0) -b3 = Body "b3" 5e12 (P $ V3 5 2 1) (V3 3e3 1e3 0) +b1 = Body "b1" 1 42e12 (P $ V3 0 0 0) (V3 0 0 0) +b2 = Body "b2" 1 11e12 (P $ V3 1 2 3) (V3 0 3e3 0) +b3 = Body "b3" 1 5e12 (P $ V3 5 2 1) (V3 3e3 1e3 0) -- Astronomical Unit [m] au :: Double au = 149597870700 -sun = Body "Sun" 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) -moon = Body "Moon" 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) -venus = Body "Venus" 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) +sun = Body "Sun" 695700000 1.98855e30 (P $ V3 0 0 0) (V3 0 0 0) +earth = Body "Earth" 6.371e6 8.97237e24 (P $ V3 au 0 0) (V3 0 29.78e3 0) +moon = Body "Moon" 1.7371e6 7.342e22 (P $ V3 (au+384399e3) 0 0) (V3 0 (29.78e3+1022) 0) +mercury = Body "Mercury" 2.4397e6 3.3011e23 (P $ V3 57909050000 0 0) (V3 0 47362 0) +venus = Body "Venus" 6.0518e6 4.8675e24 (P $ V3 108208000000 0 0) (V3 0 35.02e3 0) +mars = Body "Mars" 3.3895e6 6.4171e23 (P $ V3 227.9392e9 0 0) (V3 0 24.077e3 0)