Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert from Radians to Degrees in Java

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;     }  } 
  1. Am I right that _alpha is now an angle in degrees instead of radians that I got from the atan() method ?

  2. Is there a simple way to do so ?

Thanks !

like image 446
Master C Avatar asked Apr 23 '11 11:04

Master C


People also ask

How do you convert radians to degrees in Java?

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.

Is Java in degrees or radians?

By default, the Java Math library expects values to its trigonometric functions to be in radians.

What is radians in Java?

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.

Is Java math sin in radians?

The Math. sin() method returns a number between -1 and 1. The Math. sin() method expects the number in radians.


1 Answers

Why not use the built-in method Math.toDegrees(), it comes with the Java SE.

like image 198
mP. Avatar answered Oct 05 '22 06:10

mP.