An algorithm for determining the angle of incidence.

read more

Terminal point and initial point.

Terminal point may not be on the same side or as the initial

I found a formula (looked up). 180+2*(normal to the wall) - current = result

If result/360>1, -360.

Determining the normal to wall (0,270,180,90):

If 0<angle before current<90 and current >180, wall = 90.

If angle before current <180 and current <180, wall = 270

If angle before current >180 and current <180

All of the above may not work, determining the normal to the wall is difficult. An alternative would be finding which wall the object comes into contact with by finding the distance from each of the sides, and then based on the current angle, determine which it hits. For instance, if distance from the top/1/a(cos(theta))