Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Misc > Re: Circle - Sq...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 12 Topic 948 of 1011
Post > Topic >>

Re: Circle - Square Collision Detection

by John Nagle <nagle@[EMAIL PROTECTED] > Oct 17, 2007 at 02:48 AM

guitarstrummr@[EMAIL PROTECTED]
 wrote:
> Anyone have any quick and simple code for collision detection between
> a circle and a square?

    Check the distances between the centers first; eliminate the case
where the circle and square are far enough apart that they can't
possibly touch.  After that, do a signed point to line distance
calculation
for each edge of the square vs. the center of the circle.  If the
signed distance is less than the radius of the circle for all edges,
you have a collision.

    Work with squared distances; don't bother with the square roots.
See "http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html",
eq. (11), but don't bother with the absolute value.  Pick a consistent
winding order (clockwise or counterclockwise) for the edges of your
squares,
so a positive signed distance will always indicate "outside".   It's
mostly adds and multiplies; few divides, no trig functions.

    If you have to rotate and translate the square and circle, find
a site that explains basic graphics math and learn how to use rotation
matrices.

				John Nagle
 




 12 Posts in Topic:
Circle - Square Collision Detection
"guitarstrummr@[EMAI  2007-10-15 20:25:18 
Re: Circle - Square Collision Detection
Luc The Perverse <atay  2007-10-16 08:20:43 
Re: Circle - Square Collision Detection
John Nagle <nagle@[EMA  2007-10-17 02:48:47 
Re: Circle - Square Collision Detection
Luc The Perverse <atay  2007-10-17 00:48:52 
Re: Circle - Square Collision Detection
Miss Elaine Eos <Misc@  2007-10-17 14:35:19 
Re: Circle - Square Collision Detection
John Nagle <nagle@[EMA  2007-10-17 08:09:10 
Re: Circle - Square Collision Detection
Miss Elaine Eos <Misc@  2007-10-17 15:24:12 
Re: Circle - Square Collision Detection
John Nagle <nagle@[EMA  2007-10-18 08:47:04 
Re: Circle - Square Collision Detection
Miss Elaine Eos <Misc@  2007-10-19 02:45:55 
Re: Circle - Square Collision Detection
John Nagle <nagle@[EMA  2007-10-21 04:43:06 
Re: Circle - Square Collision Detection
Richard James <IWillGe  2007-10-19 16:59:54 
Re: Circle - Square Collision Detection
Anton <anton.txt@[EMAI  2007-10-28 22:57:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 8:44:02 CDT 2008.