From cf4a07510de9b954c3f7393d54206eece7d6ad4a Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 08 一月 2025 17:30:10 +0800
Subject: [PATCH] 1. 新增卫星遥测正方形网格顶点计算逻辑

---
 src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt |   66 +++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt
index f45b316..55564d9 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt
@@ -1,6 +1,7 @@
 package com.flightfeather.uav.common.utils
 
 import kotlin.math.PI
+import kotlin.math.asin
 import kotlin.math.cos
 import kotlin.math.sin
 
@@ -24,4 +25,69 @@
         val lat = (dy / ec + pos.second * PI / 180.0) * 180.0 / PI
         return Pair(lng, lat)
     }
+
+    /**
+     * 鑾峰彇涓や釜缁忕含搴︿箣闂寸殑瑙掑害锛�0搴�-360搴︼級
+     */
+    fun getAngle(lngA: Double, latA: Double, lngB: Double, latB: Double): Double {
+        val a = ((90 - latB) * Math.PI) / 180;
+        val b = ((90 - latA) * Math.PI) / 180;
+        val AOC_BOC = ((lngB - lngA) * Math.PI) / 180;
+        val cosc = cos(a) * Math.cos(b) + Math.sin(a) * Math.sin(b) * Math.cos(AOC_BOC);
+        val sinc = Math.sqrt(1 - cosc * cosc);
+        val sinA = (Math.sin(a) * Math.sin(AOC_BOC)) / sinc;
+        val A = (Math.asin(sinA) * 180) / Math.PI;
+        var res = 0.0;
+        if (lngB > lngA && latB > latA) res = A;
+        else if (lngB > lngA && latB < latA) res = 180 - A;
+        else if (lngB < lngA && latB < latA) res = 180 - A;
+        else if (lngB < lngA && latB > latA) res = 360 + A;
+        else if (lngB > lngA && latB == latA) res = 90.0;
+        else if (lngB < lngA && latB == latA) res = 270.0;
+        else if (lngB == lngA && latB > latA) res = 0.0;
+        else if (lngB == lngA && latB < latA) res = 180.0;
+        return res;
+    }
+
+    /**
+     * 鑾峰彇涓ょ粡绾害闂寸殑璺濈
+     */
+    fun getDistance(lng1: Double, lat1: Double, lng2: Double, lat2: Double): Double {
+//        lat1 = lat1 || 0;
+//        lng1 = lng1 || 0;
+//        lat2 = lat2 || 0;
+//        lng2 = lng2 || 0;
+
+        val rad1 = (lat1 * Math.PI) / 180.0;
+        val rad2 = (lat2 * Math.PI) / 180.0;
+        val a = rad1 - rad2;
+        val b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
+        val distance =
+            Ea * 2 * asin(
+                Math.sqrt(
+                    Math.pow(
+                        Math.sin(a / 2),
+                        2.0
+                    ) + Math.cos(rad1) * Math.cos(rad2) * Math.pow(Math.sin(b / 2), 2.0)
+                )
+            );
+
+        return distance;
+    }
+
+    /**
+     * 瑙掑害澧炲噺锛岀‘淇濊搴﹀浜�0 - 360搴︿箣闂�
+     * @param angle 鍘熻搴�
+     * @param offset 鍋忕Щ閲�
+     */
+    fun plusAngle(angle: Double, offset: Double): Double {
+        val result = angle + offset;
+        return if (result > 360) {
+            result - 360;
+        } else if (result < 0) {
+            result + 360;
+        } else {
+            result;
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3