I have a perfect 2D system, with no friction, elasticity, etc. A ball is colliding with a rectangle. I know the angle of the motion of the ball in degrees. I want to figure out how said angle will change upon collision. I determine the angle of collision by averaging angles of a bunch of points in the intersection. What do I do with these two angles? Maybe I also have to determine if the corner is in the intersection as well and handle it differently? Also, the angles con be larger than 360. It doesn't matter for movement, since it's in polar coordinates, but it may hinder calculations?
1 Answer
The edges of your rectangle are just straight lines, so the angle of reflection is equal to the angle of incidence:
Now, if this surface has its own angle, we can factor that in. Call the angle of incidence/reflection θ and the angle of the surface Φ:
So our new angle is θ + Φ. But how do these relate to the angle of the original vector? Let's call that α:
Then we have, from the sum of the interior angles and the supplementary angle of Φ:
α + θ + (π - Φ) = π
α + θ = Φ
and the angle we want is
θ + Φ = 2 Φ - α
where, to reiterate, α is the angle of our incoming object and Φ is the angle of the reflecting surface.
For inside corners, you can consider that as two reflections off of surfaces that are at an angle of π/2 to each other, resulting in a turn of π (back in the direction it came from).
For outside corners, you can consider the plane of reflection as perpendicular to the vector to the point of contact:
This time μ is the angle of the vector drawn from the ball's center to the point of collision. So now
Φ = μ + π/2
and the resulting angle is
2 Φ - α = 2 μ + π - α
where, again, α is the direction of motion and μ is the angle from the center of the ball to the point of contact.