Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Collision Detection
Author Message
Clayton

Posted: Thu Mar 22, 2007 4:31 pm   Post subject: Re: Collision Detection

Wow! This is amazing, this amount of effort deserves some more bits! +400 bits sounds good for now

richcash

Posted: Thu Mar 22, 2007 9:28 pm   Post subject: Re: Collision Detection

Thanks Freakman

Well, it's not as amazing as I thought it would be before I made it. It's actually quite a bit slower than checking a point at every angle on one ellipse to be inside of the second ellipse.

However, when it comes to ellipses that are almost as big as the screen and bigger, that method becomes inaccurate. Or, if you start checking a point at every 0.1 degrees or 0.01 degrees to increase the precision, then that method becomes much slower than mine. Mine can also be used in conjuction with time-based collision, if you want to do some crazy math.

There still might be a really effiecient way to do it using geometric proprties (like I did with similar ellipses), but I can't think of one.

More sections to come.
Skynet

Posted: Thu Mar 22, 2007 10:11 pm   Post subject: Re: Collision Detection

Options I can think of:
-Approximate the ellipses with polygons
-Split your plane up into discrete parts (maybe integers mapped to screen pixels) and see if a coordinate is hit twice (Use Bresenham's line algorithm to fill the interior once you have the values of the points on the perimeter...it's really fast)
-Similar to the last, approximate perimeter of ellipses on a integer/fixed precision plane, then flood fill from the center of each ellipse. Compare result to the sum of the area of both ellipses.

I may be talking out of my ass, but these ideas seem to make sense. Of course, they're all approximations. I believe you're 100% correct in saying that the equations Maple spit out run the risk of incurring huge truncation errors, and I'd hazard a guess that approximating an ellipse in integer or fixed-point precision would produce better results. (Unless you're using something like Maple, which is powered by black magic)
richcash

Posted: Fri Mar 23, 2007 12:22 pm   Post subject: Re: Collision Detection

Skynet wrote:
Options I can think of:
-Approximate the ellipses with polygons
-Split your plane up into discrete parts (maybe integers mapped to screen pixels) and see if a coordinate is hit twice (Use Bresenham's line algorithm to fill the interior once you have the values of the points on the perimeter...it's really fast)
-Similar to the last, approximate perimeter of ellipses on a integer/fixed precision plane, then flood fill from the center of each ellipse. Compare result to the sum of the area of both ellipses.

... but these ideas seem to make sense. Of course, they're all approximations.

What you're saying does make sense, and it would be smarter to use an approximation for ellipses that are realistic sizes (can fit on the screen). Your methods are similar in performance to checking several points on one ellipse to be inside of the other ellipse (you can do this by plugging in theta at, say, every degree into the parametric equations of one ellipse). I call these collision detection by induction (I like naming things!).

Like I said before, the rounding errors occur when the ellipses are too skinny (say that one ellipse's major axis is 20 times larger than its minor axis) or if the ellipses are too small (have radii under 10). But for huge ellipses, my function thrives. I tried out my function on two ellipses : one was 3000(x-radius) X 800(y-radius) and the other was 2000 X 500. It detected the collision perfectly with no loss of speed. Any above methods would become much worse than my function with these ellipses and larger.

It's possible that there is an effiecient function out there using geometric properties, but I can't think of one and a quick internet search resulted in nothing. So I say just use my long function only for massive ellipses.
Flipmc

Posted: Fri Jan 30, 2009 6:30 pm   Post subject: RE:Collision Detection

Wow! Thanks for this!
I'll need it sooner or later.
DanielG

Posted: Fri Jan 30, 2009 7:16 pm   Post subject: RE:Collision Detection

massive necro, good tutorial though.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 3 of 3  [ 36 Posts ]
Goto page Previous  1, 2, 3
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: