# Need help for computer science coursework - motion and gravity

1. Feb 14, 2014

### gutti

I'm not a physics student and haven't done any physics work since high school. I've since then forgot most of what I knew and although while researching this problem, everything looks familiar. It just doesn't fit together in my head. This isn't a marked piece of the coursework it's just involved and the coursework really doesn't work without it.

I am making a pinball simulation and need to calculate the motion of a ball. At all times I can get the coordinates of the ball (which I don't think really matter, the velocity(speed and angle of movement) and I am given a value for gravity which is 25 L/ms^2 where L is some unit of distance.

On each tick of the program the ball will move and then gravity must be applied to it.

I need to calculate the new angle the ball will be moving at and the new speed of the ball.

Could someone tell me which equations I would use to calculate this.

2. Feb 14, 2014

### jackarms

This isn't really the section of the forums to ask this, but I'm happy to answer it anyway. Luckily motion is pretty easy to set up in a program. If you use vectors to represent position, velocity, and acceleration, it becomes quite simple.

For each tick you choose which forces to apply to which objects (in your case the pinball), and calculate the resulting acceleration from Newton's Second:
$$a = \frac{F}{m}$$
Or, in a case like gravity where acceleration will always be the same value, you can just change the acceleration vector directly.

Then, on each tick, just add the acceleration vector to the velocity vector, then add the velocity vector to the position vector. There are other ways to do it, say if you wanted to move things forward a certain time value each time, but this is the simplest, I think. Also, make sure you set the acceleration vector to null on each frame (or reset it to something like the acceleration from gravity) so that you don't accumulate values in the vector each frame.

Then you can calculate the speed and angle from the velocity vector. (Speed is the magnitude of the vector, angle is the direction of the vector)

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted