To express my regret for not having posted recently, I'm going to explain my method of polygon collision detection and response.
It's quite simple really. For polygons described in a series of points and a single test point, here's a description of the algorithm I use to move that point the shortest distance outside the polygon:
- Assume the current closest point is infinitely far away.
- For every single line segment between the points:
- Find the point closest to the test point on that segment. You can use whatever method you wish for this part. This part's just a little bit of vector calculus. Here's a hint: if the closest point is not one of the endpoints on the segment, the vector to it from the test point will be perpendicular to the segment.
- If that point is closer to the test point then the current closest point, then it becomes the current closest point
- The current closest point is the fastest way out of the polygon.
No comments:
Post a Comment