aboutsummaryrefslogtreecommitdiff
path: root/advtrains/lzb.lua
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-12-01 12:09:04 +0100
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-12-01 12:09:04 +0100
commit0518fbbf3ae388631cb21f238068f2a6b3785972 (patch)
tree0a70cd4c3a480d32af005f7e1b67cd0e1c30976f /advtrains/lzb.lua
parentb71c72b4ab4d50c8f3a3a6ccbe15427548e1d2ff (diff)
parent2157a7ef365902162336540d89d91049c5d3a394 (diff)
downloadadvtrains-0518fbbf3ae388631cb21f238068f2a6b3785972.tar.gz
advtrains-0518fbbf3ae388631cb21f238068f2a6b3785972.tar.bz2
advtrains-0518fbbf3ae388631cb21f238068f2a6b3785972.zip
Merge branch 'master' of https://git.bananach.space/advtrains
Diffstat (limited to 'advtrains/lzb.lua')
-rw-r--r--advtrains/lzb.lua9
1 files changed, 4 insertions, 5 deletions
diff --git a/advtrains/lzb.lua b/advtrains/lzb.lua
index afbf68e..6cbf4ab 100644
--- a/advtrains/lzb.lua
+++ b/advtrains/lzb.lua
@@ -85,9 +85,9 @@ end
--[[
Distance needed to accelerate from v0 to v1 with constant acceleration a:
- v1 - v0 a / v1 - v0 \ 2
-s = v0 * ------- + - * | ------- |
- a 2 \ a /
+ v1 - v0 a / v1 - v0 \ 2 v1^2 - v0^2
+s = v0 * ------- + - * | ------- | = -----------
+ a 2 \ a / 2*a
]]
local function apply_control(id, train)
@@ -112,8 +112,7 @@ local function apply_control(id, train)
local v0 = train.velocity
local v1 = it.spd
if v1 and v1 <= v0 then
- local f = (v1-v0) / a
- local s = v0*f + a*f*f/2
+ local s = (v1*v1 - v0*v0) / (2*a)
local st = s + params.ADD_SLOW
if v0 > 3 then