Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would one calculate the interception point $Y$ with $\overleftrightarrow{XY}$ being the shortest distance of $X$ to $\overleftrightarrow{AB}$?

Cross track error coordinate

This answer to the question How to find the distance between a point and line joining two points on a sphere? describes how to calculate the distance, but not the coordinates.

What would be the most direct way to calculate the coordinates of interception point $Y$?

I since found out that this problem is also called the along track distance and have implemented it but have troubles checking my results.

For completeness here are the formulas and their code counterpart I have used and implemented:

$dxt = asin(\sin(d_{13}/R) * \sin( \phi_{13}−\phi_{12})) * r$


  • $d_{13}$ is distance from start point to third point
  • $\phi_{13}$ is (initial) bearing in degrees from start point to third point
  • $\phi_{12}$ is (initial) bearing in degrees from start point to end point
  • $r$ is the earth’s radius

in JavaScript:

var dXt = Math.asin(Math.sin(d13/R)*Math.sin(Math.PI / 180 * (brng13-brng12))) * R;

in Java:

final double dt = Math.asin(Math.sin(d13 / r) * Math.sin(Math.toRadians(b13 - b12))) * R;

then I calculate the Along Track Distance (following the formula on the site)

$dat = acos(\cos( d_{13}/r) / \cos(dxt/r)) * r$


  • $d13$ is distance from start point to third point
  • $dxt$ is cross-track distance
  • $r$ is the earth’s radius

in JavaScript:

var dAt = Math.acos(Math.cos(d13/R)/Math.cos(dXt/R)) * R;

in Java:

final double dAt = Math.acos( Math.cos(d13 / r) / Math.cos(dXt / r) ) * r;

As a test case I have

  • $A (0,0)$
  • $B (90,0)$
  • $X (45,45)$

and get the following results my with my implementation

  • $3335847.799336763$ for $\overleftrightarrow{XY}$
  • $6086322.17407125$ for $\overleftrightarrow{AB}$

and thus $(54.735, 0) as coordinates for Y

Using $r * \cos (lat)$ the radius on the given latitude is $4504977.303$, thus $1/8$ of the circumference is $3538200.9$.

Shouldn't $Y$ be $(0, 45)$? Surely the shortest distance from $X (45, 45)$ to $\overleftrightarrow{AB}$ is the great circle on 45° latitude ? Thus the cross track -distance should be $3538200.9$. Am I lacking imagination in three-dimensions?

share|cite|improve this question
Maybe start by rotating the sphere so that A is at the north pole and B is on the $xz$-plane? (Just a thought.) – Jesse Madnick Jun 22 '12 at 6:10

I think the best way to do this would be to look at the sphere as a subset of 3-dimensional space, find the coordinates of A, B, and X in that 3-dimensional space (that's just converting spherical coordinates to Cartesian), and then you can (orthogonally) project everything onto the plane containing A, B, and X. A, B, and X project to themselves, of course, and the arc between A and B will project to the line between A and B, and the arc between X and Y will project to the line between X and Y. Therefore, Y will project to the orthogonal projection of X onto the line AB, and then from that you can just project back onto the sphere and convert that to latitude and longitude. It's somewhat indirect, but it avoids having to work with distances in spherical coordinates.

share|cite|improve this answer
I may have to look into this. At this time I try not to transform my coordinates. Would you care to take a look at my approach I added to my question? – oschrenk Jul 4 '12 at 14:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.