1. ## Reflecting particle

Hi guys

For my 2 year project I have decided to make a particle simulator and so far so good
But I want the particle to bounce when it hits a side. Now this is a little complex as i need to have a formula that calculates the gradient and direction of the bounced particle.

I hope this makes sense, thanks!

(for example, how does pong get the ball to bounce)

2. Well, change the direction. IE if it hits the right side, it is now travelling in the original y, and the inverse x. You can figure out the other sides using similar logic. So keep some speed, and on update set x += speed * dx and y += speed * dy.

Other then this simpler route you can keep track of the angle of the particle, relative to some axis, and use the trig functions to figure out the new position.

3. Well, change the direction. IE if it hits the right side, it is now travelling in the original y, and the inverse x. You can figure out the other sides using similar logic. So keep some speed, and on update set x += speed * dx and y += speed * dy.
For that you'll need two speed variables speedX and speedY, or perhaps a vector with two components.

But most of the better implementations of pong use something more than that. You could for instance do it using some trig as mentioned above.

If you want to reflect the particle against a plane, then you'll have to use the get the dot product between your vector and the normal and calculate the new direction. Something like -

Code:
`R = V - (2 * N * dot(V, N));`