diff options
author | ywang <foo@example.com> | 2019-11-27 10:37:25 +0100 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2019-11-27 10:37:25 +0100 |
commit | 2157a7ef365902162336540d89d91049c5d3a394 (patch) | |
tree | 83474690ec0c98664dcf9894d39eec127b027f38 /advtrains | |
parent | 35a6f14561add77ff96e943b748327041c1c5924 (diff) | |
download | advtrains-2157a7ef365902162336540d89d91049c5d3a394.tar.gz advtrains-2157a7ef365902162336540d89d91049c5d3a394.tar.bz2 advtrains-2157a7ef365902162336540d89d91049c5d3a394.zip |
Simplify formula for brake distance calculation
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/lzb.lua | 9 |
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 |