<分区>
我在使用 Math.cos 函数在 Java 中计算 cosinus 90 时遇到了一些问题:
public class calc{
private double x;
private double y;
public calc(double x,double y){
this.x=x;
this.y=y;
}
public void print(double theta){
x = x*Math.cos(theta);
y = y*Math.sin(theta);
System.out.println("cos 90 : "+x);
System.out.println("sin 90 : "+y);
}
public static void main(String[]args){
calc p = new calc(3,4);
p.print(Math.toRadians(90));
}
当我计算 cos90 或 cos270 时,它给出了荒谬的值。它应该是 0。我用 91 或 271 进行了测试,给出了接近 0 的值,这是正确的。
我应该怎么做才能使 cos 90 = 0 的输出?因此,它使输出 x = 0 和 y = 4。
多谢指教