JAVA已知圆心经纬度和半径求圆周点的经纬度

JAVA已知圆心经纬度和半径求圆周点的经纬度

项目中遇到一个需求,需要根据传入的圆心经纬度和半径参数获得圆周点的经纬度,在网上查询了很多没有找到能用的算法,从GPT中获取到了一个简洁的用java实现的算法,在此记录一下,供大家参考。已亲自在gis球上验证计算结果正确无误。

/**
     * 根据圆心经纬度和半径求圆周点的经纬度
     * @param lat         纬度(单位:度)
     * @param lon         经度(单位:度)
     * @param radius      半径(单位:千米)
     * @param numPoints   点的个数
     * @return
     */
    public static List<Point> calculatePoints(double lat, double lon, double radius, int numPoints) {
        double d = radius / 6371.0; // convert radius from meters to radians
        List<Point> points = new ArrayList<>();
        for (int i = 0; i < numPoints; i++) {
            double brng = 2 * Math.PI * i / numPoints;
            double latRad = Math.asin(Math.sin(Math.toRadians(lat)) * Math.cos(d) + Math.cos(Math.toRadians(lat)) * Math.sin(d) * Math.cos(brng));
            double lonRad = Math.toRadians(lon) + Math.atan2(Math.sin(brng) * Math.sin(d) * Math.cos(Math.toRadians(lat)), Math.cos(d) - Math.sin(Math.toRadians(lat)) * Math.sin(latRad));
            Point point = new Point(Math.toDegrees(lonRad), Math.toDegrees(latRad));
            points.add(point);
        }
        return points;
    }
    /**
     * 点
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Point {
        /**
         * 经度
         */
        private double longitude;
        /**
         * 纬度
         */
        private double latitude;
    }

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值