Date: Thu, 1 Dec 1994 23:14:38 -0600 From: Matthew Caldwell <sexkittn@BURN.DEMON.CO.UK> Subject: Re: circular constraints, anyone?Rather than using a list of coordinates, you can check whether a point is within a particular circle with a handler like this:
-- Ch and Cv are the coords of the centre of the circle
-- and r is its radius
-- while aPoint is a point in the form [h,v] or point(h,v)
on isPointInCircle aPoint, Ch, Cv, r
set x = getAt(aPoint,1) - Ch
set y = getAt(aPoint,2) - Cv
return (x*x + y*y) <= (r*r)
end isPointInCircle
To check whether a point is within a ring, use this:
-- as above, but outR is the radius of the outer boundary
-- and inR is that of the inner boundary
on isPointInDonut aPoint, Ch, Cv, outR, inR
set x = getAt(aPoint,1) - Ch
set y = getAt(aPoint,2) - Cv
return ((x*x + y*y) <= (outR*outR)) and ((x*x + y*y) >= (inR*inR))
end isPointInDonut
To check whether a whole rect (eg, that of a sprite) is within a circle,
use the above handler on each of its corners
on isRectInCircle aRect, Ch, Cv, r
put getAt(aRect,1) into leff
put getAt(aRect,2) into topp
put getAt(aRect,3) into rite
put getAt(aRect,4) into bott
if isPointInCircle([leff,topp], Ch, Cv, r) then
if isPointInCircle([rite,topp], Ch, Cv, r) then
if isPointInCircle([leff,bott], Ch, Cv, r) then
return isPointInCircle([rite,bott], Ch, Cv, r)
end if
end if
end if
return 0
end isRectInCircle
Changing this for donuts is obvious.
____ \ / Matthew Caldwell <sexkittn@burn.demon.co.uk> \/ Hey Betty, is that Jimmy's ring you're wearing?