Let P1=[x1,y1] and P2=[x2,y2] be the two endpoints of a line segment of the reflecting "wall", and let P3 = [x3,y3] be a point on a ray with vector v = [v1,v2] pointing from P3 along the ray. Assume that the ray will intersect the given line segment. The point of intersection, P4, of the ray with the wall segment will be:
t = ((y2-y3)*v1-(x2-x3)*v2)/((x1-x2)*v2-(y1-y2)*v1);
P4 = t*P1+(1-t)*P2;
[Note #1: If t lies outside the interval [0,1], then the ray doesn't actually intersect the segment.]
The point, P5, at the mirror image of P3 with respect to the line perpendicular to the segment at P4 will be:
P5 = P3+2*dot(P4-P3,P2-P1)/dot(P2-P1,P2-P1)*(P2-P1);
Thus, the reflected ray proceeds from P4 and goes through P5.
[Note #2: This just gives the direction of the reflected ray from P4 toward P5. It doesn't matter if P5 lies outside the other parts of your "wall".]
Best Answer