PDA

View Full Version : Converting Longitude/Latitude/Altitude to Cartesian Coords



Zeeshan
04-07-2008, 02:07 AM
Hi,

I want to convert a point from Longitude/Latitude/Altitude system to Cartesian (x,y,z) coordinates.

Actually, I am extracting some 3D points from Google Earth's KML file-format and want these in simple x,y,z coordinates.

Can someone point me to some quick formulae?

Thanks a lot in advance.

CornedBee
04-07-2008, 02:09 AM
A point on or above a sphere doesn't have simple x,y,z coordinates ...

matsp
04-07-2008, 02:50 AM
A point on or above a sphere doesn't have simple x,y,z coordinates ...

Surely you can express any point in a 3D model with a x, y, z coordinate? The tricky part however is to define where (0, 0, 0) is - I would expect at the centre of earth would make the most sense. You will probably need double precision floats for the height over surface to make any measurable difference to the calculation.

--
Mats

CornedBee
04-07-2008, 03:36 AM
You will also need the radius of the sphere.

Didn't think of a containing space for the sphere. Yes, of course that is possible.

Let's assume that (0,0,0) is the center of the sphere. The planetary axis is Z. In the initial rotation, the X axis is perpendicular to the viewer, and the viewer looks at the 0°-meridian. In other words, a beam from the root to the camera goes through (0°ln,0°lt)

OK, first, you rotate by the longitude around the Z axis. The viewer now looks at the ln°-meridian. The beam goes through (ln°ln,0°lt).
Next, you rotate by the latitude around the new X axis. The viewer now looks at the desired spot, and the beam goes through it.
Finally, you take that beam and measure off it the radius of the sphere plus the altitude. You've got the desired point.

brewbuck
04-07-2008, 09:05 AM
If you want this to be at all accurate you will have to use one of the geoid models provided by USGS or NASA. The Earth is not a perfect sphere, in fact, not even close to one.

Neo1
04-07-2008, 01:31 PM
If you want this to be at all accurate you will have to use one of the geoid models provided by USGS or NASA. The Earth is not a perfect sphere, in fact, not even close to one.

From wikipedia:
As determined by modern instruments, a sphere approximates the earth's shape to within one part in 300

I'd say that it's pretty close, it's certainly not "not even close to one"...

brewbuck
04-07-2008, 01:33 PM
From wikipedia:
As determined by modern instruments, a sphere approximates the earth's shape to within one part in 300

I'd say that it's pretty close, it's certainly not "not even close to one"...

What the heck? 1 part in 300 is freaking huge. The Earth's diameter is about 8000 miles. 1/300th of that is about 27 miles.

So yeah, if you want your coordinates to be off by about 27 miles feel free to disregard the actual shape of the planet...

Neo1
04-07-2008, 01:50 PM
Well the actual size matters little, would you also argue that 1/300 of the width of a hair is much? Well compared to the entire width it's the same difference as with the earth, obviously...

If you take into consideration how much of a hassle it would be not to consider the earth a perfect sphere from a programming point of view, i think the signifigance of those 27 miles become less and less apparent...

brewbuck
04-07-2008, 02:02 PM
Well the actual size matters little, would you also argue that 1/300 of the width of a hair is much? Well compared to the entire width it's the same difference as with the earth, obviously...

Uh, consider all the REASONS why a person would want to convert lat/long/alt to Cartesian coordinates... For instance, controlling the path of a satellite; targeting a space-based laser; telling the aliens where to land... Are you sure that 27 miles of error is acceptable in those applications?

Even if this is for toy purposes, that's a huge error. I type in a latitude-longitude of my house, and it displays the terrain miles away from the location I wanted. Garbage. Use a real model.

EDIT: even more telling is this statement by the OP: "Actually, I am extracting some 3D points from Google Earth's KML file-format and want these in simple x,y,z coordinates."

So yes, if you want your data to be completely useless for any real application, disregard the shape of the Earth.

And your argument about "difficulty" is moot, since there are plenty of public domain implementations of these transformations on the web.

Neo1
04-07-2008, 02:07 PM
Uh, consider all the REASONS why a person would want to convert lat/long/alt to Cartesian coordinates... For instance, controlling the path of a satellite; targeting a space-based laser; telling the aliens where to land... Are you sure that 27 miles of error is acceptable in those applications?

Even if this is for toy purposes, that's a huge error. I type in a latitude-longitude of my house, and it displays the terrain miles away from the location I wanted. Garbage. Use a real model.

Well, i don't want to argue with this, for this particular purpose perhaps 27 miles is to big of an error margin.

I still wouldn't say that it's not even close to a perfect sphere, it's so huge, 27 miles is a grain of sand in a desert.

Magos
04-07-2008, 03:01 PM
Uh, consider all the REASONS why a person would want to convert lat/long/alt to Cartesian coordinates... For instance, controlling the path of a satellite; targeting a space-based laser; telling the aliens where to land... Are you sure that 27 miles of error is acceptable in those applications?

I'm pretty sure the gov' engineers developing those laser-firing satellite systems aint coming to cprog.com asking for help how to convert between different coordinate systems :).

As for the OP, some info + conversion rules can (as always) be found on wikipedia: http://en.wikipedia.org/wiki/Spherical_coordinates