From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: collision detection Date: Thu, 2 Oct 1997 18:39:53 +0100 Organization: None Distribution: world Message-ID: References: <34327EAC AT relay DOT probe DOT co DOT uk> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 22 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Andrew Deren writes: >Thanks a lot it works. Would you by any chance also know how to detect a >rectangle with a circle. I can think of a few ways to bodge this, but no good solutions jump out at me. Try comp.graphics.algorithms or rec.games.programmer, they are the best places for this kind of question... The most obvious method (very inefficient but I think it will work), is to subdivide the problem into a couple of different cases. For an intersection, either the centre point of the circle must lie inside the rectangle (simple point in box test), or one of the edges of the rectangle must intersect the circle. To detect that, loop through the four edges of the rect, measuring the distance from each edge to the centre of the circle (distance from point to line, see comp.graphics.algorithms FAQ), and checking whether it is less than the radius of the circle... -- Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/ Beauty is a French phonetic corruption of a short cloth neck ornament.