dongteng0748 2018-05-02 11:46
浏览 108
已采纳

如何获得围绕中心坐标和半径的N个坐标

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.

enter image description here

  • 写回答

2条回答 默认 最新

  • dongmimeng5500 2018-05-02 12:41
    关注

    you can use the Great-circle_distance calculation to get the points.

    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."
    ";
        echo "lon = ".$lon2."
    
    ";
    }
    
    $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 ."
    ";
        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.

    https://3v4l.org/4fI7F

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起