是否有数学计算来定义通过 google 的高程 API 在点 A 和点 B 之间是否存在可见性?

Is there a mathematical calculation to define if there is visibility between a point A and a point B via google's Elevation API?

有没有办法通过 google API 获取海拔剖面数据来检查两点之间是否存在视线?

例如我可以通过此 link 获取海拔剖面图:https://maps.googleapis.com/maps/api/elevation/json?path=36.578581,-118.291994|36.23998,-116.83171&samples=10&key=YOUR_API_KEY

结果是 json,其中 10 个点位于两点之间,其地面高程,例如:

    {
   "results" : [
      {
         "elevation" : 4411.94189453125,
         "location" : {
            "lat" : 36.578581,
            "lng" : -118.291994
         },
         "resolution" : 19.08790397644043
      },
      {
         "elevation" : 1658.561645507812,
         "location" : {
            "lat" : 36.54183904164596,
            "lng" : -118.1291141726249
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : 1085.295776367188,
         "location" : {
            "lat" : 36.50487579522382,
            "lng" : -117.966389550823
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : 1491.4912109375,
         "location" : {
            "lat" : 36.46769177008888,
            "lng" : -117.8038207060907
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : 1583.762817382812,
         "location" : {
            "lat" : 36.43028747728768,
            "lng" : -117.6414082023003
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : 488.8834228515625,
         "location" : {
            "lat" : 36.39266342953181,
            "lng" : -117.4791525957044
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : 933.0382080078125,
         "location" : {
            "lat" : 36.35482014117158,
            "lng" : -117.3170544349424
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : 1657.123779296875,
         "location" : {
            "lat" : 36.31675812816988,
            "lng" : -117.1551142610472
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : 1074.835205078125,
         "location" : {
            "lat" : 36.27847790807609,
            "lng" : -116.9933326074523
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : -84.51690673828125,
         "location" : {
            "lat" : 36.23998,
            "lng" : -116.83171
         },
         "resolution" : 9.543951988220215
      }
   ],
   "status" : "OK"
}

有没有数学公式可以看出A点和B点是否可见?

我需要在PHP中编写代码。

谢谢大家。

鉴于您正在沿直线处理 2 个点,我认为处理此问题的最简单方法是从 2D 的角度来看,其中 x 轴表示您的样本编号, y 轴是指您的海拔高度。

然后我们假设如果结果n处的高程比直线高那么视线就断了。

其中:

(x1, y1) = (1, 4411.94)

(x2, y2) = (10, -84.51)

这是绘制出的结果的图片以及在其上绘制的从一点到另一点的线:

我们可以看到样本 8 和 9 的视线被破坏了。

下面是查找相同内容的代码。它使用直线的基本方程:y = mx + c

$results_json  = json_decode('{"results":[{"elevation":4411.94189453125,"location":{"lat":36.578581,"lng":-118.291994},"resolution":19.08790397644043},{"elevation":1658.561645507812,"location":{"lat":36.54183904164596,"lng":-118.1291141726249},"resolution":9.543951988220215},{"elevation":1085.295776367188,"location":{"lat":36.50487579522382,"lng":-117.966389550823},"resolution":9.543951988220215},{"elevation":1491.4912109375,"location":{"lat":36.46769177008888,"lng":-117.8038207060907},"resolution":9.543951988220215},{"elevation":1583.762817382812,"location":{"lat":36.43028747728768,"lng":-117.6414082023003},"resolution":9.543951988220215},{"elevation":488.8834228515625,"location":{"lat":36.39266342953181,"lng":-117.4791525957044},"resolution":9.543951988220215},{"elevation":933.0382080078125,"location":{"lat":36.35482014117158,"lng":-117.3170544349424},"resolution":9.543951988220215},{"elevation":1657.123779296875,"location":{"lat":36.31675812816988,"lng":-117.1551142610472},"resolution":9.543951988220215},{"elevation":1074.835205078125,"location":{"lat":36.27847790807609,"lng``":-116.9933326074523},"resolution":9.543951988220215},{"elevation":-84.51690673828125,"location":{"lat":36.23998,"lng":-116.83171},"resolution":9.543951988220215}],"status":"OK"}');

$x1 = 0;
$x2 = count($results_json->results);

$y1 = $results_json->results[0]->elevation;
$y2 = $results_json->results[$x2 - 1]->elevation; // last result in results array

$m = ($y2 - $y1) / ($x2 - $x1); // slope of the line
$c = $y2 - ($m * $x2);

$i = 0;
foreach ($results_json->results as $result){
    $elevation_of_straight_line = ($m * $i) + $c;
    $elevation_of_result = $result->elevation;
    if ($elevation_of_result > $elevation_of_straight_line){
        echo 'line of sight broken';
        echo 'Elevation of sample index '.$i.' = '.$elevation_of_result;
        echo 'Elevation of line of sight = '.$elevation_of_straight_line;
    }
    $i++;
}

这消除了从 3D 角度看这个问题所带来的复杂性。尽管在地球曲率发挥作用的情况下,这有其缺点。 这也应该可以根据需要扩展到尽可能多的样本。