I've been mulling this problem over in my head for a while. Given an arbitrary closed 2d polygon, which is well defined, consisting of lines and curves (perhaps Bezier curves for consistency). Given a starting point and direction within the polygon. How would you go about efficiently calculating how a laser, starting at that start point, and pointing in that direction, would bounce around inside the shape?
To put this in concrete terms say you had an array which defined the shape.
- The elements of the array are either lines (start and end point), or Bezier curves (list of n points defining the curve).
- You can assume that the end of one segment will connect to the start of the next segment of the array, and that the end of the last segment will connect to the start of the first one.
- You can also assume that none of the segments intersect with one another or themself.
Here's an example array:
[
Line from (0, 0) to (1, 2),
Line from (1, 2) to (3, 2),
Bezier curve from (3, 2) to (3, 0) passing through (4, 1),
Line from (3, 0) to (0,0)
]
And we can say the laser originates at (1, 0.5) and travels directly NE.
The challenge is to build an algorithm which would follow the path of the line, calculating a list of intersections and normal values for reflection as the laser bounces around. I'd like to find a general algorithm for solving this given any input array. If you have a solution or just a helpful tip/place to start looking it would be much appreciated.