## News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

## Braking rates and differential equations

Started by lambo, April 14, 2019, 09:55:58 AM

0 Members and 1 Guest are viewing this topic.

#### lambo

I am hoping to implement a realistic approximation of braking distance calculation in the next version of Experimental (brake performance is highly relevant to the maximum speed of rail vehicles and the capacity of railways), but my limited mathematical ability does not stretch to writing C++ code to solve differential equations of the sort required to calculate braking distances (see here for an explanation of those equations). What I need is a formula for converting speed, weight, brake force and rolling/air resistance into a braking distance. I should be grateful for any suggestions or pointers as to how to go about this task; integrating this into the Simutrans code should then be fairly straightforward.

#### jamespetts

Thank you for your interest in working on the code. I am also not proficient in advanced mathematics: the existing code relating to physics was written by Bernd Gabriel, who has not been active in development recently.

One particular (and somewhat challenging) thing to bear in mind when dealing with code relating to the physics is that it is not possible to use the standard floating point types because these are not consistent between different platforms (Linux, Windows, etc.), so will cause clients to lose synchronisation from the servers in network games if client and server are running different operating systems. To get around this, Bernd wrote a floating point class for the physics code (float32e8_t), which works effectively to prevent loss of synchronisation, but which is much slower than the normal floating point standard types.

Incidentally, do you have a particular reason to believe that the current modelling of braking is inaccurate? It was intended, at least, to be accurate when it was written for precisely the reasons that you give (viz. that braking performance is important to the speed of rail vehicles and thus the capacity of railways).

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

#### ACarlotti

Like James, I am unsure what issue you are hoping to solve with a 'realistic approximation of braking distance calculation'. The only issue I'm currently aware of is that braking distance calculations could be inaccurate if there is a change of gradient just before the stopping point - are you referring to this? If not, then what precisely are you referring to?

You mention that your "limited mathematical ability does not stretch to writing C++ code to solve differential equations of the sort required to calculate braking distances". I suspect that it might be more effective with someone who understands the maths better to write the code themselves, rather than them trying to explain the maths to another person who would then be more likely to write code that is inefficient or incorrect (and perhaps subtlely so). I could, however, be wrong about this.

Anyway, thanks for mentioning that you think there is an issue - if you explain more clearly what you think the issue is, then hopefully we can sort it out together (or perhaps istead find a good reason why it can't practicably be solved).

#### prissi

Before solving differential equation for a game like Simutrans, one should rather use polynomal fit functions, which work well with integers. That may also speed up the current acceleration code more (or had that issue ever been solved).

#### jamespetts

Quote from: prissi on April 15, 2019, 06:58:49 AM
Before solving differential equation for a game like Simutrans, one should rather use polynomal fit functions, which work well with integers. That may also speed up the current acceleration code more (or had that issue ever been solved).

The issue has not been solved - we still use the integer based floating point class, which is notably slower than built-in floating point types.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.