Yesterday, I was thinking about one characterization of the line segment in euclidean geometry: The shortest distance between two points is a line segment. We can use this to describe a "line" in spherical geometry, for example.
But how do we do to find the shortest distance between two points in a surface, "walking" along the surface? I have been thinking the following: Suppose you have the surface described by $z=x^2+\sin(y)$, lets take two points at this surface, say: $\{x_0,y_0,z_0\},\{x_1,y_1,z_1\}$. I believe we have to find a plane which have these two points as solutions and have a continuous curve as an intersection with the original surface and then use line integrals, but (intuitively) there can be a myriad such curves. How to find the best one (shortest distance)?
Also, how simple are the curves that we can have as an intersection? I guess that if we are lucky enough, we can find some convenient cases in which it could be written as some of original functions used in the original function, that is: An intersection function in terms of $x²,\sin(y)$, but I guess there are also some examples in which the intersection function can be radically different from the functions given in the original function.
Also I am assuming that the intersection with a plane would yield the best distance, but it could be something else. I am assuming it is a plane because I've seen somewhere that the smallest distance between two points on the sphere is the intersection of it with a plane. This is perhaps, something basic from calculus and my stupidity has forbidden me of seeing it, but I can't really find out by myself. I am also sorry about the complete speculative nature of my question, but I believe it will be meaningful enough to allow answers.