You should view the different coordinate systems as a means of keeping track of relative movement. Thus the legs could be given a third coordinate system, which moves relative to both the coordinate system of the train as well as the "fixed" coordinate system of the Earth/tree/body.