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.