js求两点之间的角度,距离

var p1:Point = new Point(40,30);
var p2:Point = new Point(80,60);
 
var angle:Number = Math.atan2((p1.y-p2.y), (p2.x-p1.x)) //弧度 -0.6435011087932844, 即 2*Math.PI - 0.6435011087932844
var theta:Number = angle*(180/Math.PI);  //角度 -36.86989764584402,即360 - 36.86989764584402 = 323.13010235415598

 let distance = this.p1.sub(this.p2).mag();

你可能感兴趣的:(cocos)