JS计算三个坐标点的夹角
先计算两个线段的弧度 再乘以180/π 得到两个点到中间点的夹角角度
function getAngle(pointA, pointB, pointC) {
const ABX = pointA.longitude - pointB.longitude;
const ABY = pointA.latitude - pointB.latitude;
const CBX = pointC.longitude - pointB.longitude;
const CBY = pointC.latitude - pointB.latitude;
const AB_MUL_CB = ABX * CBX + ABY * CBY;
const DIST_AB = Math.sqrt(ABX*ABX+ABY*ABY)
const DIST_CB = Math.sqrt(CBX*CBX+CBY*CBY)
const cosValue = AB_MUL_CB/(DIST_AB*DIST_CB);
return Math.acos(cosValue)*180/Math.PI;
}
//90度
console.log(getAngle({longitude:116.379817,latitude:39.930138},{longitude:116.3805,latitude:39.91333},{longitude:116.398035,latitude:39.913856}))