如何计算直线形式从北方方向两点的角度?



有没有人有脚本/代码/函数来计算由两点(x1,y1(和(x2,y2(形成的线与北线(方位角(的角度?

JavaScript 中的两点 (x1,y1( 和 (x2,y2(

function calcAngleDegrees(x1, y1,x2,y2) {
let x = x2 - x1 ;
let y = y2 - y1 ;
return Math.atan2(y, x) * 180 / Math.PI;
}
let angleDegree = calcAngleDegrees(0,0,5,-5); // -45
let bearingFromAngle = (450 - angleDegree ) % 360; // 135
float calc_azimuth(float x1, float y1, float x2, float y2)
{
//calculate deltas
float deltax = x2 - x1;
float deltay = y2 - y1;
//chech if the deltas are zeros, and if they are, then use a small number
if (deltax == 0.0)
deltax = 0.000001;
if (deltay == 0.0)
deltay = 0.000001;
//Calculate angle
float angle = abs(atan(deltay / deltax) * (180/3.14159));
//define and initialize azimuth
float azim = 0;
//first quadrant
if (x2 >= x1 && y2 > y1)
azim = 90.0 - angle;
//second quadrant
else if (x2 > x1 && y2 <= y1)
azim = angle + 90.0;
//third quadrant
else if (x2 <= x1 && y2 < y1)
azim = 270.0 - angle;
//fourth quadrant
else
azim = 270.0 + angle;
return azim;
}

相关内容

  • 没有找到相关文章

最新更新