如何获得围绕中心坐标和半径的N个坐标 [英] How to get N number of coordinates around center coordinate and radius
问题描述
我有一个中心坐标和一个距离/半径,我需要使用半径从中心获取N个坐标,例如,如何在下图中获取12个红点坐标.
I got a center coordinate and a distance/radius, I need to get N number of coordinates from center using radius, for example how to get 12 coordinates of red dots in following image.
推荐答案
,您可以使用好-circle_distance 计算以获取积分.
you can use the Great-circle_distance calculation to get the points.
我首先从所需的中心点计算轴承,然后foreach循环将它们传递给函数.
I first calculate the bearings from the center point needed then foreach loop them and pass them to the function.
function destinationPoint($lat, $lng, $brng, $dist) {
$rad = 6371; // earths mean radius
$dist = $dist/$rad; // convert dist to angular distance in radians
$brng = deg2rad($brng); // conver to radians
$lat1 = deg2rad($lat);
$lon1 = deg2rad($lng);
$lat2 = asin(sin($lat1)*cos($dist) + cos($lat1)*sin($dist)*cos($brng) );
$lon2 = $lon1 + atan2(sin($brng)*sin($dist)*cos($lat1),cos($dist)-sin($lat1)*sin($lat2));
$lon2 = fmod($lon2 + 3*M_PI, 2*M_PI) - M_PI; // normalise to -180..+180º
$lat2 = rad2deg($lat2);
$lon2 = rad2deg($lon2);
echo "lat = ".$lat2."\n";
echo "lon = ".$lon2."\n\n";
}
$lat = 0;
$lng = 0;
$dist = 1; // km
$n = 12;
$bearings = range(0, 360-(360/$n) , 360/$n); // create array of all bearings needed from $lat/$lng
foreach($bearings as $brng){
echo $brng ."\n";
destinationPoint($lat, $lng, $brng, $dist);
}
在理论中,根据您需要的精度,只需要使用函数计算一半的值,然后就可以使用基本计算来计算另一半.
但是,如果距离很大(不知道确切的意思是大距离),可能会有所不同.
In theroy and depending on how accurate you need it to be, you only need to calculate half the values using the function and then you should be able to calculate the other half with basic calculation.
But if the distance is large (don't know exactly what large means) it may make a difference.
这篇关于如何获得围绕中心坐标和半径的N个坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!