public static getAngle(pointA, pointB): number {//通过两点获得角度
let mx = pointA.x;
let my = pointA.y;
let px = pointB.x;
let py = pointB.y;
var x = Math.abs(px - mx);
var y = Math.abs(py - my);
var z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
var cos = y / z;
var angle = Math.acos(cos);//用反三角函数求弧度
let pi = Math.PI;
if (mx > px && my > py) {//目标点在第四象限
angle = pi - angle;
}
if (mx == px && my > py) {//目标点在y轴负方向上
angle = pi;
}
if (mx > px && my == py) {//目标点在x轴正方向上
angle = pi / 2;
}
if (mx < px && my > py) {//目标点在第三象限
angle = pi + angle;
}
if (mx < px && my == py) {//目标点在x轴负方向
angle = pi * 3 / 2;
}
if (mx < px && my < py) {//目标点在第二象限
angle = 2 * pi - angle;
}
angle = angle + pi / 2;
if (angle > 2 * pi) angle = angle - 2 * pi;
if (isNaN(angle)) return 0;
return angle;
}
public static toAngle(a: number): number {
return a / MathConstant.PI_180;
}