Message-ID: <32FA27A6.3549@pobox.oleane.com> Date: Thu, 06 Feb 1997 19:49:10 +0100 From: Francois Charton Organization: CCMSA MIME-Version: 1.0 To: Shawn Hargreaves CC: djgpp AT delorie DOT com Subject: Re: Collison detection fo Action game References: <855142026 DOT 12716 AT dejanews DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Shawn Hargreaves wrote: > > One of the simplest and fastest is to model each object as a circle. > Given the centre points of two objects (x1,y1 and x2,y1), and their > radius (radiii? what's the plural?) r1 and r2, they have collided if > sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) < sqrt(r1*r1 + r2*r2). > Shouldn't it be : sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) < r1 + r2 (distance between the two points is inferior to the sum of the radii of the two spheres?) With this formula, you should still avoid the square root: (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) < (r1+r2)*(r1+r2) which can be further simplified in ((r1+r2)-(x1-x2))*((r1+r2)+(x1-x2))>(y1-y2)*(y1-y2) this trades a multiply for an addition, which can be a little faster on some machines, especially if you use fixed point. Francois