应该使用线性方程来计算相对于时间(步长为100ms)发射的弹丸的坐标,并输出线性数,但是如果我使用CalcMe.com(数学工具)绘制该方程,它将使抛物线图
InVel = Double.parseDouble(jTextField1.getText());
g = Double.parseDouble(jTextField8.getText());
y = 1;
while(y >= -1) {
t += 100;
x = InVel * TimeUnit.MILLISECONDS.toSeconds(t) * Math.cos(45);
y = InVel * TimeUnit.MILLISECONDS.toSeconds(t) * Math.sin(45) - (1 / 2) * g * Math.pow(TimeUnit.MILLISECONDS.toSeconds(t), 2);
//System.out.print(Double.toString(x));
//System.out.printf(" ");
System.out.print(Double.toString(y));
System.out.printf("%n");
}
jTextField6.setText(Double.toString(x));
代码在Java中
g为常数(9.8)
并且invel是由用户提供的,因此其常量也是如此
g是重力,是弹丸的初始速度
等式是:x=invel*time*cos(45)
和y=invel*time*sin(45)-(1/2)*g*t^2
有人可以帮助我吗?
答案 0 :(得分:0)
您的毫秒到秒的值转换方法 TimeUnit.MILLISECONDS.toSeconds(t)是主要事实。它返回的 long 值是您要加倍的值。请看下面的代码。可能是您的答案。只需将硬编码值替换为 jTextField
public static void main(String[] args) {
double InVel = Double.parseDouble("10.555");
double g = Double.parseDouble("9.8");
double y = 1;
double x=0;
double t=0;
while(y >= -1) {
t += 100;
double timeInSeconds = (t / (double)1000) % (double)60;
x = InVel * timeInSeconds * Math.cos(45);
y = InVel * timeInSeconds * Math.sin(45) - ((double) 1 / (double) 2) * g * Math.pow(timeInSeconds, 2);
//System.out.print(Double.toString(x));
//System.out.printf(" ");
System.out.println("X = " + x + " Y = " + Double.toString(y));
System.out.printf("%n");
}
}