## Finding Lat/Lon on a 3D Globe

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

JBJ
Posts: 1263
Joined: Fri Dec 12, 2008 6:20 pm UTC
Location: a point or extent in space

### Finding Lat/Lon on a 3D Globe

If I have a 3D globe that looks like this:

How could I find the latitude/longitude from the x,y coordinates?
(x,y coords based on the green crosshair with 0,0 at the center).

In the example picture above, the visible edges of the globe are 195 pixels from the center on each axis, but the actual size will be different depending on the display. The width and height will always be the same. So if another value for the boundaries makes it easier to explain, feel free to substitute.

The globe will also be spinning and in different orientations (looking more on the northern/southern hemispheres). It doesn't have to be precise, but I'd like to be accurate within about 5 degrees or so (250-350 miles).

I can already determine the lat/lon at the centerpoint (0,0), so what would be great would be the relative angles on the sphere from the center position. In other words, always assume that the center is on lat 0.000, long 0.000. I can transpose from there.

Background: I'm working on this as a little side project for work as a fun little data visualization. It was inspired by and borrowed heavily from here:
http://www.smartjava.org/content/render ... be-threejs
and here:
http://www.chromeexperiments.com/globe

Thanks in advance for any help.
So, you sacked the cocky khaki Kicky Sack sock plucker?
The second cocky khaki Kicky Sack sock plucker I've sacked since the sixth sitting sheet slitter got sick.

scarecrovv
It's pronounced 'double u'
Posts: 674
Joined: Wed Jul 30, 2008 4:09 pm UTC
Location: California

### Re: Finding Lat/Lon on a 3D Globe

Is this an orthographic or perspective projection?

http://en.wikipedia.org/wiki/3D_projection

It makes a difference. Orthographic would be easier. I think you might have a perspective projection, but it's hard to be sure from just the picture.

JBJ
Posts: 1263
Joined: Fri Dec 12, 2008 6:20 pm UTC
Location: a point or extent in space

### Re: Finding Lat/Lon on a 3D Globe

It appears that it indeed was a perspective camera. I'm using the Three.js library, and looking at the documentation, I see that there is an alternative to use an Orthographic camera.
I just switched it around to use the orthographic camera and I get the following now:

I also added reference lines at 30 and 45 degrees (30 degrees only to the right of 0,0)
So now it looks like 30 degrees is halfway between the center and the visible edge. Can I now just use sin and cos to find the lat/lon?
So, you sacked the cocky khaki Kicky Sack sock plucker?
The second cocky khaki Kicky Sack sock plucker I've sacked since the sixth sitting sheet slitter got sick.

PM 2Ring
Posts: 3683
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

### Re: Finding Lat/Lon on a 3D Globe

JBJ wrote:Can I now just use sin and cos to find the lat/lon?

Pretty much. For details, have a look at the draw() function in my animated globe JavaScript program that I posted in Coding: Fleeting Thoughts back in 2011.

JBJ
Posts: 1263
Joined: Fri Dec 12, 2008 6:20 pm UTC
Location: a point or extent in space

### Re: Finding Lat/Lon on a 3D Globe

Excellent. Thanks to both for your help, I've got enough now to forge ahead.
So, you sacked the cocky khaki Kicky Sack sock plucker?
The second cocky khaki Kicky Sack sock plucker I've sacked since the sixth sitting sheet slitter got sick.