View Full Version : Calculating the Latitude and Longtitude of a 3D point..
01-07-2004, 10:47 AM
..so there you have it.. i have a 3D grid , 297 points total, each point is 1/8 mile(201 meters) apart and i need to click on each point and to get a lat&lon from that particular point. where do i start? i also would like to keep track of the azimuth.. help with anyone that knows.. thanks!
01-07-2004, 02:26 PM
There's the simple answer and the real answer for a non-spherical earth.
The simple answer is that latitude and longitude are just 2/3 of spherical coordinates. Converting to spherical is pure trig:
longititude = theta = atan2(x,y); //or y,x
latitude = phi = asin(z); //assuming Z is up, or swap y and z.
altitude = distance from x,y,z to origin minus height of ground.
Fix signs and pre-normalize values to -1,1 as needed.
01-08-2004, 05:32 AM
thaanks for your help! i admit that my trig is rusty... as far as depth goes, i already have that solved and when i pick on each point i get the correct depth.. i just need the lat and lon with it..so i have to ask and i hope that this wont sound too dumb.. what is atan2 and asin?? are those like the inverses? anyway thanks for your help. the 3d coordinates of each point are already stored and i know where each one is which is why i am able to use glUnProject to get my height in 3D coorinates. i am just confused about atan2 and asin.. could you explain? thanks in advance so much!
so here would be an example.. i click on a point on my heightmap 3d grid and i get back the x,y,z coordinate. lets says, (2082.78 -1271.32 -548.377).
heres a thought.. lets say i need a lat, lon offset from the original render..for my translation.. so lat offset would be between -90 - 90, lon offset would be between -180 and 180 and the azimuth would be 0 - 360 degrees. the azimuth i can get but i would just thinking if i also wanted to use lat lon to translate my terrain how would that work? as you can tell i am completely lost of this topic even after searching countless boards and finding very little that is useful. any help would be appreciated!
[This message has been edited by cutting_crew (edited 01-08-2004).]
01-21-2004, 09:19 PM
USGS has GCTP, General Cartographic Transformation Package, which converts latitude, longitude to x,y meters for a number of projections. The C code is adaptable. One requirement is your x,y,z point is displayed using some known projection in the first place. Mercator and orthographic are the easiest to deal with. In Mercator, lat and lon are vertical and horizontal. Orthographic (not the openGL definition) projection is a straight-on view from an infinite point away, but the math is relatively simple. So, assuming your x,y point is displayed using a supported projection, GCTP makes it trivial to get longitude and latitude. X,y from lon, lat also is trivial. Check out usgs.gov.
01-27-2004, 11:16 AM
Yes arc sin, arc cos, arc tan are all names for the inverse trig functions, they get you back from coordinates to the angle you started with.
In C: #include <math.h>
In C++: #include <cmath>
The atan2() function is a special case of the atan() function. Instead of atan(y/x) you can use atan2(y,x) and it is smart enough to know about the signs of y and x. Like, 45 degrees, 135 degrees, 225 degrees, and 315 degrees all have the same coordinates just with different signs because they are in different quadrants. atan2() is smart enough to look at the signs and give the correct angle instead of always giving 45 degrees like atan() would have.
[This message has been edited by gltester (edited 01-27-2004).]
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.