# Require maths help calculating deflection angles of quadrants

For each quadrant, I need to find a neat way of calculating the deflection angle for a small circular object striking a circle, as shown in the diagram.

• Angles a and b are already known.
• Angle a is always relative to 0 degrees position.
• Angle b is relative to the quadrant.
• The initial angle can also be greater than 180, when coming from the other direction, as shown in the diagram the right.

For quadrant 2, in the following snippet from my code, dy and dx represent the x and y coordinates of a point on the circle:

intersectAngle = atan(dy/dx);

Initial angle is calculated from velocity vectors:

pAngle = PI - (atan2(pVel.x, pVel.y));

For quadrant 0, I came up with this for the rebound angle:

pAngle = pAngle - 2 *(pAngle - tangentAngle);

Where tangentAngel is just the intersect angle with half PI added. Thsi worked for a ball from any direction.

Moving onto quadrant 1, this works for pAngles of less than 90 deg, but not for pAngles from the other direction:

pAngle = pAngle + 0.5 * PI - intersectAngle;

Feels like I shouldn't be writing all this code and that there is a more efficient way. I realise this is an elementary question but I'm studying this so it's all new to me. Please be gentle.

It seems like you are just reflecting the vector and it would be easier to do so, as such, than manually fiddle with quadrant math. I think you have access to vectors but, if it's a project constraint, I can modify this to use only basic scientific calculator functions. V1 relates to angle a and V2 relates to angle b. All vectors should be normalized.

This works for any vector, in any quadrant:

1. I believe V1 is pVel, normalized.
2. I believe V2 is {dx, dy}, normalized.
3. V3.Dot(V2) == -V1.Dot(V2)
4. The angle between V3 and V2 is acos(-V1.Dot(V2))
5. The angle between V3 and '0' is acos(-V1.Dot(V2)) + b
6. Post-collision velocity is V3 * the original magnitude of V1

This could happen if you detect the wrong collision first (very little implementation detail included):