在Java中将Radians转换为Degrees [英] Convert from Radians to Degrees in Java

查看:728
本文介绍了在Java中将Radians转换为Degrees的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我写了下面的构造函数:

  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. 我是否正确,现在我已经从atan()方法得到了一个角度度量单位而不是弧度数?

  2. 是否有一个简单的方法这样做?

  3. 方案

    为什么不使用内置方法 Math.toDegrees(),它随Java SE一起提供。


    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 !

    解决方案

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

    这篇关于在Java中将Radians转换为Degrees的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆