我也制作了这个程序。您有您需要考虑四个主要部分:除非你采取空气摩擦考虑
- VelocityX-保持不变,它的速度计算* COS(THETA)
- VelocityY-以下公式VY随时间变化= Velocity sinθ-g time
- X position-VelocityX * time;
- Ÿ位置 - VelocityY *时间0.5 * G * ^时间2
如果你希望你的炮弹在你需要改变Y位置公式像一些规定的高度开始:
- ÿ位置 - StartingHeight + VelocityY *时间0.5 * G * ^时间2
时间抛射运动花(即飞行)实际上是在设置速度Y中的时候,你得到等于零(因为当它重新发射时,射弹是不动的酸痛它是峰值高度)
- 速度Y = 0
- (速度* SIN(THETA))/克 达到它的峰值为射弹所需的时间是需要为它上落下的同时地面(如果它是从地面发射的,即起始高度是零)
峰值高度VelocityY通过达到峰值所需要的时间乘以
- PeakHeight = Starti ngHeight +(速度罪(THETA)-G时间)(速度罪(THETA))/ G
下面是前一阵子,当我做出尝试做同样的工作的代码片段。我用JavaFX的折线画它,因为它具有子像素精度(它需要兼作参数) 编辑:
public void getYPoints(){
int counter=0;
double time=0.0;
double yCoord=y;
while(yCoord>=0){
yCoord=yCoord+(ySpeed*time+0.5*g*time*time);
yPoints.add(yCoord);
counter++;
time+=0.01;
//System.out.printf("Y coord for time %f is %f and in arraylist is %d\n",time,yCoord,yPoints.get(counter-1));
this.time=time;
this.counter=counter;
}
//return yPoints;
}
public void getXPoints(){
double xCoord=x;
double newTime=0.0;
while(newTime<this.time){
xCoord=xCoord+xSpeed*this.time;
xPoints.add(scale*xCoord);
newTime+=0.01;
}
你可以添加一些代码,我们,所以我们可以很容易地理解? –