JAVA计算两点连线与水平线夹角
package com.utils;
/**
* Created
* Data: 2020/4/20.
* Description:
*/
public class AngleUtils {
public static int calAngle(double x1, double y1, double x2, double y2) {
double x = Math.abs(x1 - x2);
double y = Math.abs(y1 - y2);
double z = Math.sqrt(x * x + y * y);
int angle = Math.round((float) (Math.asin(y / z) / Math.PI * 180));
return angle;
}
public static void main(String[] args) {
int j = calAngle(-2, 2,0,0);
System.out.println("角度:" + j);
}
}