Answers for "java find angle between two points"

0

how to find the angle of 2 coordinates java

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)
Posted by: Guest on January-02-2021

Code answers related to "java find angle between two points"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language