1 回答

TA貢獻(xiàn)1848條經(jīng)驗 獲得超6個贊
鑒于您正在沿著一條直線處理 2 個點(diǎn),我認(rèn)為處理此問題的最簡單方法是從 2D 角度查看它,其中 x 軸表示您的樣本編號,y 軸表示你的高度。
然后我們假設(shè)如果結(jié)果 n 處的高程高于直線,則視線中斷。
在哪里:
(x1, y1) = (1, 4411.94)
(x2, y2) = (10, -84.51)
這是繪制出的結(jié)果的圖片以及在其上繪制的從一點(diǎn)到另一點(diǎn)的線:
我們可以看到樣本 8 和 9 的視線被打破了。
下面是查找相同內(nèi)容的代碼。它使用直線的基本方程: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 角度看這個問題所帶來的復(fù)雜性。盡管在地球曲率發(fā)揮作用的情況下,這有其缺點(diǎn)。這也應(yīng)該可以根據(jù)需要擴(kuò)展到盡可能多的樣本。
- 1 回答
- 0 關(guān)注
- 153 瀏覽
添加回答
舉報