Update position and speed of all bodies
This commit is contained in:
parent
35519b8fda
commit
1056081932
1 changed files with 11 additions and 1 deletions
10
src/Lib.hs
10
src/Lib.hs
|
@ -70,6 +70,16 @@ update dt (Body m pos speed) neighbours =
|
|||
newspeed = speed + dt *^ accel
|
||||
newpos = pos + dt *^ P newspeed
|
||||
|
||||
-- Update all bodies with a timestep dt
|
||||
updateAll :: Double -> [Body] -> [Body]
|
||||
updateAll dt bodies = aux [] [] bodies
|
||||
where
|
||||
-- Cycles through all bodies, updates each one and stores it in
|
||||
-- res. Each body already updated is moved to prev.
|
||||
aux res prev [] = res
|
||||
aux res prev (b:next) =
|
||||
aux (newb:res) (b:prev) next
|
||||
where newb = update dt b $ prev ++ next
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- EXAMPLES
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue