From f0abc5b4a6efc5aa3493a50817d3bc1aa2347322 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 12 二月 2025 17:03:00 +0800
Subject: [PATCH] 1. 新增坐标点是否在多边形内部的判定算法

---
 src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt |    7 +++
 src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt              |   86 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 1 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
index 1bfc3e9..6d0ca31 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
@@ -223,6 +223,11 @@
      * @param gridCellList 寰呰瀺鍚堢殑鍗槦缃戞牸
      */
     fun dataFusion(realTimeDataList:List<BaseRealTimeData>, gridData: GridData, gridCellList: List<GridCell?>) {
-
+        // 閬嶅巻璧拌埅鐩戞祴鏁版嵁锛岃绠楁瘡涓偣鎵�鍦ㄧ綉鏍�,骞跺舰鎴愮綉鏍煎��
+        realTimeDataList.forEach {
+            it.longitude
+            it.latitude
+            gridCellList.forEach {  }
+        }
     }
 }
\ 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 55564d9..e3e9917 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt
@@ -90,4 +90,90 @@
             result;
         }
     }
+
+    /**
+     * 鍒ゆ柇鍧愭爣鐐规槸鍚﹀湪澶氳竟褰㈢殑鍥涜嚦鑼冨洿鍐�
+     * @param point 鍧愭爣鐐�
+     * @param polygon 澶氳竟褰㈠潗鏍囩偣鏁扮粍
+     */
+    fun inBBox(point: Pair<Double, Double>, polygon: List<Pair<Double, Double>>): Boolean {
+
+        val x = point.first
+        val y = point.second
+        // 璁$畻澶氳竟褰㈤《鐐圭粡搴﹁寖鍥村拰绾害鑼冨洿
+        val xsSort = polygon.map { it.first }.sorted()
+        val ysSort = polygon.map { it.second }.sorted()
+
+        val xMin = xsSort[0]
+        val yMin = ysSort[0]
+        val xMax = xsSort[xsSort.lastIndex]
+        val yMax = ysSort[ysSort.lastIndex]
+
+        return x >= xMin && x <= xMax && y >= yMin && y <= yMax
+    }
+
+    /**
+     * 鍒ゆ柇鍧愭爣鐐规槸鍚﹀湪澶氳竟褰㈢殑杈逛笂
+     * @param point 鍧愭爣鐐�
+     * @param polygon 澶氳竟褰㈠潗鏍囩偣鏁扮粍
+     */
+    fun onBorder(point: Pair<Double, Double>, polygon: List<Pair<Double, Double>>): Boolean {
+        var res = false
+        // 寰幆鍒ゆ柇姣忎竴鏉¤竟
+        for (i in polygon.indices) {
+            val p1 = polygon[i]
+            val p2 = if (i + 1 == polygon.size) {
+                polygon[0]
+            } else {
+                polygon[i + 1]
+            }
+            // 璁$畻杈圭殑涓や釜椤剁偣绾害宸拰缁忓害宸殑姣斿��
+            val k1 = (p2.second - p1.second) / (p2.first - p1.first)
+            // 璁$畻鍧愭爣鐐瑰拰鍏朵腑涓�涓《鐐圭殑绾害宸拰缁忓害宸殑姣斿��
+            val k2 = (p2.second - point.second) / (p2.first - point.first)
+            // 濡傛灉姣斿�肩浉鍚岋紝璇存槑涓変釜鐐瑰湪鍚屼竴鐩寸嚎涓婏紝鍗冲潗鏍囩偣鍦ㄨ竟涓�
+            if (k1 == k2) {
+                res = true
+                break
+            }
+        }
+        return res
+    }
+
+    /**
+     * 鍒ゆ柇鍧愭爣鐐规槸鍚﹀湪澶氳竟褰㈠唴閮�(灏勭嚎娉�)
+     * @param point 鍧愭爣鐐�
+     * @param polygon 澶氳竟褰㈠潗鏍囩偣鏁扮粍
+     */
+    fun inPolygon(point: Pair<Double, Double>, polygon: List<Pair<Double, Double>>):Boolean {
+        val x = point.first
+        val y = point.second
+        var j = polygon.size - 1
+        var odd = false
+        for (i in polygon.indices) {
+            if (
+                ((polygon[i].second > y) != (polygon[j].second > y))
+                && (x < ((polygon[j].first - polygon[i].first) * (y - polygon[i].second)
+                        / (polygon[j].second - polygon[i].second) + polygon[i].first))
+            ) {
+                odd = !odd;
+            }
+            j = i;
+        }
+        return odd
+    }
+
+    /**
+     * 鍒ゆ柇鍧愭爣鐐规槸鍚﹀湪澶氳竟褰㈠唴閮�
+     */
+    fun isPointInPolygon(point: Pair<Double, Double>, polygon: List<Pair<Double, Double>>): Boolean {
+        if (polygon.size < 4) throw IllegalArgumentException("not a polygon")
+
+        // 涓嶅湪鍥涜嚦鑼冨洿鍐咃紝鍒欎竴瀹氫笉鍦ㄥ杈瑰舰鍐�
+        if (!inBBox(point, polygon)) return false
+        // 鍦ㄥ杈瑰舰杈逛笂锛屼篃璁や负鍦ㄥ杈瑰舰鍐�
+        if (onBorder(point, polygon)) return true
+        // 璁$畻鏄惁鍦ㄥ杈瑰舰鍐呴儴
+        return inPolygon(point, polygon)
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3