cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/06/14:05:24

Message-ID: <32FA27A6.3549@pobox.oleane.com>
Date: Thu, 06 Feb 1997 19:49:10 +0100
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
CC: djgpp AT delorie DOT com
Subject: Re: Collison detection fo Action game
References: <855142026 DOT 12716 AT dejanews DOT com> <vgpI$hAr7O+yEwGt AT talula DOT demon DOT co DOT uk>

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019