📜  如何找到2个坐标的角度java代码示例

📅  最后修改于: 2022-03-11 14:52:21.703000             🧑  作者: Mango

代码示例1
public double getAngleFromPoint(Point firstPoint, Point secondPoint) {

    if((secondPoint.x > firstPoint.x)) {//above 0 to 180 degrees

        return (Math.atan2((secondPoint.x - firstPoint.x), (firstPoint.y - secondPoint.y)) * 180 / Math.PI);

    }
    else if((secondPoint.x < firstPoint.x)) {//above 180 degrees to 360/0

        return 360 - (Math.atan2((firstPoint.x - secondPoint.x), (firstPoint.y - secondPoint.y)) * 180 / Math.PI);

    }//End if((secondPoint.x > firstPoint.x) && (secondPoint.y <= firstPoint.y))

    return Math.atan2(0 ,0);

}//End public float getAngleFromPoint(Point firstPoint, Point secondPoint)