我看过不同的网站,试图解决我的问题。我还试图在Java中查找任何YT或其他trig视频,但什么也找不到。(我是个菜鸟,所以我也不总是理解大多数网站提到的所有东西)。
无论如何,我正试图制作一个简单的程序来计算Snell定律的部分内容(我意识到有一些网站可以这样做)。但是弧正弦似乎一点也不影响我的变量值。
以下是代码:
import java.util.Scanner;
public class trig_functions_test {
public static void main(String[] args) {
Scanner HumanInput = new Scanner (System.in);
double n1, n2, Oi, OR;
System.out.println("Enter the first medium's index of refraction.");
n1 = HumanInput.nextDouble();
System.out.println("Enter the second medium's index of refraction.");
n2 = HumanInput.nextDouble();
System.out.println("Enter the angle of incidence.");
Oi = HumanInput.nextDouble();
System.out.println("Enter the angle of refraction.");
OR = HumanInput.nextDouble();
//if angle of refraction is the missing variable
if (OR == 0) {
Oi = Math.toRadians(Oi);
OR = (n1*Math.sin(Oi)/n2);
OR = Math.toRadians(OR);
OR = Math.asin (OR);
OR = Math.toDegrees(OR);
System.out.println(OR);
}
}
}当我调试程序时,我得到以下内容:
首先,以下是正在实施的计划:

(0只是表示没有折射的角度)
这些是在if语句中的第2行被评估(?)之后的结果:

在将"OR“转换为弧度后,"OR”的值将变为0.011364657670640462。
然后,这里是有问题的部分,与弧正弦的部分被计算,"OR“变成0.011364*90231927541* (改变的部分在*‘s之间)。
最后," or“再次转换为度数,然后在第二行(或多或少) "OR”等于0.6511*609374816383* (*‘s之间表示更改的部分)之后,返回到我的值。
发布于 2014-04-20 23:27:52
你的麻烦来自于这条线:
OR = Math.toRadians(OR); 在计算时,您已经得到了以弧度表示的答案:
OR = (n1*Math.sin(Oi)/n2);当你再次把它转换成弧度时,你就是在扭曲结果。删除OR = Math.toRadians(OR);,您的程序将按预期工作。
发布于 2014-04-20 23:22:42
你的解决方案比你需要的要复杂得多。你应该通过求解Snell定律中的折射角度来评估你的表达式,就像这样:
Oi = Math.toRadians(Oi);
OR = Math.asin((n1/n2)*Math.sin(Oi));
OR = Math.toDegrees(OR)
System.out.println("Angle of refraction: "+OR);https://stackoverflow.com/questions/23188628
复制相似问题