问题描述
我试图计算使用MIT AppInventor它采用川用我现在面临Java.The问题的的Android应用程序,我做转换是,在川计算的三角函数部分使用degress.My问题是如何我翻译这个计算Java和得到的结果相同?
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?
这是我做的计算是川,所有变量的类型为双:
This is how I do the calculation is Kawa,all variables are of type 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))
然后我做了我最好把它翻译成Java code,变量是双也如上,深度,长度和管深度用户输入值。
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.
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:
推荐答案
您可以转换角度,弧度自己。
You can convert the angles to radians yourself.
我们知道:
180 degrees = PI radians
所以:
1 degree = PI / 180 radians
所以,只要您有X度,结果
它们是等于(X * PI / 180)弧度。结果
So wherever you have X degrees,
they are equal to (X * PI / 180) radians.
在Java中,你有
Math.PI
限定在PI数的值
which defines the value of the PI number.
只要改变你的Java code这样:
Just change your Java code to this:
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
这篇关于如何转换度计算弧度? (川到Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!