We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › 2D collision detection
Page Index Toggle Pages: 1
2D collision detection (Read 1952 times)
2D collision detection
Mar 24th, 2010, 5:48pm
 
Is there any utility available for doing 2D collision detection? Just the simple case of given a bunch of rectangular regions, testing whether a new rectangle would overlap with any of these?
Re: 2D collision detection
Reply #1 - Mar 24th, 2010, 8:14pm
 
you can search for "rectangle collision detection" :)
Re: 2D collision detection
Reply #2 - Mar 25th, 2010, 1:11am
 
Re: 2D collision detection
Reply #3 - Mar 25th, 2010, 8:45am
 
BenHem: Yes I did search for "rectangle collision detection", did not find any thing obvious, may be I missed something?

nardove: may be I should made myself clearer: I need to do collision detection for many (n=10^5 at least) items repeatedly, so each detection should take log(n) time. Some kind of quadtree/rb tree structure. I am trying to avoid reinventing the wheel, if there is already a utility like that in the processing community.

Thanks.
Re: 2D collision detection
Reply #4 - Mar 25th, 2010, 2:33pm
 
Hi,

the check does not compound logarithmically -- the new rectangle would just be tested against all existing rectangle bounds -- unless I misunderstand your intentions.

for (int i=0; i< [number of existing rectangles]; i++){
 (does this new rectangle overlap with rectangle i  If so, do stuff)
 else do other stuff
}

Re: did you miss something -- I don't know -- the first Google hit for me is this:
http://www.gamedev.net/reference/articles/article735.asp -- the top example there is basic rectangle overlap detection.
Re: 2D collision detection
Reply #5 - Mar 26th, 2010, 3:15am
 
I am assuming that I want to check if a rectangle collides with n existing rectangles, and assuming that these n rectangles do not move. A data structure can be set up in time O(n), and once set up, each check is O(log(n)). See

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.59.7766

Page Index Toggle Pages: 1