Implementing Projectile Motion

后端 未结 4 1519
轻奢々
轻奢々 2021-01-05 02:27

I\'ve scored the internet for sources and have found a lot of useful information, but they are math sites trying to tell me how to solve what angle an object has to be at to

4条回答
  •  迷失自我
    2021-01-05 03:10

    While Benny's answer is good, especially in its generality, you can solve your problem exactly rather than using finite integration steps. The equation you want is:

    s = u*t + 0.5*a*t^2;
    

    Look here for an explanation of where this comes from.

    Here s is the displacement, u is the initial speed, a is the acceleration and t is time. This equation is only 1 dimensional, but can be easily used for your problem. All you need to do is split the motion of your projectile into two components: one parallel to your acceleration and one perpendicular. If we let Sx describe the displacement in the x direction and Sy the displacement in the y direction we get:

    Sx = Ux*t + 0.5*Ax*t; 
    Sy = Uy*t + 0.5*Ay*t;
    

    Now in your particular example Ax is 0 as the only acceleration is due to gravity, which is in the y direction, ie Ay = -g. The minus comes from the fact that gravity will be acting in the opposite direction to the original motion of the object. Ux and Uy come from simple trigonometry:

    Ux = U*cos(angle);
    Uy = U*sin(angle);
    

    Putting this all together you get two equations describing where the projectile will be at a time t after being launched, relative to its starting position:

    Sx = U*cos(angle)*t;
    Sy = U*sin(angle)*t - 0.5*g*t^2;
    

提交回复
热议问题