Converting Longitude/Latitude/Altitude to Cartesian Coords

This is a discussion on Converting Longitude/Latitude/Altitude to Cartesian Coords within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Hi, I want to convert a point from Longitude/Latitude/Altitude system to Cartesian (x,y,z) coordinates. Actually, I am extracting some 3D ...

  1. #1
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    Munich, Germany
    Posts
    224

    Converting Longitude/Latitude/Altitude to Cartesian Coords

    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.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    A point on or above a sphere doesn't have simple x,y,z coordinates ...
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    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.

  6. #6
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by brewbuck View Post
    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"...
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Neo1 View Post
    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...

  8. #8
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    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...
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  9. #9
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Neo1 View Post
    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.
    Last edited by brewbuck; 04-07-2008 at 02:05 PM.

  10. #10
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by brewbuck View Post
    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.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  11. #11
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Quote Originally Posted by brewbuck View Post
    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
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting Longitude/Latitude/Altitude to Cartesian Coords
    By Zeeshan in forum Game Programming
    Replies: 6
    Last Post: 04-24-2008, 03:14 AM
  2. Trying to convert vectors from cartesian coordinate
    By FALSTON01 in forum C++ Programming
    Replies: 1
    Last Post: 10-20-2005, 05:17 PM
  3. Heightfield Texture Coords
    By psychopath in forum Game Programming
    Replies: 1
    Last Post: 10-03-2005, 09:55 AM
  4. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  5. Direct Input and Mouse Coords
    By Khelder in forum Game Programming
    Replies: 5
    Last Post: 12-30-2003, 01:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21