Two towns A and B are 5km and 7km, respectively, from a railroad line. The points C and D nearest to A and B on the line are 6 km apart. Where should a station be located to minimize the length of a new road from A to S to B?

Apparently the answer is supposed to be 3.5 but the methods I've used (e.g. using tan and a^2 + b^2 = c^2) but they don't seem to work. Can anyone help me get the answer? Much appreciated.

what is S? Does it lie on the rail line? If so then if S is x km from C, you want to minimize

z = √(x^2+5^2) + √((6-x)^2 + 7^2)
sure enough, x = 5/2, or 3.5 km away from D
dz/dx = x/√(x^2+5^2) - (6-x)/√((6-x)^2 + 7^2)
now just find x where dz/dx = 0