I'm trying to get the alpha angle in degrees from x,y when user creates an object.
I wrote the following constructor:
public class Point { private double _radius , _alpha; public Point ( int x , int y ) { _radius = Math.sqrt ( Math.pow(x,2) + Math.pow (y,2) ) ; _alpha = ( ( Math.atan (y/x) ) * 180 ) / Math.PI; } }
Am I right that _alpha is now an angle in degrees instead of radians that I got from the atan() method ?
Is there a simple way to do so ?
Thanks !
Math. toDegrees() is used to convert an angle measured in radians to an approximately equivalent angle measured in degrees. Note: The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.
By default, the Java Math library expects values to its trigonometric functions to be in radians.
Java toRadians() method with ExampletoRadians() is used to convert an angle measured in degrees to an approximately equivalent angle measured in radians. Note: The conversion from degrees to radian is generally inexact.
The Math. sin() method returns a number between -1 and 1. The Math. sin() method expects the number in radians.
Why not use the built-in method Math.toDegrees()
, it comes with the Java SE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With