Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Lattitude and Longitude to X,Y

  1. Dec 8, 2009 #1
    I was writing a program to place a markers on a map of the United States, for a Civil War battlemap generator. I tried this:

    Assuming x,y and lat/long are superimposed yet different coordinate systems. For example, if a coordinate system with a unary equivalent to 12 on the other were to exist, express two concurrent points. Then use the distance formula:
    sqrt( (24+12)^2+(24+12)^2)/sqrt ( (2+1)^2+(2+1)) = 12 (as do all other concurrent values.)

    I found pixel where the four corners states meet (195,306), and a point in Florida. Using the formula above, with lat/long and x/y I calculated a conversion factor of about 14. However, when I did the four corners and the Lake Michigan. The conversion factors varied dramitcally. I thusly assume the the lines curve, even on a flat projection where Texas looks like its near Florida? My code went thus...
    Code (Text):

    const float refcoord[2]={36.998976, -109.045172};
    const float conversionfactor=0.17975951;
    const int refpix[2]={195,306};
    void drawID(float lat, float lon, FXint& x,FXint& y){
    x=refpix[0]-(refcoord[0]-lat)/conversionfactor;
    y=refpix[1]-(refcoord[1]-lon)/conversionfactor;
    }
     
    If this is the problem I think it is, could someone link me to some trig help? Thanks alot.
     
  2. jcsd
  3. Dec 8, 2009 #2

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    The size of a degree of longtitude (x-axis) depends on your latitude (since the Earth gets smaller nearer the poles)
    The size of a degree of longitude is the same everywhere.

    So you need a different scaling factor in X and Y
     
  4. Dec 8, 2009 #3
    What is the sequence or function that would define this scaling factor for x? I figured out the ratio above on my own, but my math education at the moment, is limited (trig). Or how would I determine it?

    Thanks again.
     
    Last edited: Dec 8, 2009
  5. Dec 8, 2009 #4
    Try googling "longitude x latitude y".
     
  6. Dec 8, 2009 #5

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

  7. Dec 9, 2009 #6
    Whenever I put in that calculation for (3.141592654/180)*Cos(0)*6367449 I get 111132.950017331. This must be wrong (by several factors of 10). Also, I get 0.0174.. whenever I do the more complex equation (with the polar and equatorial radii) with Cos(0). Cos(0) is, of course, 1.

    In fact I seem to be encountering .017 type stuff a LOT. Is that a constant... or something near a standard cos(x)?

    Thanks again...
     
  8. Dec 9, 2009 #7

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    There are about 111km/deg at the equator so thats probbaly the value for longtitude in metres.
    0.0174 sounds a lot like 1deg in radians - remember you computer/calcualtor is workign in radians
     
  9. Dec 10, 2009 #8
    Ahhhhhhhhhhhhhhhhhhhhhhhhh..... should've seen THAT coming.

    Thanks.
     
  10. Dec 13, 2009 #9
    Because I am a glutton for pain, I have decided to carry this one through (if I can). Aside from the obvious (km means 1000) and the less than obvious (cos(x)*6....). I tried to develop a new conversion ration JUST going vertical (different Y on a fixed X)... but the inaccuracy is .08 every 10 degrees (ratio/ratio, basically.) Is a fixed conversion ratio for longitude even valid? Otherwise, would this piece of code do it?

    Code (Text):

    const float refcoord[2]={36.999, -109.05};
    const float conversionfactor=4.3; ///The AVERAGE conversion ratio
    const int refpix[2]={321,337};
    void drawID(float lat, float lon, FXint& x,FXint& y){
    x=refpix[0]-(refcoord[0]-lat)*(conversionfactor*((float(180/3.141)*cos(float(3.141/180)*lat)) ));
    y=refpix[1]-(refcoord[1]-lon)*conversionfactor*-1;
    }
     
    It gets practice, it gets fairly close (within the size of my marker) for some locations (St. Louis). However, there is a magic threshold somewhere my X value becomes fairly massive (lake Michigan). (If anyone wants this threshold, I can figure it out by just systematically logging the output of the sub.)

    Oh... and thanks for the help.
     
  11. Dec 15, 2009 #10
    Corrected...

    Most navigational charts are http://en.wikipedia.org/wiki/Lambert_Conformal_Projection" [Broken], which have two parallel lines of latitude secant to the globe and intersecting it. The result is a chart of least distortion for it's scale, and where straight lines drawn on the chart closely approximate great circle lines.

    If you're starting with an LCC, you can use http://en.wikipedia.org/wiki/Lambert_Conformal_Projection#Transformation"to convert spheric coordinates into the projection coordinates. This is useful, as this is what most electronic mapping software uses to pinpoint one's location on a digitized chart from GPS feeds.

    No worries! http://fer3.com/arc/img/106859.pre-comp%20pages%20from%20afpam11-216.pdf" [Broken](but it's the good kind). Be forewarned, however, as it's a 70 MB file.

    Check out page 395. I think you may find it helpful. :smile:
     
    Last edited by a moderator: May 4, 2017
  12. Dec 15, 2009 #11
    Last edited: Dec 15, 2009
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook