java计算一个多边形的重心_java代码获取多边形的中心点

packagecom.skjd.util;importjava.util.ArrayList;importjava.util.List;/*** 坐标以及电子围栏相关的工具类

*@authorzhangyao

**/

public classPointUtil {public static voidmain(String[] args) {

String str="114.316587,30.671626#114.325921,30.683437#114.342122,30.689342#114.359009,30.695246#114.377066,30.692884#114.393304,30.678417#114.412289,30.650953#114.426107,30.625253#114.433703,30.595853#114.444368,30.560458#114.466705,30.527415#114.457264,30.517327#114.454002,30.503097#114.458465,30.474631#114.430828,30.466313#114.397697,30.460362#114.343281,30.456778#114.305086,30.457354#114.269101,30.468743#114.23449,30.489598#114.182713,30.522872#114.17296,30.535364#114.167328,30.55022#114.165783,30.575754#114.167155,30.591715#114.161492,30.606935#114.160461,30.619049#114.170589,30.627469#114.206123,30.623481#114.233932,30.629832#114.184837,30.704361#114.187927,30.776472#114.233589,30.780122#114.238567,30.717035#114.248609,30.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
计算地图上两个多边形的距离可以使用以下步骤: 1. 将多边形的顶点坐标转换为经纬度坐标。 2. 根据经纬度坐标计算两个多边形之间的距离。 以下是Java代码示例: ``` public class PolygonDistanceCalculator { private static final double EARTH_RADIUS = 6371000; // 地球半径 /** * 计算两个多边形之间的距离 * @param polygon1 多边形1的顶点坐标列表 * @param polygon2 多边形2的顶点坐标列表 * @return 两个多边形之间的距离(单位:米) */ public static double calculateDistance(List<Point> polygon1, List<Point> polygon2) { double minDistance = Double.MAX_VALUE; for (Point p1 : polygon1) { for (Point p2 : polygon2) { double distance = calculateDistance(p1, p2); if (distance < minDistance) { minDistance = distance; } } } return minDistance; } /** * 计算两个点之间的距离 * @param p1 点1的坐标 * @param p2 点2的坐标 * @return 两个点之间的距离(单位:米) */ private static double calculateDistance(Point p1, Point p2) { double lat1 = Math.toRadians(p1.getLatitude()); double lat2 = Math.toRadians(p2.getLatitude()); double lon1 = Math.toRadians(p1.getLongitude()); double lon2 = Math.toRadians(p2.getLongitude()); double deltaLat = lat2 - lat1; double deltaLon = lon2 - lon1; double a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return EARTH_RADIUS * c; } } class Point { private double longitude; // 经度 private double latitude; // 纬度 public Point(double longitude, double latitude) { this.longitude = longitude; this.latitude = latitude; } public double getLongitude() { return longitude; } public double getLatitude() { return latitude; } } ``` 在上述代码中,`calculateDistance`方法用于计算两个点之间的距离,使用了Haversine公式。`calculateDistance`方法调用了`calculateDistance`方法来计算两个多边形之间的最小距离。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值