Presentation is loading. Please wait.

Presentation is loading. Please wait.

16. Latitude and Longitude

Similar presentations


Presentation on theme: "16. Latitude and Longitude"— Presentation transcript:

1 16. Latitude and Longitude
A little bit of spherical trigonometry: great circles, the Haversine Law, Rhumb lines and Mercator maps Contest Algorithms: 16. Lat & Long

2 Latitude and Longitude

3 Contest Algorithms:16. Lat & Long

4

5 Great Circles The largest circle that can be drawn on the surface of the earth. Equator Meridian/ Longitude line Another Great Circle

6 Small Circles Parallel/ Latitude line Another Small Circle
All latitude lines (parallels) are small circles except for the equator

7 Nautical Miles A nautical mile (NM) is the distance travelled on a great circle when moving through 1 minute of arc.

8 Length of the Equator There are 360o in a circle and 60' (minutes) in a degree. No. of minutes in a circle: 360 x 60 = 21600' NM length of the equator: NM 1 NM == km (by int. agreement) km length of the equator = * = 40,003 km actual is 40,075 km Contest Algorithms:16. Lat & Long

9 From Angle to NM Calculate the shortest distance from 60o W to 10o E along the equator. Smallest angle along the equator between the two positions is =70o Shortest distance = 70 x 60 = 4200 NM convert degrees to minutes

10 Latitude Distance Equator Latitude 41o N N S 41o R r As you travel around a line of latitude (small circle) the distance travelled is shorter than the distance covered on the equator (great circle). Radius of the small circle: r Radius of the Equator: R Latitude angle:  Then r = R cos  So the small circle is smaller than the great circle by a factor of cos . N r R

11 Calculate a Latitude Distance
Calculate the distance along the line of latitude from (41o N, 36o W) to (41o N, 155o E) . Smallest angle is not 191o, but 169o Converting this angle into minutes: = 169 x 60 = 10140'. Since the measurement is along a small circle the distance is reduced by a factor of cos 41o. Distance in nautical miles = x cos 41o = 7653 NM N 36o W 155o E 0o

12 Review of Plane Trigonometry
Cosine Law: A c 2 = a + b - ab cos C c b Sine Law: a sin A = b B c C B C a Angles A, B and C; Sides a, b and c

13 Spherical Trigonometry
Great circles arcs / sides / angles: a, b, c this assumes a unit sphere; otherwise multiple by radius R to get lengths 0 < a + b + c < 3π Face/surface angles / bearings: A, B, C π < A + B + C < 3π Contest Algorithms:16. Lat & Long

14 Spherical Trig. Laws Sine Law sin a A = b B c C Cosine Law for sides
a b c are sides A B C are angles Cosine Law for sides Cosine Law for angles cos a = b c + sin A B C cos A = - B C + sin a b c

15 Calculating Distance P Calculate the air distance from New York to Moscow We know their coordinates. New York: Latitude = 40o47'N, Longitude = 73o58'W Moscow: Latitude = 55o45'N, Longitude = 37o42'E The air distance = great circle arc from N to M == p m n N M p Contest Algorithms:16. Lat & Long

16 Views of the Triangle P P P n m M N m n M N View from above earth's
center n P m M 73o58'W 37o42'E N New York's longitude Moscow's longitude m n 55o45'N 40o47'N N M New York's latitude Moscow's latitude prime meridian equator earth's center earth's center Contest Algorithms:16. Lat & Long

17 Calculate cos p = cos m cos n + sin m sin n cos P Sides m and n:
m = 90o – lat of New York = 49o13' = cos m = ; sin m = n = 90o - lat of Moscow = 34o15' = cos n = ; sin n = Face/surface angle P P = long NY + long MO = 73o58'W + 37o42'E = 111o40' = cos P = Contest Algorithms:16. Lat & Long

18 cos p = cos m cos n + sin m sin n cos P Substitute:
= p = cos = o == *60 minutes = 405.3' = NM == * = km Google reports: Contest Algorithms:16. Lat & Long

19 The Haversine Law cos a = cos b cos c + sin b sin c cos A
Inaccurate when a is small Instead substitute: cos θ = 1 − 2 hav θ cos(a − b) = cos a cos b + sin a sin b Produces: hav a = hav(c-b) + sin c sin b hav A Contest Algorithms:16. Lat & Long

20 The Haversine Formula Considers the special case when A is the north pole, and B and C are the two points whose separation d is to be determined. In that case, c and b are 90° − their latitudes, A is the longitude separation Δlon, and a is the desired d/R. Note that sin(π/2 − φ) = cos(φ) Contest Algorithms:16. Lat & Long

21 hav(a/R) = hav(lat2 - lat1) + cos(lat1) cos(lat2) hav(lon2 – lon1)
lati and lon i are the lattitide of the two points R is the Earth's radius hav(angle) = sin2(angle/2) [ = (1 – cos(angle))/2 ] Let rhs of 1st equation be h, then hav(a/R) =h, so sin2(a/2R)= h a = 2R arcsin( √h) Contest Algorithms:16. Lat & Long

22 Code see LatLongTests.java
public static double haversine(double lat1, double lon1, double lat2, double lon2) { double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double a = Math.pow(Math.sin(dLat/2), 2) + Math.pow(Math.sin(dLon/2), 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.asin(Math.sqrt(a)); return EARTH_RADIUS_KM * c; } // end of haversine() Contest Algorithms:16. Lat & Long

23 public static double fromDMS(String dmsStr) /
public static double fromDMS(String dmsStr) /* Obtain an angle from a degrees, minute and secs character string. see e.g S W */ { if (dmsStr == null) { System.out.println("String is null"); return 0; } String[] dms = dmsStr.split("\\s+"); if (dms.length != 4) { System.out.println("Incorrect DMS format in \"" + dmsStr +"\""); : Contest Algorithms:16. Lat & Long

24 int degrees = parseInt(dms[0]); if (degrees < 0) { sign = -1;
int sign = 1; int degrees = parseInt(dms[0]); if (degrees < 0) { sign = -1; degrees *= -1; } int mins = parseInt(dms[1]); double secs = parseInt(dms[2]); char suffix = dms[3].toUpperCase().charAt(0); if (suffix == 'S' || suffix == 'W') sign *= -1; if (mins < 0 || mins >= 60) { System.out.println("Minutes out of range; using 0"); mins = 0; if (secs < 0 || secs >= 60) { System.out.println("Seconds out of range; using 0"); secs = 0; return ( sign*(Math.abs(degrees) + mins/60d + secs/3600d)); } // end of fromDMS() Contest Algorithms:16. Lat & Long

25 Usage > java LatLongTests Great circle distance: 7507.8
public static void main(String[] args) { // New York coordinates (from double nyLat = fromDMS(" N"); double nyLong = fromDMS(" W"); System.out.printf("New York lat,long: %.3f, %.3f\n", nyLat, nyLong); // , // Moscow coordinates double mLat = fromDMS(" N"); double mLong = fromDMS(" E"); System.out.printf("Moscow lat,long: %.3f, %.3f\n", mLat, + mLong); // , System.out.printf("Great circle distance: %.1f\n", haversine(nyLat, nyLong, mLat, mLong) ); : // more examples } Contest Algorithms:16. Lat & Long

26 Distance from NY to Moscow (2)
Coordinates: New York: Latitude = 40o47'N, Longitude = 73o58'W Moscow: Latitude = 55o45'N, Longitude = 37o42'E Calculation: diffLat = = diffLon = = h = sin²(diffLat/2) + cos(lat1) * cos(lat2) * sin²(diffLon/2); // in radians h = ( * * ) = = a = 2*6371*arcsin(√h) a = * = , which agrees with Google's result Contest Algorithms:16. Lat & Long

27 Navigational Terminology
Azimuth / bearing / true course: the angle a line makes with a meridian, taken clockwise from north North=0°, East=90°, South=180°, West=270° the A, B, C angles Geodesic: The smaller great circle arc through two given points the shortest distance between the two points the a, b, c "lines”

28 Bearing from NY to Moscow
Use the sine law: sin 𝐴 sin 𝑎 = sin 𝐵 sin 𝑏 = sin 𝐶 sin 𝑐 Bearing for New York (N) in terms of the polar data: sin 𝑁= sin 𝑃 sin 𝑝 ∙ sin 𝑛 N = sin-1( sin( ) / sin(67.51) * ) = sin-1(0.9293/ * ) = sin-1(0.5660) = 34.48o Contest Algorithms:16. Lat & Long

29 Confirmation using earthdirections.org
Contest Algorithms:16. Lat & Long

30 Code see LatLongTests.java public static double bearing(double lat1, double lon1, double lat2, double lon2) { double dLon = Math.toRadians(lon2 - lon1); lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double y = Math.sin(dLon) * Math.cos(lat2); double x = (Math.cos(lat1) * Math.sin(lat2)) - (Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon)); return (Math.toDegrees(Math.atan2(y, x))+360)%360; } // end of bearing() Contest Algorithms:16. Lat & Long

31 Usage // in main() System.out.printf("Bearing from NYC to Moscow: %.3f degrees\n", bearing(nyLat, nyLong, mLat, mLong) ); > java LatLongTests Great circle distance: Bearing from NYC to Moscow: degrees Contest Algorithms:16. Lat & Long

32 The Rhumb Line The two points are located on a Mercator map, and a straight line (the rhumb line) is drawn between them. Contest Algorithms:16. Lat & Long

33 Mercator vs. From Space Mercator map View from Space meridians
latitude lines This is the Great Circle Track that Charles Lindbergh flew Owl – Shortest distance between two points is a curve (great circle) View from Space

34 The Mercator Projection
Let the globe be a spherical balloon that is blown up inside a cylinder, and sticks to the cylinder when it comes into contact with it. unroll the cylinder to get the map Two properties: circles of latitude become horizontal lines on the map meridians become vertical lines Result: latitudes and longitude lines form a grid pattern Contest Algorithms:16. Lat & Long

35 Also called a loxodrome A constant course always make the same angle with the meridians (longitude line) that it passes through. constant course == a rhumb line on a Mercator map

36 Calculating Rhumb Line Info
Derive the equations to calculate the Rhumb line course C and its distance d between two points A and B. d can be calculated in terms of a sum of small distances dx between A and B: dLon * cos Lat lattitude lines divide d into lots of small triangles d dx dLat C C A meridians Contest Algorithms

37 dx is composed of a north-south component, dLat, and a west-east component, dLon ∙ cos Lat.
The factor (cos Lat) is the relative circumference of the respective parallel of latitude. Rearrange: Contest Algorithms:16. Lat & Long

38 Sum all the dx triangles by integrating the equations between (Lat A, Lat B) and (Lon A, Lon B):
1/cos θ = sec θ sec θ = ln( | sec θ + tan θ |) + K = tan(θ/2 + π/4) + K Contest Algorithms:16. Lat & Long

39 Integrate both sides: Rearrange: Contest Algorithms:16. Lat & Long

40 Solve for C, and use atan2(y,x) rather than arctan()
C = Math.atan2( , ) Contest Algorithms:16. Lat & Long

41 To find d, sum the dx lengths, by integrating the dx equation:
Result: 𝐷= 𝐿𝑎𝑡 𝐵 − 𝐿𝑎𝑡 𝐴 cos 𝐶 Contest Algorithms:16. Lat & Long

42 Rhumb Line from NY to Moscow
Coordinates: New York: Latitude = 40o47'N, Longitude = 73o58'W Moscow: Latitude = 55o45'N, Longitude = 37o42'E Calculation: diffLat = = o diffLon = = o = radians tan(LatMO/2 + π/4) = ; tan(LatNY/2 + π/4) = ln( / ) = C = atan2(1.949, ) = radians = 78.5o Contest Algorithms:16. Lat & Long

43 D = / cos(1.37) = / = NM distance == * 60 = NM km distance = * = km Contest Algorithms:16. Lat & Long

44 Online Rhumb Line Calculator
Contest Algorithms:16. Lat & Long

45 Code public static double rhumbDistance(double lat1d, double lon1d, double lat2d, double lon2d) // return distance in km { double lat1 = Math.toRadians(lat1d); double lon1 = Math.toRadians(lon1d); double lat2 = Math.toRadians(lat2d); double lon2 = Math.toRadians(lon2d); if ((Math.abs(lat1 - lat2) < EPS) && (Math.abs(lon1 - lon2) < EPS)){ System.out.println("Too points are the same"); return 0; } double dPhi = Math.log(Math.tan(lat2/2.0 + Math.PI/4.0) / Math.tan(lat1/2.0 + Math.PI/4.0)); double course = Math.atan2((lon2 - lon1), dPhi); System.out.printf("Rhumb line course (in degrees): %.4f\n", Math.toDegrees(course)); double distNM = ((lat2d - lat1d) / Math.cos(course) * 60); // in Nautical miles return (distNM * NAUTICAL_MILES_TO_KM); } // end of rhumbDistance() Contest Algorithms:16. Lat & Long

46 Usage // in main() System.out.printf("Rhumb line distance (in km): %.1f\n", rhumbDistance(nyLat, nyLong, mLat, mLong) ); Contest Algorithms:16. Lat & Long


Download ppt "16. Latitude and Longitude"

Similar presentations


Ads by Google