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/biz/satellite/SatelliteGridManage.kt |   65 +++++++++++++++++++++
 src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt              |   66 ++++++++++++++++++++++
 2 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
new file mode 100644
index 0000000..3d37e30
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
@@ -0,0 +1,65 @@
+package com.flightfeather.uav.biz.satellite
+
+import com.flightfeather.uav.common.utils.MapUtil
+import kotlin.math.sqrt
+
+/**
+ * 鍗槦閬ユ祴缃戞牸绠$悊
+ * 鏍规嵁缃戞牸涓績鐐硅绠�4涓《鐐瑰潗鏍�
+ * 鏍规嵁宸叉湁缃戞牸杩涜缁嗗垎缃戞牸璁$畻
+ * @date 2025/1/8
+ * @author feiyu02
+ */
+class SatelliteGridManage {
+
+    /**
+     * 鏍规嵁姝f柟褰㈢綉鏍间腑蹇冪偣鍧愭爣锛岃绠�4涓《鐐瑰潗鏍�
+     */
+    fun calGridVertex(points:List<Pair<Double, Double>>):List<Array<Pair<Double, Double>>> {
+        if (points.size < 2) return emptyList()
+        val p1 = points[0];
+        val p2 = points[1];
+        // 涓や腑蹇冪偣闂寸殑瑙掑害
+        val angle = MapUtil.getAngle(p1.first, p1.second, p2.first, p2.second);
+        // 涓や腑蹇冪偣闂寸殑璺濈
+        val dis = MapUtil.getDistance(p1.first, p1.second, p2.first, p2.second);
+        // 缃戞牸姝f柟褰㈠瑙掔嚎鐨勪竴鍗婇暱搴�
+        val halfDiagonal = sqrt((dis / 2) * (dis / 2) * 2);
+        // 璁$畻棣栦釜姝f柟褰㈠悇椤剁偣鐩稿浜庝腑蹇冪偣鐨勮搴︼紝寰楀埌姝f柟褰㈠悇椤剁偣鐨勫潗鏍�
+        val angle1 = MapUtil.plusAngle(angle, 45.0);
+        val gp1 = MapUtil.getPointByLen(p1, halfDiagonal, angle1);
+        val angle2 = MapUtil.plusAngle(angle1, 90.0);
+        val gp2 = MapUtil.getPointByLen(p1, halfDiagonal, angle2);
+        val angle3 = MapUtil.plusAngle(angle2, 90.0);
+        val gp3 = MapUtil.getPointByLen(p1, halfDiagonal, angle3);
+        val angle4 = MapUtil.plusAngle(angle3, 90.0);
+        val gp4 = MapUtil.getPointByLen(p1, halfDiagonal, angle4);
+        // 璁$畻4涓《鐐瑰垎鍒笌涓績鐐圭殑缁忕含搴﹀樊鍊�
+        val dx1 = gp1.first - p1.first
+        val dy1 = gp1.second - p1.second
+        val dx2 = gp2.first - p1.first
+        val dy2 = gp2.second - p1.second
+        val dx3 = gp3.first - p1.first
+        val dy3 = gp3.second - p1.second
+        val dx4 = gp4.first - p1.first
+        val dy4 = gp4.second - p1.second
+
+        // 寰楀埌鎵�鏈夋鏂瑰舰缃戞牸鐨�4涓《鐐逛俊鎭�
+        return points.map { p->
+            arrayOf(
+                p.first + dx1 to p.second + dy1,
+                p.first + dx2 to p.second + dy2,
+                p.first + dx3 to p.second + dy3,
+                p.first + dx4 to p.second + dy4,
+            )
+        }
+    }
+
+    /**
+     * 鎷嗗垎缃戞牸
+     */
+    fun splitGrid() {
+
+    }
+
+}
\ No newline at end of file
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