2

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.

user1118321
  • 25,567
  • 4
  • 55
  • 86
gak
  • 32,061
  • 28
  • 119
  • 154
  • I'm not familiar with OpenGL. Do you want a sequence of points? In spherical coordinates or Cartesian? – Beta Sep 30 '12 at 22:54
  • @Beta Yes, a sequence of points in either spherical or cartesian coordinates, whichever is less complex. – gak Sep 30 '12 at 23:11
  • Do you know how to convert between the two? Are you familiar with the idea of a rotation matrix in Cartesian coordinates? – Beta Oct 01 '12 at 00:16

1 Answers1

3

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).
Beta
  • 96,650
  • 16
  • 149
  • 150
  • Can you provide code examples for each step? I'm having difficulty understanding some of these mathematical concepts. You make it sound easy :) So these are Cartesian coordinates, e.g. "A" would be a x, y, z point relative to the center of the Earth? Step three looks like there are several steps, coding wise, that I don't understand how to implement. – gak Oct 01 '12 at 02:43
  • most languages have all the operations listed here as methods of the vector object, otherwise the math is a bit messy, what language are you using? – pseudoDust Oct 01 '12 at 13:16
  • @GeraldKaszuba, you won't be able to make this work without understanding the concepts, and to explain them all down to a basic level would take at least half a dozen pages. It might be easier to find an online tutorial on vector algebra, or sit down with a mathy friend. To start: **A** is a vector, from the center of the Earth to a point on (or near) the surface. Whether we choose to write **A** in Cartesian, spherical or any other coordinates, it's the same vector, just as the distance from Paris to Rome is the same whether it's measured in miles or kilometers. – Beta Oct 01 '12 at 17:30
  • @Beta Yes I see what you mean. Thanks for the help. – gak Oct 01 '12 at 22:00
  • @Beta Got it going! Much easier for me to understand when it's translated to code. :) Here's a screenshot: https://plus.google.com/photos/106001808066334889083/albums/5794942733870295681 – gak Oct 03 '12 at 04:59
  • @GeraldKaszuba SHALL WE PLAY A GAME? – Beta Oct 03 '12 at 05:41
  • @Beta haha it does look like it :) – gak Oct 03 '12 at 06:18