Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to mimi and this great article <a href="http://www.movable-type.co.uk/scripts/latlong.html" rel="nofollow noreferrer">http://www.movable-type.co.uk/scripts/latlong.html</a> but they don't give the whole picture. Here is a detail one. All this points are collected using Google Earth using Placemark to mark the locations. Make sure lat/long are set to decimal degrees in Preferences.</p> <pre><code>lat A = 3.222895 lon A = 101.719751 lat B = 3.222895 lon B = 101.719751 lat C = 3.224972 lon C = 101.722932 Earth radius, R = 6371 </code></pre> <p><strong>1. First you have to find the bearing from A to C and A to B.</strong><br> Bearing formula </p> <pre><code>bearingAC = atan2( sin(Δλ)*cos(φ₂), cos(φ₁)*sin(φ₂) − sin(φ₁)*cos(φ₂)*cos(Δλ) ) bearingAB = atan2( sin(Δλ)*cos(φ₂), cos(φ₁)*sin(φ₂) − sin(φ₁)*cos(φ₂)*cos(Δλ) ) </code></pre> <p>φ is latitude, λ is longitude, R is earth radius</p> <p><strong>2. Find A to C distance using spherical law of cosines</strong> </p> <pre><code>distanceAC = acos( sin(φ₁)*sin(φ₂) + cos(φ₁)*cos(φ₂)*cos(Δλ) )*R </code></pre> <p><strong>3. Find cross-track distance</strong> </p> <pre><code>distance = asin(sin(distanceAC/ R) * sin(bearingAC − bearing AB)) * R </code></pre> <p><strong>Objective-C code</strong> </p> <pre><code>double lat1 = 3.227511; double lon1 = 101.724318; double lat2 = 3.222895; double lon2 = 101.719751; double lat3 = 3.224972; double lon3 = 101.722932; double y = sin(lon3 - lon1) * cos(lat3); double x = cos(lat1) * sin(lat3) - sin(lat1) * cos(lat3) * cos(lat3 - lat1); double bearing1 = radiansToDegrees(atan2(y, x)); bearing1 = 360 - ((bearing1 + 360) % 360); double y2 = sin(lon2 - lon1) * cos(lat2); double x2 = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lat2 - lat1); double bearing2 = radiansToDegrees(atan2(y2, x2)); bearing2 = 360 - ((bearing2 + 360) % 360); double lat1Rads = degreesToRadians(lat1); double lat3Rads = degreesToRadians(lat3); double dLon = degreesToRadians(lon3 - lon1); double distanceAC = acos(sin(lat1Rads) * sin(lat3Rads)+cos(lat1Rads)*cos(lat3Rads)*cos(dLon)) * 6371; double min_distance = fabs(asin(sin(distanceAC/6371)*sin(degreesToRadians(bearing1)-degreesToRadians(bearing2))) * 6371); NSLog(@"bearing 1: %g", bearing1); NSLog(@"bearing 2: %g", bearing2); NSLog(@"distance AC: %g", distanceAC); NSLog(@"min distance: %g", min_distance); </code></pre> <p>Actually there's a library for this. You can find it here <a href="https://github.com/100grams/CoreLocationUtils" rel="nofollow noreferrer">https://github.com/100grams/CoreLocationUtils</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload