Keeping a Train on Rails (Spline based)

For a small projekt I need a train that must be able to drive curves.
Its easy to move the train along a straight spline, but with curves (or inclines) its actually getting pretty tricky.

Just to make it clear, we are not talking about small mine cart wagons. This is about long wagons of real trains.

I thought about having the wagon pivot at the front wheels and drive two points on the spline, one for the front and one for the back wheels. On a straight segment, you can just trail the second point by the distance of the wheels and use some transform magic to place the wagon correctly. But that does not work in curves. Assuming a sharp 90° curve, and a constant speed on the front wheel, the back of the wagon needs to slow down in the curve, which increases the distance on spline between the wheels. The increase in distance (on the spline) depends on the radius of the curve. Sure you don’t put the radius of each small bent into your code.

So how do you write generic code to find the corret position on spline for the backwheel for any circumstance?

What I would go for is a search algorithm:
Take the front wheel distance on spline, subtract the distance between the wheels and get the transform on the spline. Then check if the distance between the front wheel transform (on spline) and back wheel transform (on spline) is equal to the distance of the wheels.
If it is, take that transform for the backwheel.
If it is not, increase (the distance on spline can only increase) the sample distance for the backwheel on the spline and try again and again until a transform is found that statisfies WheelDistance==Distance(TransformFrontWheel, TransformBackWheel).

Would that be the correct way to go or do you have any other ideas?