风筝误舞蹈教学:怎么计算两点间角度

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/24 14:53:49
怎么计算两点间角度 有什么公式吗?最好讲的细点谢谢
function getAngle(px1, py1, px2, py2){
x = px2 - px1;
y = py2 - py1;
hyp = Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
hyp 是两点间的距离没错吧

下面着快看不懂了
cos = x / hyp;
rad = Math.acos(cos);
// Ask your math teacher if you don’t understand this one.(如果你看不懂,就去问你的数学老师)

deg = 180/(Math.PI / rad);
// Yes, we do got one angle, rad, by 'Math.acos(cos)', but in radians.(是的,我们通过cos得到了一个角度“rad”,不过是以弧度为单位的)

// Therefore, we need do one more step to transfer it to normal angle we need.(因此,我们需要再进一步把它转换成我们所需要的标准的角度)

if(y <0){deg = -deg;}
else if((y == 0) && (x <0)){deg = 180;}

return deg;
}

你有编程计算器吗,卡西欧5800的,如果有,用这个算很简单了。

是啊,两点的角度应有其他条件存在吧

两点何以成角

量角器