In article <cmpRi.5736$y21.3058@[EMAIL PROTECTED]
>,
John Nagle <nagle@[EMAIL PROTECTED]
> wrote:
> Miss Elaine Eos wrote:
> > In article <jKeRi.13363$JD.3817@[EMAIL PROTECTED]
>,
> > John Nagle <nagle@[EMAIL PROTECTED]
> wrote:
> >
> >> guitarstrummr@[EMAIL PROTECTED]
wrote:
> >>> Anyone have any quick and simple code for collision detection
between
> >>> a circle and a square?
> >> Check the distances between the centers first; eliminate the case
> >> where the circle and square are far enough apart that they can't
> >> possibly touch. After that, do a signed point to line distance
calculation
> >> for each edge of the square vs. the center of the circle. If the
> >> signed distance is less than the radius of the circle for all edges,
> >> you have a collision.
> > If the signed distance is less for ANY edge of the square, right?
"All
> > edges" gives you "square contained in circle" -- right?
> >
> > (Just checking...)
> Point to line distance, which is just a dot product, is for an
> infinite line, not a line segment. It tells you which side of an
> infinite line you're on. So you have to check all the edge lines.
> (This would be clearer if I could attach an image.)
Even still -- if any two lines are nearer than radius of circle, that's
an intersection, right? You don't need the other two to be inside.
Imagine a circle with a square 45° from it, at the 10:30 position, just
barely intersecting. 1 lines in, 2 lines out.
Right? Am I missing something?
--
Please take off your pants or I won't read your e-mail.
I will not, no matter how "good" the deal, patronise any business which
sends
unsolicited commercial e-mail or that advertises in discussion newsgroups.


|