纬度,经度之间的点与线之间的最小距离 [英] Minimum distance between a point and a line in latitude, longitude

查看:231
本文介绍了纬度,经度之间的点与线之间的最小距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两行经纬线

A:3.222895,101.719751

B:3.227511,101.724318



和1点

C:3.224972,101.722932



如何计算C点和一行之间的最小距离,由A点和B'
如果您还可以提供计算和目标代码,这将是方便的。距离约为89米(使用Google地球中的标尺)。

解决方案

感谢mimi和这篇伟大的文章 http://www.movable-type.co.uk/scripts/latlong.html 但他们并没有给出整体情况。这是一个细节。使用Google地球使用地标收集所有这些积分,以标记位置。确保在偏好设置中lat / long设置为十进制度。

  lat A = 3.222895 
lon A = 101.719751
lat B = 3.222895
lon B = 101.719751
lat C = 3.224972
lon C = 101.722932
地球半径,R = 6371

1。首先,您必须找到从A到C和A到B的方位。

轴承公式

  bearingAC = atan2(sin(Δλ)* cos(φ2),cos(φ1)* sin(φ2)-sin(φ1)* cos(φ2)* cos(Δλ))
bearingAB = atan2 sin(φλ)* cos(φ2),cos(φ1)* sin(φ2)-sin(φ1)* cos(φ2)* cos(Δλ))
$ p>

φ是纬度,λ是经度,R是地球半径



2。使用球面定律求出A到C距离

  distanceAC = acos(sin(φ1)* sin(φ2 )+ cos(φ1)* cos(φ2)* cos(Δλ))* R 

3。查找跨轨距离

  distance = asin(sin(distanceAC / R)* sin(bearingAC-bearing AB ))* R 

Objective-C代码

  double lat1 = 3.227511; 
双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 - (轴承2 + 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);

其实有一个图书馆。您可以在这里找到 https://github.com/100grams/CoreLocationUtils


I have a line with two points in latitude and longitude
A: 3.222895, 101.719751
B: 3.227511, 101.724318

and 1 point
C: 3.224972, 101.722932

How can I calculate minimum distance between point C and a line consists of point A and B? It will be convenient if you can provide the calculation and objective-c code too. The distance is around 89 meters (using ruler in Google Earth).

解决方案

Thanks to mimi and this great article http://www.movable-type.co.uk/scripts/latlong.html 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.

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

1. First you have to find the bearing from A to C and A to B.
Bearing formula

bearingAC = atan2( sin(Δλ)*cos(φ₂), cos(φ₁)*sin(φ₂) − sin(φ₁)*cos(φ₂)*cos(Δλ) )  
bearingAB = atan2( sin(Δλ)*cos(φ₂), cos(φ₁)*sin(φ₂) − sin(φ₁)*cos(φ₂)*cos(Δλ) ) 

φ is latitude, λ is longitude, R is earth radius

2. Find A to C distance using spherical law of cosines

distanceAC = acos( sin(φ₁)*sin(φ₂) + cos(φ₁)*cos(φ₂)*cos(Δλ) )*R

3. Find cross-track distance

distance = asin(sin(distanceAC/ R) * sin(bearingAC − bearing AB)) * R

Objective-C 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);

Actually there's a library for this. You can find it here https://github.com/100grams/CoreLocationUtils

这篇关于纬度,经度之间的点与线之间的最小距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆