From 89942aaecd6c78ba0468496d853b0a49b164137f Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 23 六月 2023 13:51:04 +0800 Subject: [PATCH] 添加根据距离和角度获取目标点方法 --- src/main/java/com/yssh/utils/CalculateUtils.java | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/yssh/utils/CalculateUtils.java b/src/main/java/com/yssh/utils/CalculateUtils.java index 6dcea2a..614773a 100644 --- a/src/main/java/com/yssh/utils/CalculateUtils.java +++ b/src/main/java/com/yssh/utils/CalculateUtils.java @@ -1,5 +1,6 @@ package com.yssh.utils; +import java.awt.geom.Point2D; import java.text.SimpleDateFormat; import java.util.*; @@ -268,13 +269,39 @@ */ public static List<Coordinate> calcRect(double x, double y) { double buffer = 10; + double dis = round6(Math.sqrt(Math.pow(buffer / 2, 2) * 2)); + List<Coordinate> list = new ArrayList<>(); - // + list.add(getPointByDisAndAngle(x, y, 315, dis)); + list.add(getPointByDisAndAngle(x, y, 45, dis)); + list.add(getPointByDisAndAngle(x, y, 135, dis)); + list.add(getPointByDisAndAngle(x, y, 225, dis)); return list; } /** + * 鏍规嵁璺濈鍜岃搴﹁幏鍙栫洰鏍囩偣 + */ + private static Coordinate getPointByDisAndAngle(double x, double y, double angle, double dis) { + try { + DirectPosition2D p1 = new DirectPosition2D(x, y); + + GeodeticCalculator gc = new GeodeticCalculator(); + gc.setStartingGeographicPoint(p1); + gc.setDirection(angle, dis); + + Point2D dest = gc.getDestinationGeographicPoint(); + double newX = round6(dest.getX()); + double newY = round6(dest.getY()); + + return new Coordinate(newX, newY); + } catch (Exception ex) { + return new Coordinate(); + } + } + + /** * @param @return 鍙傛暟 * @return Double 杩斿洖绫诲瀷 * @throws -- Gitblit v1.9.3