I am trying to calculate the reflection of a laser within a polygon. My current calculations are probably quite long-winded because I'm building on line intersection and other functions. The problem is that I'm using a point (x,y) with velocity(x,y) and trying to calculate where the point is after each reflection off a line - this is a problem because when the point reflects within very small corners I can't seem to calculate the final location and velocity of the laser point.
Is there a well known algorithm for calculating laser reflection in 2D within polygons?
Note: I would post my code but as stated above it's extremely long ATM.
My general logic is:
Call method with particle {x,y,velocity={x,y}}
Begin loop
Check for intersections
If no intersections then exit
Get closest intersection to particle
Update particle location, direction and velocity
End loop
Refresh particle velocity (to maintain speed)
Return particle
I was hoping there something a bit more concise for this (basic?) math problem.