Link to home
Start Free TrialLog in
Avatar of verintsupport
verintsupport

asked on

how do you correct for the latitude in lat long calculations?

In a previous question:
https://www.experts-exchange.com/questions/21835297/How-can-i-calculate-the-angle-between-2-vectors-lat-long.html

I'm still trying to figure out how to compensate for the latitude:

D-glitch answered :
---------------------------------------------------------------------------------------------------------
At the equator, degrees of long and lat are the same size:   ~70 miles/deg
As you move north or south, deg lat stay the same, but deg long shrink by cos(lat)

So it is not correct to treat the long and lat coordinates as distances.

a    -95.770712    34.934324          
b    -95.768356    34.933977          
c    -95.774587    34.925908          

a'    -0.002356     0.000347          
b'     0.000000     0.000000          
c'    -0.006231    -0.008069          
                   
Correcting for the latitude:
         
a"    -0.001932     0.000347        169.82 deg
b"     0.000000     0.000000
c"    -0.005109    -0.008069        237.66 deg
--------------------------------------------------------
                                                 67.84 deg

--------------------------------------------------------------------------------------------

Thanks

Richard
Avatar of Dushan Silva
Dushan Silva
Flag of Australia image

Avatar of verintsupport
verintsupport

ASKER

Thanks Dushan911!

It's very interesting...and it will be very useful at one point.

 Does it hold the answer to my current question?

Richard
You have to say what you mean by "correct for"
Do you want to compute the azimuth (direction to steer on the surface) to get from point A to point B, or do you want to know the distance between two points?

If you want the approximate distance between two points close to each other, then you can simplify quite a bit:

latLonRatio = cos((lat1 + lat2) / 2)
dx = (lon2 - lon1) * latLonRatio
dy = lat2 - lat1
dist = sqrt(dy*dy + dx*dx)

example: You are at 40N, 74W and want the distance to 40N,74.1W
cos(40) = .766
.1*.766 = .0766 degrees
It's better to do it in radians, then r*angle = distance.
 .0766 degrees = .01337 radians   (radians = degrees * pi / 180)
the radius of the earth is about 6370 km, ie 6370000 m
6370000 * .01337 = distance in meters.

distance to 40.1N, 74.1W:

dx = .1 * .766
dy = .1
dist = sqrt( ... )

If you want the azimuth, the code is in the following page in Javascript, close enough to C: http://blubwat.net/altaz.htm
The goal is to calculate the angle between 2 vectors on earth... see below.

D-glitch  answered my other question with a good answer but i don'T understand how he compensated for the latitude.... see his answer in the question.

Thanks

x: lat, long
a: -95.77071229704562,34.9343240443434
b: -95.76835645203101,34.9339768366878
c: -95.774587384548,34.9259077248493

vector A is ba
vector B is bc

I have the distance in km of both vectors

A 0.218 km
B 1.062 km

thanks

Richard
 
Avatar of ozo
I don't know what it means to a lat < -90 but the correct formula is

headingba =
 atan(cot((along-blong)/2)*sin((blat-alat)/2)/cos((alat+blat)/2)+
 atan(cot((along-blong)/2)*cos((blat-alat)/2)/sin((alat+blat)/2)

headingbc =
 atan(cot((clong-blong)/2)*sin((blat-clat)/2)/cos((clat+blat)/2)+
 atan(cot((clong-blong)/2)*cos((blat-clat)/2)/sin((clat+blat)/2)
Assuming you have lat and long reversed, d-glitch is multiplying a'long and b'long by cos(lat)
which is a good approximation if a, b and c are close to each other and far from the poles
It helps to have a real globe on hand.

Look at a circle of constant longitude. The prime meridian through Greenwich for example.
It runs north and south and goes through both poles.

Now look at the longitude line through Macalester Texas.
It also goes through the N and S poles.

All the longitude lines are the same length, the full circumference of the earth.

==> This affects the latitude.  
        If you move 1 deg north or south, anywhere on the earth, you are moving the same distance.

==============================================================
Now look at a circle  of constant latitude.  Take the equator for example.
It is the full circumference of the earth.
So at the equator, a degree east or west is the same as a degree north or south.

Now look at the Tropic of Cancer or the Arctic Circle.  
The Tropic of Cancer is smaller than the equator, and the Arctic Circle is even smaller.
So if you move a degree east or west, the distance depends on how you are from the equator.

For longitude,   1 deg =  70 miles  aproximately

At the equator  1 deg =  70 miles * cos( 0 deg)  =  70 miles

At the poles      1 deg =  70 miles * cos( 90 deg) =  0.

This is as good an approximation as the earth is round.  It is certainly the one you want to start with.
You're talking about calculating geodesics.  The above formulas are correct if you don't care about correcting for geodetic eccentricity (the bulge around the equator modeled by the WGS84 ellipsoid).  To do it the really frickin' accurate way you need to use Vincenty's method for calculating regular and inverse geodesics.

Straight from the horse's mouth:  http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf

d-glitch

I'm sorry for my slow understanding and i thank you for the nice explanation you gave me.

I undertsand why we have to compensate but i have a hard time arriving at the same numbers as you.

Would you mind going step by step with formulas to get to this answer wich is the right one?    67.84 deg


a    -95.770712    34.934324          
b    -95.768356    34.933977          
c    -95.774587    34.925908          

a'    -0.002356     0.000347          
b'     0.000000     0.000000          
c'    -0.006231    -0.008069          
                   
Correcting for the latitude:
         
a"    -0.001932     0.000347        169.82 deg
b"     0.000000     0.000000
c"    -0.005109    -0.008069        237.66 deg
--------------------------------------------------------
                                                 67.84 deg

Thanks
I used an Excel Spreadsheet:

To go from [a b c] ==> [a' b' c']             I subtracted the b coordinates from each of the points.

To go from  [a' b' c'] ==> [a" b" c"]        I multiplied the longitude values by cos( 34.93 deg) = 0.8199

This gives you (x,y) coordinates that are scaled equally.  But I am not paying any attention to the scale.

Then i used the ATAN2(long, lat) to get the heading of each point relative to [b].
ATAN2 uses radians, I had to convert to degrees.

Note that ATAN2( -0.005109,  -0.008069) = -122.34 deg

I added 360 to get a positive value.

I can redo the spreadsheet and post it if that would help.      
D-Glitch,

When i use my exact values i get 63.2379... degrees.

I am wrong in thinking this is more exact or is there something i don't understand about the decimal lat/longs.

See spreadsheet below.

-0.002190571      0.000347208      2.984399319      170.9934853      170.9934853
                        
-0.005812892      -0.008069112      -2.195074934      -125.7685294      234.2314706
                        
-2.135244827      -122.3405168      237.6594832            63.23798524

Thanks

Richard
Your answer may be correct.  I may have lost some digits cutting and pasting between EE and Excel when I corrected my wrong answer in the earlier question.

I will check my math again.
ASKER CERTIFIED SOLUTION
Avatar of d-glitch
d-glitch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>  I use cos( 34.xx * PI() /180)

Thank you all for your help
Thank you very much d-glitch... This is exactly what i needed... now i have to code this in c#