[charter]
[3.2.0] [更精确的算角度]
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import kotlin.Triple;
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
@@ -340,4 +341,56 @@ public class CoordinateCalculateRouteUtil {
|
||||
//弧度转角度制
|
||||
return (int) (180 * radian / Math.PI);
|
||||
}
|
||||
|
||||
|
||||
private static Triple<Double,Double,Double> ball2xyz(Double thera,Double fie,Double r){
|
||||
double x = r * Math.cos(thera) * Math.cos(fie);
|
||||
double y = r * Math.cos(thera) * Math.sin(fie);
|
||||
double z = r * Math.sin(thera);
|
||||
return new Triple(x,y,z);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://blog.csdn.net/reborn_lee/article/details/82497577
|
||||
* 将地理经纬度转换成笛卡尔坐标系
|
||||
*/
|
||||
private static Triple<Double,Double,Double> geo2xyz(double lat,double lng){
|
||||
double thera = (Math.PI * lat) / 180;
|
||||
double fie = (Math.PI * lng) / 180;
|
||||
return ball2xyz(thera, fie,6400.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算3个地理坐标点之间的夹角
|
||||
* @param l1 顶点坐标
|
||||
* @param l2
|
||||
* @param l3
|
||||
* @return l1为顶点的角度 精度没有angleOflocation高
|
||||
*/
|
||||
public static double getDegree(LatLng l2,LatLng l1,LatLng l3) {
|
||||
Triple<Double,Double,Double> p1 = geo2xyz(l1.latitude,l1.longitude);
|
||||
Triple<Double,Double,Double> p2 = geo2xyz(l2.latitude,l2.longitude);
|
||||
Triple<Double,Double,Double> p3 = geo2xyz(l3.latitude,l3.longitude);
|
||||
|
||||
double x1 = p1.getFirst();
|
||||
double y1 = p1.getSecond();
|
||||
double z1 = p1.getThird();
|
||||
|
||||
double x2 = p2.getFirst();
|
||||
double y2 = p2.getSecond();
|
||||
double z2 = p2.getThird();
|
||||
|
||||
double x3 = p3.getFirst();
|
||||
double y3 = p3.getSecond();
|
||||
double z3 = p3.getThird();
|
||||
|
||||
// 计算向量 P2P1 和 P2P3 的夹角 https://www.zybang.com/question/3379a30c0dd3041b3ef966803f0bf758.html
|
||||
double p1P2 = Math.sqrt(Math.pow(x2 - x1,2.0) + Math.pow(y2 - y1,2.0) + Math.pow(z2 - z1,2.0));
|
||||
double p2p3 = Math.sqrt(Math.pow(x3 - x2,2.0) + Math.pow(y3 - y2,2.0) + Math.pow(z3 - z2,2.0));
|
||||
|
||||
double p = (x1 - x2) * (x3 - x2) + (y1 - y2) * (y3 - y2) + (z1 - z2) * (z3 - z2); //P2P1*P2P3
|
||||
|
||||
return (Math.acos(p / (p1P2 * p2p3)) / Math.PI) * 180;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user