您的位置:首页 > 其它

记录下-两点角度计算

2017-08-07 16:50 232 查看
public static double GetAngle(double sx, double sy, double ex, double ey)
{
//两点的x、y值
var x = ex - sx;
var y = ey - sy;
//斜边长度
var len = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
if (len == 0) return 0; //2点重合
var cos = x / len;
//求出弧度
var radius = Math.Acos(cos);
//求角度
var angle = 180 / (Math.PI / radius);
if (y < 0)
{
angle = 360 - angle;
}
return Math.Round(angle); //取整
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: