已知两个坐标,计算坐标连成的线与水平方向的夹角

click(e){
  let event = e || window.event;  //兼容
      let drag = event.currentTarget;
      let centerLeft = Math.round(drag.offsetWidth / 2) + drag.offsetLeft;
      let centerTop = Math.round(drag.offsetHeight / 2) + drag.offsetTop;
      let diffX = event.clientX;
      let diffY = event.clientY;

      let deg = this.getAngle(centerLeft, centerTop, diffX, diffY);
}
getAngle (x1, y1, x2, y2) {
      var x = x1 - x2,
        y = y1 - y2;
      if (!x && !y) {
        return 0;
      }
      var angle = (180 + Math.atan2(-y, -x) * 180 / Math.PI + 360) % 360;
      return angle;
    }

你可能感兴趣的:(已知两个坐标,计算坐标连成的线与水平方向的夹角)