Try the pythagorian theorem: x = sqrt(y^2 + z^2)
Since you can have any value on the x axis, the shortest distance will always be a straight line.
To see it better, draw out a triangle, where Z is the height, and Y is the lenght, leaving the distance X which will be the hypotenuse.
Draw it out, it'll make it clear.
EDIT: X,Y,Z in your case being points A,B,C