taxi 自动驾驶画线

This commit is contained in:
lianglihui
2021-06-24 12:18:57 +08:00
parent 848e9667b6
commit e3532f4573
9 changed files with 335 additions and 15 deletions

View File

@@ -0,0 +1,121 @@
package com.mogo.module.common.utils;
import static java.lang.Math.PI;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020/4/14 1:02 PM
* desc : 计算车辆驾驶方向的工具类
* version: 1.0
*/
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);
//Log.w(MODULE_NAME, "getDegreeOfCar2Poi_计算车辆行驶方向 与 poi点到车辆的连线 间的夹角_angle===" + _angle);
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;
}
}
return calculationAngle(poiAngle, carAngle);
}
/**
* 计算两个行驶方向间的夹角 计算结果小于180度
*
* @param angle0
* @param angle1
* @return
*/
public static int calculationAngle(int angle0, int angle1) {
// 获取两方向间夹角
int angle = Math.abs(angle0 - angle1);
if (angle > 180) {
int minAngle = Math.min(angle0, angle1);
int maxAngle = Math.max(angle0, angle1);
return 180 - Math.abs(minAngle + 180 - maxAngle);
} else {
return angle;
}
}
/**
* 计算车辆行驶方向角度,起点&终点经纬度
*
* @param carLat 车辆位置 lat
* @param carLon 车辆位置 lon
* @param poiLat poi 位置 lat
* @param poiLon poi 位置 lon
*/
public static int getCarAngle(double carLat, double carLon, double poiLat, double poiLon) {
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;
}
}
if (poiAngle >= 355) {
poiAngle = 0;
}
return poiAngle;
}
/**
* 计算连两个角度差值
*
* @param angle1 角度1
* @param angle2 角度2
* @return 差值
*/
public static double getAngleDiff(double angle1, double angle2) {
// 两个角度差值较小
return 180 - Math.abs(Math.abs(angle1 - angle2) - 180);
}
}

View File

@@ -0,0 +1,45 @@
package com.mogo.module.common.utils;
import android.location.Location;
import android.util.Log;
import com.mogo.map.MogoLatLng;
import com.mogo.map.location.MogoLocation;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020/5/15 10:31 AM
* desc : 基于位置工具类
* version: 1.0
*/
public class LocationUtils {
private static final String TAG = "LocationUtils";
/**
* 获取传入的经纬度在车辆的什么位置
*
* @return 顺时针true-前false-后
*/
public static boolean isPointOnCarFront(MogoLocation carLocal, MogoLatLng pointLocal) {
double carLon = carLocal.getLongitude();
double carLat = carLocal.getLatitude();
double poiLon = pointLocal.getLon();
double poiLat = pointLocal.getLat();
float carAngle = carLocal.getBearing();
// 计算车辆与点之间的夹角
int diffAngle = DrivingDirectionUtils.getDegreeOfCar2Poi(
carLon, carLat, poiLon, poiLat, (int) carAngle);
if (diffAngle <= 90) {
Log.i(TAG, "目标点在车辆--前方");
return true;
} else {
Log.i(TAG, "目标点在车辆--后方");
return false;
}
}
}