How to code the projectile of a ball of different force and angle in Java Swing?

后端 未结 3 556
眼角桃花
眼角桃花 2020-12-01 20:36

I have written the following function for projectile motion of different force and angle, but it doesn\'t work properly. Where have I gone wrong? I want something like the A

3条回答
  •  抹茶落季
    2020-12-01 20:59

    The formulae you created for x- and y-displacement are both missing a time factor in the first term. Below, I placed your code above and the correct code below, for comparison, so you can see exactly what you left out.

    For X Displacement

    • (ball.getX()+10)*Math.cos(radians)+ ...
    • (ball.getX()+10)*time*Math.cos(radians)+ ...

    For Y Displacement

    • (ball.getY()+10)*Math.sin(radians)+ ...
    • (ball.getY()+10)*time*Math.sin(radians)+ ...

    I referenced Wikipedia's equation for displacement as a function of radians to answer your question.

提交回复
热议问题