From: Rob Farley Newsgroups: comp.os.msdos.djgpp Subject: Re: collision detection Date: Tue, 14 Oct 1997 17:43:31 +0100 Sender: Rob Farley Distribution: world Message-ID: References: NNTP-Posting-Host: pulsedesign.demon.co.uk MIME-Version: 1.0 Lines: 43 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article , G DOT DegliEsposti AT ads DOT it writes > > > > > >Hello everybody. > >Andrew Deren wrote: >> >> Does anyone know how to detect if two rectangles overlap each other at >> some point. Let's say we have something like this: >> >> typedef struct RECT { >> int x1, y1, x2, y2; >> } RECT; >> >In many years I have seen it is not possible to solve this problem without >lots >of tests, unless you have some special conditions (and usually you have not >:-) > >You have to test for all vertices of A beeing inside B *and* all vertices >of B >beeing inside A, otherwise you can have particular cases where it does not >work. This maybe going sideways, but, if you use circles instead of rectangles then all you use is a bit of pythagoras. If you've got a circle with radius of r1, and a centre at x1,y1, and another of radius r2, with a centre at x2,y2, then: (x1-x2) squared (y1-y2) squared Add them up the square root, then, if the answer is smaller than r1+r2 then they are colliding, then after that you may want to do a more accurate test. Hope this is of some use. -- Rob Farley