From c9bbee8bb47d6f383f9699b59c046ddc0cb464e9 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 03 七月 2024 17:49:49 +0800
Subject: [PATCH] 1. 新增走航报告自动道路识别模块

---
 src/main/kotlin/com/flightfeather/uav/common/location/CoordinateUtil.kt |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/common/location/CoordinateUtil.kt b/src/main/kotlin/com/flightfeather/uav/common/location/CoordinateUtil.kt
index 227c76e..185c2f1 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/location/CoordinateUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/location/CoordinateUtil.kt
@@ -1,13 +1,12 @@
 package com.flightfeather.uav.common.location
 
-import kotlin.math.PI
-import kotlin.math.cos
-import kotlin.math.sin
+import kotlin.math.*
 
 object CoordinateUtil {
 
     private const val Ea = 6378137 //璧ら亾鍗婂緞
     private const val Eb = 6356725 //鏋佸崐寰�
+    private const val EARTH_RADIUS = 6371000 // 鍦扮悆鍗婂緞锛屽崟浣嶄负绫�
 
     /**
      * 鏍规嵁鍧愭爣鐐广�佽窛绂诲拰瑙掑害锛岃幏鍙栧彟涓�涓潗鏍�
@@ -26,6 +25,33 @@
     }
 
     /**
+     * 璁$畻鍧愭爣鐐筽2鐩稿浜巔1鐨勬柟浣嶈
+     * @return 瑙掑害
+     */
+    fun getAngle(lon1: Double, lat1: Double, lon2: Double, lat2: Double): Double {
+        val deg2rad = PI / 180
+        val dlat = (lat2 - lat1) * deg2rad
+        val dlon = (lon2 - lon1) * deg2rad
+        val y = sin(dlon) * cos(lat2 * deg2rad)
+        val x = cos(lat1 * deg2rad) * sin(lat2 * deg2rad) - sin(lat1 * deg2rad) * cos(lat2 * deg2rad) * cos(dlon)
+        val angel = atan2(y, x)
+        return (angel * 180 / PI + 360) % 360
+    }
+
+    /**
+     * 璁$畻鍧愭爣鐐逛箣闂磋窛绂�
+     */
+    fun calculateDistance(lon1: Double, lat1: Double, lon2: Double, lat2: Double): Double {
+        val dLat = Math.toRadians(lat2 - lat1)
+        val dLon = Math.toRadians(lon2 - lon1)
+        val a = (sin(dLat / 2) * sin(dLat / 2)
+                + (cos(Math.toRadians(lat1)) * cos(Math.toRadians(lat2))
+                * sin(dLon / 2) * sin(dLon / 2)))
+        val c = 2 * atan2(sqrt(a), sqrt(1 - a))
+        return EARTH_RADIUS * c
+    }
+
+    /**
      * 绾害鐩稿悓鏃�
      * 璺濈杞崲涓虹粡搴�
      */

--
Gitblit v1.9.3