Search code examples
mathlanguage-agnosticgeometrygreat-circle

Draw a path around a globe?


So basically I would like to:

  • Draw a path between two positions in Earth, with longitude and latitude coordinates
  • Be able to render this path with multiple straight lines (e.g. with OpenGL)
  • Specify an altitude, and bonus points for being able to arc over the sphere (e.g. a flight path)
  • Doesn't really matter which language it's in. I can translate :)

There is the "great-circle" distance formula, but I'm not sure how I would apply it into this problem.


Solution

  • All right, here's my approach. If any of the steps are unclear, tell me and I'll elaborate.

    1. We're going from A to B.
    2. We normalize these vectors, a = A/|A|, b = B/|B|. (The magnitudes |A| and |B| will be the radius of the Earth if we're staying on the ground.)
    3. We take the cross-product, c = a x b. We will rotate around this vector, c, to carry A to B, and the magnitude of c is the cosine of the angle between A and B: theta = acos(|c|). Pretty cool, huh?
    4. We don't want to make the trip in one jump, we want n small steps, so we divide theta up. We start at A, then at each step we rotate around c by an angle theta/n.
    5. That gives a path along the ground. To get an arc (maybe starting/ending at some altitude), we decide how much altitude to add at each step (very easy in spherical coordinates-- in Cartesian we must scale the vector).