尝试使用Java计算向量。

huangapple go评论84阅读模式
英文:

trying to calculate vectors with java

问题

我对Java数学和一般数学有一个快速的问题。因此,763.5*cos(70)应该等于261.13237,这是Ax向量的计算方式,然而,在Java中,答案似乎是483.53921155638994。不知道为什么。任何帮助都将不胜感激。

以下是您目前的代码:

package Main;
import java.util.Scanner;
import java.lang.Math;
public class vectors{
    
    public static void main(String[] args) {
        
        double Mag = 763.5;
        double Deg = 70;
        double Ax;
        double Ay;
        
        Ax = Mag*Math.cos(Deg);
        
        System.out.println(Ax);
    }
}
英文:

I had a quick question about java math and a little bit about math in general. so 763.5*cos(70) should in equal to 261.13237 that's how the Ax vector is calculated, however, in java the answer seems to be 483.53921155638994. no idea why. any help is much appreciated

here is what I have so far

package Main;  
import java.util.Scanner;
import java.lang.Math;
public class vectors{
    
           
    public static void main(String[] args) {
        
        double Mag = 763.5;
        double Deg = 70;
        double Ax;
        double Ay;
        
        Ax = Mag*Math.cos(Deg);
        
        System.out.println(Ax);
        
        
        

}
}

答案1

得分: 1

Math.cos()的参数单位是弧度:

double Mag = 763.5;
double Deg = 70;
double radians = (Deg / 360) * 2 * Math.PI;
double Ax;
double Ay;

Ax = Mag * Math.cos(radians);

System.out.println(Ax);

261.13237942914816

英文:

Math.cos()'s argument is in radians:

        double Mag = 763.5;                                                     
        double Deg = 70;                                                        
        double radians = (Deg / 360) * 2 * Math.PI;                             
        double Ax;                                                              
        double Ay;                                                              
                                                                                
        Ax = Mag*Math.cos(radians);                                             
                                                                                
        System.out.println(Ax);

261.13237942914816

huangapple
  • 本文由 发表于 2020年8月10日 11:05:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/63333591.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定