Java 如何将度数计算转换为弧度?(卡瓦到爪哇)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20594658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:00:31  来源:igfitidea点击:

How to convert a degrees calculation to radians? (Kawa to Java)

javaandroidradianskawa

提问by Brian J

I have tried to convert a calculation from an app I made using MIT AppInventor which uses Kawa to Android using Java.The problem I'm facing is that the trigonometric parts of the calculation in Kawa are using degress.My question is how do I translate this calculation to Java and get the same output?

我试图将计算从我使用 MIT AppInventor 制作的应用程序转换为使用 Java 的 Android。我面临的问题是 Kawa 中计算的三角部分使用 degress。我的问题是我如何翻译这个计算到Java并得到相同的输出?

This is how I do the calculation is Kawa,all variables are of type double:

这就是我如何计算 Kawa,所有变量都是 double 类型:

 Tri 1=atan(Offset Depth/Offset Length)
 Mark 1=sqrt(Offset Length^2+Offset Depth^2)
 Tri 2=(180-Tri1)/2
 Mark 2=Duct Depth/(tan(Tri 2))

Then I did my best to translate it to Java code,the variables are double also as above,depth,length and duct depth are user input values.

然后我尽力将它翻译成Java代码,变量也是如上的两倍,深度、长度和管道深度是用户输入值。

 tri1 = Math.atan(offsetDepth / offsetLength);
 marking1 = Math.sqrt(Math.pow(offsetLength,2) + Math.pow(offsetDepth,2));  
 tri2 = (180 - tri1) / 2;
 marking2 = ductDepth / Math.tan(tri2);

Screenshot of what the inputs and outputs look like:

输入和输出的屏幕截图:

enter image description here

在此处输入图片说明

采纳答案by peter.petrov

You can convert the angles to radians yourself.

您可以自己将角度转换为弧度。

As we know:

据我们所知:

180 degrees = PI radians

So:

所以:

1 degree = PI / 180 radians

So wherever you have X degrees,
they are equal to (X * PI / 180) radians.

所以无论你有 X 度,
它们都等于 (X * PI / 180) 弧度。

In Java you have

在 Java 中,你有

Math.PI

which defines the value of the PI number.

它定义了 PI 编号的值。

Just change your Java code to this:

只需将您的 Java 代码更改为:

tri11 = Math.atan(1.0 * offsetDepth / offsetLength); // tri11 is radians
tri1 = tri11 * 180.0 / Math.PI; // tri1 is degrees
marking1 = Math.sqrt(Math.pow(1.0 * offsetLength,2) + Math.pow(1.0 * offsetDepth,2));  
tri2 = (180.0 - tri1) / 2.0; // tri2 is degrees
tri22 = tri2 * Math.PI / 180.0; // tri22 is radians
marking2 = 1.0 * ductDepth / Math.tan(tri22);
// output whatever you like now

回答by Keppil

You can use Math.toRadians()to convert degrees to radians.

您可以使用Math.toRadians()将度数转换为弧度。