Geometry of a RailRoad Curve

I work on the railroads and my task is to improve the alignment of a curve.

I have surveyed the existing geometry by going along the track and recording x, y, z co-ordinates at approx 1m intervals.

I have plotted these points and then I have created a function that creates a smooth alignment.

The problem is during the implementation.

What I mean is this; on the railroads we have a machine called a Track Alignment Machine which is a rectangular locomotive which sits on the track and picks the track up and moves it left or right and puts it back down depending on the required design alignment.

The Track Alignment Machine only moves the track at right angles to itself. So if the Track Alignment Machine was on a curve then every time the machine moves the track that movement whether it be left or right would be tangent to the curve.

My problem it that how I implement my design alignment i.e f(x) if I can only move the track tangentially . I know need to know how much to move the track in both the x and y plane.

Basically what you will have to do is find the tangent vector to the curve, then find the normal vector that gives you the perpendicular property and once you have the normal vector (or the equation for the line in two dimensions), then you find the intersection of the normal line with the curve and that will give you the point.

If you have the equation for the curve then you need to differentiate the curve and find the tangent at each point. In the case of B you use what the derivative at point B and for C you use the negative of the derivative since you are going backwards and not forwards.

As for the normal, you can use the relationship that m1m2 = -1 where m1 and m2 are the rates of change corresponding to y1 = m1x + c1 and y2 = m2x + c2. Since you have B = (x1,y1) and C = (x2,y2) you can then substitute these in to find your m2 and c2 for both the B and C situations.

Then given a y = ax + c for your normal line and y = f(x) for your curve then make ax + c = f(x) and solve for x. If your curve is represented by the diagram accurately enough you will only get one solution called x = S.

Then for the distance you use the fact that d(A,B) = SQRT((xa - xb)^2 + (ya - yb)^2) where A is the point you have been given (B and C points in diagram) and B refers to the solution you found above (S,f(S)).