我曾尝试转换一个应用程序,我使用麻省理工学院的AppInventor,其中使用Kawa到安卓使用Java.The的计算,我面临的问题是,在Kawa的三角计算部分使用degress.My的问题是,我如何将这个计算转换成Java,并得到相同的输出?
这就是我计算Kawa的方法,所有的变量都是双精度的:
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代码,变量也是上面的两倍,深度、长度和管道深度都是用户输入值。
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);输入和输出的屏幕截图:

发布于 2013-12-15 20:51:08
您可以自己将角度转换为弧度。
正如我们所知:
180 degrees = PI radians所以:
1 degree = PI / 180 radians所以无论你在哪里有X度,
它们等于(X * PI / 180)弧度。
在Java中,你有
Math.PI它定义了PI数字的值。
只需将您的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发布于 2013-12-15 20:49:37
可以使用Math.toRadians()将度数转换为弧度。
https://stackoverflow.com/questions/20594658
复制相似问题