feiyu02
2025-01-09 6c1e7c5ac983301c34f003415cda2ef7c7e176a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.flightfeather.uav.biz.satellite
 
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.GridCell
import kotlin.math.PI
import kotlin.math.sqrt
 
/**
 * 卫星遥测网格管理
 * 根据网格中心点计算4个顶点坐标
 * 根据已有网格进行细分网格计算
 * @date 2025/1/8
 * @author feiyu02
 */
object SatelliteGridManage {
 
    /**
     * 根据正方形网格中心点坐标,计算4个顶点坐标
     * @param points 网格中心坐标点数组
     */
    fun calGridVertex(points: List<Pair<Double, Double>>): List<GridVertex> {
        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);
        // 网格正方形对角线的一半长度
        val halfDiagonal = sqrt((dis / 2) * (dis / 2) * 2);
        // 计算首个正方形各顶点相对于中心点的角度,得到正方形各顶点的坐标
        val angle1 = MapUtil.plusAngle(angle, 45.0);
        val gp1 = MapUtil.getPointByLen(p1, halfDiagonal, angle1 * PI / 180);
        val angle2 = MapUtil.plusAngle(angle1, 90.0);
        val gp2 = MapUtil.getPointByLen(p1, halfDiagonal, angle2 * PI / 180);
        val angle3 = MapUtil.plusAngle(angle2, 90.0);
        val gp3 = MapUtil.getPointByLen(p1, halfDiagonal, angle3 * PI / 180);
        val angle4 = MapUtil.plusAngle(angle3, 90.0);
        val gp4 = MapUtil.getPointByLen(p1, halfDiagonal, angle4 * PI / 180);
        // 计算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 ->
            GridVertex(
                p.first + dx1, p.second + dy1,
                p.first + dx2, p.second + dy2,
                p.first + dx3, p.second + dy3,
                p.first + dx4, p.second + dy4,
            )
        }
    }
 
    /**
     * 拆分网格
     */
    fun splitGrid(gridCellList: List<GridCell?>): List<GridCell> {
        TODO()
    }
 
}