gpt4 book ai didi

Java 在两个 GPS 坐标之间的角度移动

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:37:33 27 4
gpt4 key购买 nike

我有一个用例,我需要生成 GPS 坐标以覆盖特定区域(由 GPS 坐标列表标记)。

所以我需要生成坐标。我测试并实现了以下功能:

//determines wether a Waypoint is inside the specified area
public boolean isInsideArea(Waypoint waypoint)

public double distanceInKmBetweenGPSCoordinates(Waypoint from, Waypoint to)

public double[] calculateCoordinatesAfterMove(Waypoint waypoint, double dx, double dy)

这是我如何为正方形(或近似正方形)生成坐标的天真实现:

public static List<drone.Waypoint> addAutoGeneratedWaypoints(List<Waypoint> polygon_lat_long_pairs) {
List<Waypoint> waypoints = new ArrayList<>();

AreaTester tester = new GPSPolygonTester(polygon_lat_long_pairs);
GPSCoordinateCalculator coordinateCalculator = new GPSCoordinateCalculator();
CustomGPSMapper mapper = new CustomGPSMapper();

boolean finish = false;
String mode = "r";
Waypoint prev = polygon_lat_long_pairs.get(0);
int count = 0;
double distanceDown = mapper.distanceInKmBetweenGPSCoordinates(polygon_lat_long_pairs.get(2), polygon_lat_long_pairs.get(3));
double travelledDown = 0;
while (!finish) {
if (mode.equals("r")) {
double[] nextA = coordinateCalculator.calculateCoordinatesAfterMove(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 5.0, 0.0);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
System.out.println("Waypoint was in area");
waypoints.add(next);
prev = next;
} else {
System.err.println("Left area, switching position");
mode = "l";
double[] nextB = coordinateCalculator.calculateCoordinatesAfterMove(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 0.0, -3.0);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
count++;
} else {
double[] nextA = coordinateCalculator.calculateCoordinatesAfterMove(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), -5.0, 0.0);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
System.out.println("Left are, switching");
mode = "r";
double[] nextB = coordinateCalculator.calculateCoordinatesAfterMove(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 0.0, -3.0);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
count++;
}
if (travelledDown >= distanceDown) {
finish = true;
}
}

List<de.dhbw.drone.waypoints.Waypoint> mapped = waypoints.stream().map(p -> new de.dhbw.drone.waypoints.Waypoint(p)).collect(Collectors.toList());
return mapped;

当它沿着正方形的右侧/左侧移动时,我停止算法。

但是,如果标记区域的形状不是正方形并且有斜线,我会很挣扎。

因此我必须使用轴承移动,如下图所示:

Fly with slope

当我可以将这个角度添加到我的运动中时,我可以对每个形状的区域使用这个算法,从而产生以下路径:

Desired path

有人能帮我如何以米为单位移动这个特定角度的距离,如何计算两个 GPS 坐标之间的角度,以及如何计算转边后的角度吗? (从右到左而不是从左到右,反之亦然)。还是可以通过计算 angle(point1, point2) 和 angle(point2, point1) 来解决?

最佳答案

要计算从一个坐标到另一个坐标的方位角并指向给定的距离 m,您可以使用来自 latlong page 的公式(方位目的地部分)


您可以使用通常在二维多边形光栅化中实现的相同方法。

横线在内存中是连续的,填充横线是最可靠的方法。

例如,在您的情况下,您可以使用恒定纬度的线。

按纬度对地球多边形的顶点进行排序,并将顶点纬度值之间的范围分开,然后用点序列 (plane example) 填充生成的“梯形”

有时(复杂的多边形等)使用拒绝方法会更简单 - 在描述的矩形中生成网格点并忽略多边形之外的网格点。

关于Java 在两个 GPS 坐标之间的角度移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55412491/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com