3

I'm lost on how to correctly and accurately translate Lat/Lon coordinates to XY coordinates to draw them using OpenGL.

The coordinate information I have is the following: Start Lon, Start Lat, End Lon, End Lat.

Here's some coordinates:

StartLon="-115.1051997" StartLat="36.0740197" EndLon="-115.0845997" EndLat="36.0740197"
StartLon="-115.0639997" StartLat="36.0740197" EndLon="-115.0434" EndLat="36.0740197"
StartLon="-115.0228" StartLat="36.0740197" EndLon="-115.0022" EndLat="36.0740197"
StartLon="-114.9816" StartLat="36.0740197" EndLon="-114.9609997" EndLat="36.0740197"
StartLon="-114.9403997" StartLat="36.0740197" EndLon="-114.9197997" EndLat="36.0740197"
StartLon="-114.8991997" StartLat="36.0740197" EndLon="-114.8786" EndLat="36.0740197"
StartLon="-114.858" StartLat="36.0740197" EndLon="-114.8374" EndLat="36.0740197"
StartLon="-114.8168" StartLat="36.0740197" EndLon="-114.7961997" EndLat="36.0740197"
StartLon="-114.7755997" StartLat="36.0740197" EndLon="-114.7549997" EndLat="36.0740197"
StartLon="-114.7343997" StartLat="36.0740197" EndLon="-114.7138" EndLat="36.0740197"
StartLon="-114.6932" StartLat="36.0740197" EndLon="-114.6726" EndLat="36.0740197"
StartLon="-114.652" StartLat="36.0740197" EndLon="-114.6313997" EndLat="36.0740197"
StartLon="-114.6107997" StartLat="36.0740197" EndLon="-114.5901997" EndLat="36.0740197"

I have this conversion algorithim right now, but I'm not sure if it's correct:

    private const double EarthRadius = 6371;

    public static double GetXCoord(double lat, double lon)
    {
        return (EarthRadius * Math.Cos(ToRadians(lat)) * Math.Cos(ToRadians(lon)));
    }

    public static double GetYCoord(double lat, double lon)
    {
        return (EarthRadius * Math.Cos(ToRadians(lat)) * Math.Sin(ToRadians(lon)));
    }

    public static double ToRadians(double valueInDegrees)
    {
        return (Math.PI / 180) * valueInDegrees;
    }

Any idea on how to take the four sets of Lat/Lon coordinates to accurate convert them to XY(Z) so I can plot them using OpenGL (Tao C#)?

1

As @radouxju says, you have two components of a 3d cartesian conversion.

It sounds like you are really looking for a Map Projection. This converts the surface of the Earth (latitude, longitude) into flat 2d cartesian coordinates. It is impossible to do this without some distortion. Hence there are literally thousands of possible projections. You choose the projection according to the type of distortion that is acceptable (eg. choose area vs shape) an/or the location you want it to work for (eg. the UK's Ordnance Survey use a system based on a Transverse Mercator projection that works very well for the British Isles but is pretty crummy for other areas).

So you need to choose your map projection. The simplest (a geographic projection) would be something like:

x = Longitude
y = Latitude

(you may need to reverse signs depending on your axis orientation in your cartesian system)

Other popular global projections include things like Mercator (preserves compass bearings), and "Cylindrical Equal Area" (preserves area). Regional projections include systems like the UTM (Universal Transverse Mercator) projections, Albers Equal Area Conic, etc.

1

the two equations that you are using here are for the conversion to a 3D cartesian coordinate system (for a 3D plot with the origin at the center of the Earth), so you must have the Z-axis, otherwise you will represent the projection of your points on the equatorial plane (which is probably not what you want).

    public static double GetZCoord(double lat, double lon)
    {
        return (EarthRadius * Math.Sin(ToRadians(lat)) );
    }

Remark 1 : This conversion is only an approximation based on a spherical Earth. If you need a more accurate value, you need to account for the shape of your Ellipsoid (and you need to know the lat/long coordinate system being used, it is probably WGS 84 but it could be another one). Have a look at Haversine or Vicenty formulas if you want more precision.

Remark 2 : for map visualisation, map projection (2D XY coordinate systems) are usually more useful. There are plenty of projections depending on your needs (to preserve aither the shape, the distance or the areas of your polygons).

EDIT : your region of interest seems to be a small area near Henderson. So a local projection would be your best choice because distortions will be minimized. A very common projection for this kind of problem is the UTM, and you are location in the zone 11 North. You can find the equations on the Web, for example here (Wikipedia). You could also have a look at gdaltransform as a source of inspiration.

  • Thanks for the reply. You would be correct with the first assumption, I want to translate the coordinates to a 2D coordinate system. Considering this, what is the best way to accomplish this? While doing this, I need to keep the OpenGL canvas/window scale as a contributing factor. – Mapo Sep 27 '14 at 15:06
  • Thanks for your updates to this, radouxju. Unfortunately, I need to be able to take any lat/lon coordinate (whether it be in the United States or China) and be able to draw it; thus I can't just focus on a specific region. I'm still very new to OpenGL, so apologies for the lack of understanding, but is it possible to have it convert the coordinates for me? Perhaps using the ortho projection method? Basically, I need to be able to take any lat/lon coordinate, and convert it into its XY screen pixel counterpart for rendering. – Mapo Oct 1 '14 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.