how to find the angle of 2 coordinates java

Solutions on MaxInterview for how to find the angle of 2 coordinates java by the best coders in the world

showing results for - "how to find the angle of 2 coordinates java"
Valentina
05 Jul 2018
1public double getAngleFromPoint(Point firstPoint, Point secondPoint) {
2
3    if((secondPoint.x > firstPoint.x)) {//above 0 to 180 degrees
4
5        return (Math.atan2((secondPoint.x - firstPoint.x), (firstPoint.y - secondPoint.y)) * 180 / Math.PI);
6
7    }
8    else if((secondPoint.x < firstPoint.x)) {//above 180 degrees to 360/0
9
10        return 360 - (Math.atan2((firstPoint.x - secondPoint.x), (firstPoint.y - secondPoint.y)) * 180 / Math.PI);
11
12    }//End if((secondPoint.x > firstPoint.x) && (secondPoint.y <= firstPoint.y))
13
14    return Math.atan2(0 ,0);
15
16}//End public float getAngleFromPoint(Point firstPoint, Point secondPoint)
17