简体   繁体   English

街道和点之间的距离(如果是经度和纬度)

[英]Distance between street and point, if latitude and longitude

I have 3 latitudes and longitude: 我有3个纬度和经度:

x : 1.000000000 1.000000000 x:1.000000000 1.000000000

y : 2.000000000 2.000000000 y:2.000000000 2.000000000

z : 3.000000000 3.000000000 z:3.000000000 3.000000000

I need to calculate the smallest distance between Z and the line formed by X -> Y, PLEASE HELP 我需要计算Z与X-> Y形成的线之间的最小距离,请帮助

PHP code that solve my problem until now: 到目前为止解决我的问题的PHP代码:

function calc ($a, $ay, $b, $by,$c, $cy) {
    $a = array($a, $ay, 0);// i use 0 altitude always
    $b = array($b, $by, 0);
    $c = array($c, $cy, 0);
    $ab = array(
        (($a[1] * $b[2]) - ($b[1] * $a[2])),
        (($a[2] * $b[0]) - ($b[2] * $a[0])),
        (($a[0] * $b[1]) - ($b[0] * $a[1]))
    );
    $normal = pow(pow($ab[0],2)+pow($ab[1],2)+pow($ab[2],2),0.5);
    $d = array(
        ($ab[0]/$normal),
        ($ab[1]/$normal),
        ($ab[2]/$normal)
    );
    $e_ = (($d[0] * $c[0]) + ($d[1] * $c[1]) + ($d[2] * $c[2]));
    $e = acos($e_);
    $res = pi()/2 - $e;
    $res = $res * 6378.1;
    return $res;
}

we need to do some spherical geometry here. 我们需要在这里做一些球面几何。 If we were just working in the plane the question would be easy https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line things are trickier on a sphere. 如果我们只是在飞机上工作,这个问题将很容易https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line事情在一个领域上比较棘手。

First what do we mean by the line formed by X -> Y. We probably mean a great circle https://en.wikipedia.org/wiki/Great_circle for example the equator. 首先,我们用X-> Y形成的线表示什么。我们可能表示一个大圆圈https://en.wikipedia.org/wiki/Great_circle ,例如赤道。

Assume for a moment that the points X, Y were on the equator, then the distance between Z and the equator would be proportional to the latitude of Z. 假设片刻X,Y在赤道上,那么Z与赤道之间的距离将与Z的纬度成比例。

One way to solve the problem would be to rotate our points so that X and Y lie on the equator and then find the latitude of Z. A procedure for doing this is (set up axis so x-axis is out through 0,0, the y-axis is due east and the z-axis due north) 解决该问题的一种方法是旋转我们的点,使X和Y位于赤道上,然后找到Z的纬度。执行此操作的步骤是(设置轴,使x轴穿过0,0, y轴位于东方,z轴位于北方)

  1. Rotate around z-axis X -> X1, Y->Y1, Z->Z1 so the longitude of X1 is zero. 绕z轴X-> X1,Y-> Y1,Z-> Z1旋转,因此X1的经度为零。
  2. Rotate around y-axis X1 -> X2, Y1->Y2, Z1->Z2 so the latitude of X2 is zero. 绕y轴X1-> X2,Y1-> Y2,Z1-> Z2旋转,因此X2的纬度为零。
  3. Rotate around the z-axis X2->X3, Y2->Y3, Z2->Z3 so the latitude of Y3 is zero 绕z轴旋转X2-> X3,Y2-> Y3,Z2-> Z3,因此Y3的纬度为零

We now have both X3 and Y3 on the equator and can find the latitude of Z3. 现在,我们在赤道上同时拥有X3和Y3,并且可以找到Z3的纬度。 The actual distance will be radius-of-earth * latitude-of-Z3-in-radians 实际距离将为地球半径* Z3的纬度(弧度)

Curiously @abiessu comment is not actually correct the great circle through 1N 1E and 2N 2E does not quite run through 3N 3E. 奇怪的是,@ abiessu的评论实际上并不能纠正1N 1E和2N 2E穿越3N 3E的大圆圈。 I make the distance 14cm. 我使距离14厘米。


An easier way to calculate this is to find the cross product of X and Y, W=X ^ Y. This vector is the normal to the plane through X, Y and the center of the sphere. 一种更简单的计算方法是找到X和Y的叉积,W = X ^Y。此向量是通过X,Y和球体中心的法线。 Now find the dot product W . 现在找到点积W。 Z this is angle-between-W-and-Z * len(W) * len(Z). Z这是W和Z之间的角度* len(W)* len(Z)。 So divide the dot product by the two lengths to give a and find pi/2-a the angle of inclination of Z above the plane. 因此,将点乘积除以两个长度即可得出a并找到pi / 2-a,即Z在平面上方的倾斜角度。 Multiply this by the radius to get the distance. 将此乘以半径即可得出距离。


Taking the example of points at 1N 1E take points on the unit sphere 以1N 1E处的点为例,在单位球面上取点

a 1.0N 1.0E (0.999695, 0.017450, 0.017452 ) 一个1.0N 1.0E(0.999695,0.017450,0.017452)

b 2.0N 2.0E (0.998782, 0.034878, 0.034899 ) b 2.0N 2.0E(0.998782,0.034878,0.034899)

c 3.0N 3.0E (0.997261, 0.052264, 0.052336 ) c 3.0N 3.0E(0.997261,0.052264,0.052336)

a^b (0.000000, -0.017458, 0.017439 ) a ^ b(0.000000,-0.017458,0.017439)

d=unit(a^b) (0.000011 , -0.707484, 0.706730 ) d =单位(a ^ b)(0.000011,-0.707484,0.706730)

d . d。 c 0.000022543731833669922 c 0.000022543731833669922

e = acos(d . c) = 1.570773783063061 in radians e = acos(d c)= 1.570773783063061以弧度为单位

pi/2 - e = 0.000022543731835522607 pi / 2-e = 0.000022543731835522607

0.14378617602014673km distance on earth with radius 6378.1km 0.14378617602014673km半径为6378.1km的地球距离

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于查找使用纬度和经度之间的距离的Sql返回错误的距离 - Sql for finding the distance between using latitude and longitude returns wrong distance Laravel中两个位置之间的距离在数据库查询中使用经纬度 - Distance between two locations in Laravel using latitude and longitude in database query 如何在两对纬度经度之间以几米为单位获得距离 - How to get distance in few meters between 2 pair of latitude longitude 如何使用php使用经度和纬度获取点之间的距离? - how to get distance between points using latitude and longitude using php? 从给定距离的第一个点找到另一个点的经度和纬度。 - Find Longitude & Latitude of another point from first point with given distance. 给出初始纬度,距离和方位的PHP中的纬度经度点 - FInd latitude longitude point in php given initial lat lng, distance, and bearing 如何使用经度和纬度计算餐厅与该餐厅附近的 10 个司机之间的距离? - How to calculate the distance between a restaurant and 10 drivers who are nearby to that restaurant restaurant using longitude and latitude? 比较矩形区域中的纬度和经度(无距离) - Compare latitude and longitude in a rectangle area (no distance) 纬度/经度矢量到距离,输出有奇怪的问题 - Latitude/longitude vector to distance, strange problem with output 经度和纬度的距​​离计算有不同的结果 - Distance calculation with longitude and latitude has different results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM