gpt4 book ai didi

java - 你如何计算具有初始高度的弹丸的位移?

转载 作者:行者123 更新时间:2023-11-29 04:36:21 24 4
gpt4 key购买 nike

我正在尝试制作类似 this 的模拟器在 Libgdx 中,我已经使用以下公式完成了位移 x 的计算:

enter image description here

Java 格式:

theta = Parameter.angle * 2;

range = ((float) Math.pow(Parameter.speed, 2) / Constant.GRAVITY) * (float) Math.sin(Math.toRadians(theta));

但问题是我的抛射物总是从 0.0 米的高度开始,我希望能够设置抛射物的初始高度,那么我需要什么公式?还有你如何计算位移y?

最佳答案

我也做了这个程序。您需要考虑四个主要组成部分:

  • VelocityX- 保持不变,除非您将空气摩擦考虑在内,它的计算公式为 Velocity*cos(theta)
  • VelocityY- 根据公式 Vy=Velocitysin(theta)-gtime 随时间变化
  • X位置-速度X*时间;
  • Y位置- VelocityY*time-0.5*g*time^2

如果你想让你的抛射物从某个给定的高度开始,你需要将 Y 位置公式更改为如下内容:

  • Y位置-StartingHeight+VelocityY*time-0.5*g*time^2

抛射物运动(即飞行)的时间实际上是将 Velocity Y 设置为零时获得的时间(因为抛射物在达到峰值高度时静止不动)

  • 速度 Y=0
  • (速度*sin(theta))/g弹丸到达顶点所需的时间与其落到地面所需的时间相同(如果是从地面发射,则起始高度为零)

峰高是 VelocityY 乘以达到该峰所需的时间

  • 峰值高度=起始高度+(速度sin(theta)-g时间)(速度sin(theta))/g

这是我不久前尝试做同样工作时的代码片段。我使用 javafx polyline 来绘制它,因为它具有亚像素精度(它需要 double 作为参数)编辑:

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;

}

关于java - 你如何计算具有初始高度的弹丸的位移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41312007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com