我正在尝试为一些计算作业制作计算器,但信息以度数给出,答案必须以度数为单位。我尝试使用 Math.toDegrees 和 Math.toRadians 但答案不正确。
public static double crossProduct() {
Scanner in = new Scanner(System.in);
System.out.println("enter angle in degrees");
double angle = in.nextDouble();
System.out.println("x1 = ");
double x1 = in.nextDouble();
System.out.println("y1 = ");
double y1 = in.nextDouble();
System.out.println("z1 = ");
double z1 = in.nextDouble();
System.out.println("");
System.out.println("x2 = ");
double x2 = in.nextDouble();
System.out.println("y2 = ");
double y2 = in.nextDouble();
System.out.println("z2 = ");
double z2 = in.nextDouble();
double mag1 = Math.sqrt((x1 * x1) + (y1 * y1) + (z1 * z1));
double mag2 = Math.sqrt((x2 * x2) + (y2 * y2) + (z2 * z2));
double res = mag1 * mag2 * Math.toDegrees(Math.sin(Math.toRadians(angle)));
System.out.println("cross product = " + res);
return res;
}
输入 <0,2,0> 和 <0,5,0> 和角度 = 90 度应该给出 10 的答案。相反它返回:
572.9577951308232
有任何想法吗?
编辑:另外,如果有人有更好/更短的输入组件的方法,那将是惊人的。