   Point/Polygon collision question
  Hey All,I'm currently working on writing my own physics engine for the iPhone using particles as the primary dynamic structure. However, I've run into a little bit of a snag that goes something like this:I have an algorithm for detecting and responding to collisions between a particle and a plane with arbitrary normal N. I also have found that, by combining several of these planes and checking for the particle being inside all four at once, I can detect collisions with arbitrary static polygons quite easily. However, though responding to single-plane boundaries (e.g. screen boundaries) is quite easy (there is only one possible normal to respond to when a collision is detected), the problem I am experiencing now is that I don't know which plane to respond to.Example: say you have an axis-aligned box in the middle of the screen. At time t(n), the particle is outside of the box. At t(n+s) , the particle is detected inside of the box. How do I know which surface the particle collided with? All I have been able to come up with right now is whether the particle is inside or out; not <i>which</i> side it collided with.The method I have seen is to solve for the time where the collision occurred, but this seems a little difficult and computationally expensive to me. The method that would seem most logical to me for this would be to back step until the particle is back out again, but this is significantly expensive when the static shape is anything more complex than an axis-aligned box.This step of determining the proper collision normal is rather important for collision response, and &#111;ne i get that step down, a whole world of possibilities opens up. Thank you very much for your help :D.JimEDIT: By the way, this is all in 2-dimensions, to simplify :).   
  a raycast shouldn't be too hard to compute, even with non-regular polygons. So yeah, you can do a raycast, or you can try to find which side is the closest and use that.But for particles, you should really go with the swept test (solve for time).   ;  Here's the one I came up with:Do an intersection test between the segment formed by the point's previous position and current position and all of the segments in the polygon; if they intersect, then that's the side that the particle collided with:The method at here also has the side benefit of returning the point of intersection, for backstepping the particle's position. This method seems (at least to me) computationally less expensive because no distances need to be computed.Correct me if I'm wrong :).   ;  That segment collision is fine, however, you have to consider the case where the particle initially starts inside the polygon (and does not crosses an edge). 