I would really appreciate any help and ideas from all you Java gods with regards to the following 2D problem:
1. How do I detect AND recover from a collision between arbitrary polygons (convex or concave with more than 3 vertices) in 2D rotating and moving directionally at different speeds?
I was thinking of checking each line segment generated from each BEFORE MOVING vertex of polygon A to the AFTER MOVING vertex, against all the edges of the polygon B. The process is then repeated for polygon B "moving" in the opposite direction. Very brute-force I know, but at least it solves the speed problem with collision detection.
I've linked a pic to illustrate: http://www.imagedump.com/index.cgi?pick=get&tp=49876&poll_id=0&a
In the picture, the red line segments generated from the movement are checked against the blue edges of the green polygon. The red circles represent the point of intersections.
1. To detect collision during DIRECTION MOVEMENT at arbitrary speeds, i find the before and after coordinates and use the above algorithm. To correct the movement, I find the point of intersection with the least displacement from the original vertex and translate the polygon there instead.
2. To detect collision during ROTATION at arbitrary speeds, i would use the exact same process, with the exception that line segments are now rotation arcs.
My big and ugly problem is that I can't find a neat and (somewhat) efficient algorithm to compute the angle I must "un-rotate" to get the correct displacement. Since I'm hardly a mathematician, the algorithm I have, in a word, sucks.
Can anyone help with the algorithm? Is this even a good way to get around the problem? :-/