# Reflection off both sides of a line

This topic is 2451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone,

I'm working on a breakout style game, and I've gotten myself stumped by a math problem that's likely trivial for the folks around here.

In the game, my ball's travel is defined by an angle and velocity. For the sake of clarity, I'm using degrees in my code and converting to radians when necessary. Unlike most breakout games, my paddles can be at any angle. They're defined by x and y points for both ends of the paddle, and I can derive their angle just fine, but they can rotate a full 360 degrees as the points at the ends can move independently.

I've been calculating the ball's angle of reflection off the paddle by using the following:

ball angle = (paddle angle * 2) - ball angle

This works just fine if the ball approaches the paddle from the correct side, but my attempts to detect the side and rotate the paddle angle 180 degrees when necessary have not proven fruitful.
I've been detecting the side by checking the sign of the following equation:

Could any of you help me work out an equation that will generate an accurate angle of reflection off the paddle at any rotation?

##### Share on other sites
Typically this would all be done using vector math rather than trig and angles.

As for your specific question, it sounds like it's vector reflection that you're looking for. To reflect a vector v with respect to a unit-length vector n, you can use the following formula (typed into post, so no guarantee of correctness):

v' = v - 2(v.n)n