delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/03/02:30:59

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: collision detection
Date: Thu, 2 Oct 1997 18:39:53 +0100
Organization: None
Distribution: world
Message-ID: <h4LLaBApx9M0Ew$4@talula.demon.co.uk>
References: <34327EAC AT relay DOT probe DOT co DOT uk>
<Pine DOT SUN DOT 3 DOT 95 DOT 971001070727 DOT 12351A-100000 AT ernie DOT eecs DOT uic DOT edu>
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

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.

- Raw text -


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