Equations for the distance between two points from spherical trig have ambiguities that must be considered. Vector methods may be used to find the distance between two points on a sphere and these need not have the ambiguities.
First note that the distance between two points on the surface may be considered to be an angle. This angle may be measured in degrees or radians or converted to other units such as miles, kms, and so on. The angle between the surface points is the same as the angle between vectors from the center of the sphere to the surface points.
One vector technique is to find the Dot Product between the two vectors
from the center of the sphere to the points on the surface. The value
of this Dot Product is the cosine of the angle between the vectors.
This is fairly good over a large range of distances but degrades when
the points are close together or nearly 180 degrees apart. The problem
may be seen by considering a plot of the cosine function, it is nearly
flat for angles near 0 and 180 so a change in distance does not give
much change in the cosine value.
Another vector technique is to use the Cross Product. The magnitude of the
Cross Product is the sine of the angle between the vectors. This works
well for angles near 0 and 180 but degrades for angles near +/- 90 since
the sine function is fairly flat in those areas.
A good solution is to use both the Dot Product and Cross Product. If the Dot Product is considered the x component and the magnitude of the Cross Product the y component of a vector then the angle of this 2-d vector is the angular distance between the points on the sphere. Finding this angle from these components is done using the RECPOL algorithm. This gives a robust, unambiguous distance algorithm. The related algorithm POLREC is used to convert the latitude/longitudes to vectors in the first place.
The entire procedure is illustrated in the JHU/APL/S1R IDL function sphdist.