Joining tracks and sloping the terrain were certainly the biggest dilemnas I've had but my approach has been geared towards this end. There are many ways to mathematically describe a rectangle, which is why I started with the circular track. The key parts were separating the model into a terrain and a displaced surface so that the terrain could be sloped without affecting the sleepers and rails.
I had a think about doing double tracks and this helped narrow down the approach. You couldn't just duplicate this setup and offset it a bit as the terrains would overlap and screw each other up. Circular tracks would have the same centre of curvature but different radii depending on which way the track curved and things quickly get messy from here.
It struck me at this point that the circular track model was constructed as a reflection of half a track along the track centre. So a) it would be relative straightforward to just create extra rails further away from the track centre, lengthen the sleepers etc... to have muliple parallel tracks and b) the path of the track(s) is defined as a single path which simplifies the math for joining two sections together. The only position that will be manually entered is the start position. The position and bearing of the end of the track is calculated from the other settings entered and then passed on to the next track segment. So for all subsequent sections of track you only define a length for straight sections, and a final compass heading and direction of the turn for circular sections.
Had I started with a straight section of track I probably would have defined the outer edges first and then worked my way in which would have made joing sections much trickier (calculating 4 corners or edges instead of 1 line).
Tidying up the sleepers at the joins is another matter. I originally thought I could just add a scalar to change the length to fix up any sleepers that got cut in half but that's too messy as well. To handle that, I think it will be better to adjust lengths and compass headings to muliples of the separation between sleepers. The deviations from manually entered values should be trivial.
For the straight sections I'm leaning towards SSS with transformations to position it by the centre of the segment and rotated to the compass heading
Smoothing the slope between sections will involve calculating the slope at the ends of each section, splitting the difference and defining a new slope with this value. A cosine function can then be used to adjust the height along the track from the starting slope to the final one.
Sounds good in my head anyway