Drexel dragonThe Math ForumDonate to the Math Forum

Ask Dr. Math - Questions and Answers from our Archives
_____________________________________________
Associated Topics || Dr. Math Home || Search Dr. Math
_____________________________________________

Transformation between (x,y) and (longitude, latitude)


Date: 01/02/2002 at 03:32:53
From: Hing C So
Subject: Transformation between (x,y) and (longitude, latitude)

Dear Dr. Math,

I have two questions on the transformation between (x,y) and 
(longitude, latitude). 

1. Given 2 positions in the terms of longitude and latitude, say, 
(a1, b1) and (a2,b2) with the distance between them very small, say, 
within 10 meters, I would like to know if there are any methods that 
can compute their separation with the best accuracy. I converted the 
(a,b) to (x,y) using the following formulae:

   x = R*cos(a)*cos(b)
   y = R*cos(a)*sin(b)

where R is the earth radius. The distance is calculated as the square 
root of (x1-x2)^2+(y1-y2)^2. Please comment on my method.

2. I have a digital map giving the four corners in terms of longitudes 
and latitudes, say, (a1,b1), (a1,b2), (a2,b1), (a2,b2). I would like 
to know how to compute the (x,y) of a particular point in the map.

Thank you very much.
H.C.So


Date: 01/02/2002 at 11:19:16
From: Doctor Rick
Subject: Re: Transformation between (x,y) and (longitude, latitude)

Hi, Hing. I'll respond to each of your questions after the question:

(1)
A distance of 10 meters is *very* small compared to the radius of the 
earth, so we can definitely use a flat-earth approximation.

Your formulas give the coordinates of the projection of a point onto 
the plane on the Greenwich meridian (longitude = 0). This is not what 
you want; you really want to project the point onto a plane parallel 
to the surface of the earth in the vicinity of the points of interest.

I find it easiest to think a little differently. For the y coordinate, 
we can use the north-south distance between two lines of latitude:

  y = R*(b2-b1)*pi/180

Here, I have converted the latitude difference, (b2-b1), from degrees 
to radians, by multiplying it by (pi radians)/(180 degrees). The 
product of the angle in radians and the radius is the arc length in 
the same units as the radius.

For the x coordinate, we can use the distance along a line of latitude 
from one line of longitude to the other:

  x = R*(a2-a1)*(pi/180)*cos(b1)

Here we have an additional factor, the cosine of the latitude along 
which we are measuring. The line of latitude is a circle with a 
smaller radius than that of the equator; it is reduced by the factor 
cos(b1).

Thus, you see that I have set up a coordinate system (x,y) that puts 
one of the points of interest at the origin. The distance from the 
origin to any other point (x,y) is the square root of (x^2 + y^2).

(2) We'd have to know the particular projection used in the map in 
order to be completely accurate: is it a Mercator projection, for 
instance? If the scale is small enough (as I assume based on the 
context of the first question), I would assume it's fairly linear 
over the region of the map. Then, if you want x to vary from 0 to w 
and y to vary from 0 to h (with the origin at the bottom left), the 
coordinates of a point (a,b) are

  x = w*(a - a1)/(a2 - a1)
  y = h*(b - b1)/(b2 - b1)

That's just a simple linear transformation. Again, it assumes that the 
map covers a small area. If you're asking something more complicated 
than this, please try again to explain it.

- Doctor Rick, The Math Forum
  http://mathforum.org/dr.math/   
    


Date: 08/10/2004 at 05:51:36
From: Bryan
Subject: Using Longitude and Latitude to Determine Distance

I'm developing a digital map that encounters the same problem but 
the range is bigger.  The area of the map is around 50 km^2.

Could the formulas:

  x = w*(a - a1)/(a2 - a1)
  y = h*(b - b1)/(b2 - b1)

be applied here?  What is the accuracy factor in this case?


Date: 08/10/2004 at 08:23:25
From: Doctor Rick
Subject: Re: Using Longitude and Latitude to Determine Distance 

Hi, Bryan.

I think a linear scaling will be fine for a map with maximum 
distances less than 10 miles, as your area suggests. It is hard to 
give a formula for the maximum error, but the following page from the 
Dr. Math Archives has a table that will help:

  Planar Approximation: Latitude and Longitude
    http://mathforum.org/library/drmath/view/62720.html

There is one assumption I didn't mention with the linear scaling 
formula: it assumes that the latitudes and longitudes at the corners 
of the map have been chosen so that the map will have the same scale 
horizontally and vertically. The Planar Approximation formula in the 
page I just mentioned will help you do this.

  x = (lon2-lon1)*cos(lat1)*pi/180
  y = (lat2-lat1)*pi/180

Here, x and y are in radians; if we want them in miles, we should use

  x = (lon2-lon1)*cos(lat1)*pi*R/180
  y = (lat2-lat1)*pi*R/180

where R is the radius of the earth, R = 6367 km = 3956 mi. Solving 
for lon2,lat2 in terms of x,y:

  lat2 = lat1 + y*180/(pi*R)
  lon2 = lon1 + x*180/(pi*R*cos(lat1))

If (lon1,lat1) is the center of the map, w pixels across and h pixels 
high, and you want a scale of n pixels on the map = one mile on 
earth, the latitudes and longitudes of the corners of the map should 
be

  lat = lat1 +or- (w/2)*n*180/(pi*R)
  lon = lon1 +or- (h/2)*n*180/(pi*R*cos(lat1))

- Doctor Rick, The Math Forum
  http://mathforum.org/dr.math/   
    
Associated Topics:
College Higher-Dimensional Geometry
High School Higher-Dimensional Geometry

Search the Dr. Math Library:


Find items containing (put spaces between keywords):
 
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

_____________________________________
Math Forum Home || Math Library || Quick Reference || Math Forum Search
_____________________________________

Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/