intersections of line segments (geodesics) on a sphere I am given two geodesics on a sphere, each designated by longitude and latitude of the endpoints.  How can I calculate whether they intersect each other?  I.e. whether the great circles intersect within the segments?
 A: Let $p_1,p_2$ are endpoints of one of the geodesics, and let's assume that $p_1,p_2$ are not antipodal points (because if they are then the geodesic is not unique). Let $q_1,q_2$ be endpoints of the other, also not antipodal. And I'm going to ignore latitude/longitide coordinates, and just use coordinates in 3-dimensions, so for example
$$p_1 = (p_{1x},p_{1y},p_{1z}) \quad\text{such that} \quad p_{1x}^2 + p_{1y}^2 + p_{1z}^2 = 1
$$
The formula $p(t) = t \cdot p_1 + (1-t) \cdot p_2$, $0 \le t \le 1$, does not even lie on the sphere, it cuts across a chord on the inside of the sphere. However, that is the kernel of a useful idea.
The formula
$$p(s,t) = s \cdot p_1 + t \cdot p_2, \quad s,t \in [0,\infty)
$$
parameterises an "angle" in 3-space whose intersection with the sphere is equal to the geodesic connecting $p_1$ and $p_2$. Similarly for the formula
$$q(s,t) = s \cdot q_1 + t \cdot q_2, \quad s,t \in [0,\infty)
$$
In both cases, multiplication by $s,t$ means scalar multiplication in 3-d coordinates, and addition means vector addition.
The two spherical geodesics intersect in at least a point on sphere if and only if the two angles intersect in at least a ray in 3-space. So now your problem is reduced to some linear algebra calculations, as follows. Form the equation $p(s,t)=q(s',t')$, which gives three equations in the four unknowns $s',t'$. Solve for $s,t,s',t'$. Check whether there exists a solution with $s>0$ or $t > 0$, and with $s'$ or $t' > 0$ (which is equivalent to saying that the two angles intersect in at least a ray). 
A: another issue seems to solve this problem.  It's pretty easy to translate the Python code shown in that issue into your programming language of choice.
