[RouterOpt]车前引导线拖尾问题优化2

This commit is contained in:
renwj
2022-04-11 18:05:29 +08:00
parent c946f7ca94
commit a0f0d3c2c8
9 changed files with 280 additions and 180 deletions

View File

@@ -2,6 +2,8 @@ package com.mogo.module.common.utils;
import static java.lang.Math.PI;
import android.util.Pair;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
@@ -11,40 +13,35 @@ import static java.lang.Math.PI;
*/
public class DrivingDirectionUtils {
/**
* 计算车辆行驶方向 与 poi点到车辆的连线 间的夹角
*
* @param carLon 车辆位置 lon
* @param carLat 车辆位置 lat
* @param poiLon poi 位置 lon
* @param poiLat poi 位置 lat
* @param carAngle 车辆行驶方向
* @return
*/
public static int getDegreeOfCar2Poi(double carLon, double carLat, double poiLon, double poiLat, int carAngle) {
int poiAngle = 0;
// 以子午线作为y轴 计算两点的余切 再将余切值转化为角度
double _angle = Math.atan2(Math.abs(carLon - poiLon), Math.abs(carLat - poiLat)) * (180 / PI);
if (poiLon > carLon) {
// poi 在 车辆位置的第1象限
if (poiLat > carLat) {
poiAngle = (int) _angle;
}
// poi 在 车辆位置的第2象限
else {
poiAngle = 180 - (int) _angle;
}
} else {
// poi 在 车辆位置的第3象限
if (poiLat < carLat) {
poiAngle = (int) _angle + 180;
}
// poi 在 车辆位置的第4象限
else {
poiAngle = 360 - (int) _angle;
}
public static long getDegreeOfCar2Poi(double x1, double y1, double x2, double y2, double x1_angle) {
Pair<Double, Double> newPoint = calculateNewPoint(x1, y1, x1_angle, 10);
if (newPoint != null) {
double angle = getAngle(x1, y1, newPoint.first, newPoint.second, x2, y2);
return Math.round(angle + 0.5);
}
return calculationAngle(poiAngle, carAngle);
return 0;
}
private static double getAngle(double sx, double sy, double x1, double y1, double x2, double y2) {
x1 = x1 - sx;
y1 = y1 - sy;
x2 = x2 - sx;
y2 = y2 - sy;
double product = x1 * x2 + y1 * y2;
double radians = Math.acos(product / (Math.sqrt(Math.pow(x1, 2.0) + Math.pow(y1, 2.0)) * Math.sqrt(Math.pow(x2, 2.0) + Math.pow(y2, 2.0))));
return Math.toDegrees(radians);
}
public static Pair<Double, Double> calculateNewPoint(double x, double y, double angle, double distance) {
if (distance == 0) {
return null;
}
double radian = Math.toRadians(angle);
double radianCandle = Math.toRadians(90.0 - angle);
double nX = x + distance * Math.sin(radian) / 100000.0;
double nY = y + distance * Math.sin(radianCandle) / 100000.0;
return Pair.create(nX, nY);
}
/**