View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Perfect Collision between Point and Rectangle

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1rap1357  Members

Posted 18 May 2011 - 02:23 AM

Using the Separating Axis Theorem, I know how to detect if a point is inside a rectangle very easily. The problem is, if the rectangle is too small or the point is moving too fast, it is never actually inside the rectangle because in a single frame it will move to the other side of the rectangle. What is the best way to detect if the point is ever going to move through the rectangle? Basically, so that I can perfectly detect when a collision between a moving point and rectangle occurs.

Thanks

### #2jeroenb  Members

Posted 18 May 2011 - 02:57 AM

You can do it like some continuous physics libraries do it. They split of the movement of the point and divide it into smaller timesteps. Then for each step it checks if there was a collision. This works for most problems, though when you are moving tooooo fast and the rectangle quite small, it might not detect it as the resulting timeslice still is too big. You can tweak this for your game by altering the update frequency, movement speed and decreasing/increasing the timeslice of the detection system.

Crafter 2D: the open source 2D game framework

​Github: https://github.com/crafter2d/crafter2d

### #3Rene Z  Members

Posted 18 May 2011 - 03:12 AM

Or do a line segment - rectangle test, where the line segment starts at the previous position of the point and ends at the new position. That should work for all circumstances.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.