is within ... polygon shape?
Jim Hurley
jhurley at infostations.com
Fri Jun 24 11:43:34 EDT 2005
>
>Message: 15
>Date: Fri, 24 Jun 2005 07:53:22 -0700
>From: Scott Rossi <scott at tactilemedia.com>
>Subject: Re: is within ... polygon shape?
>To: How to use Revolution <use-revolution at lists.runrev.com>
>Message-ID: <BEE16C72.1AE70%scott at tactilemedia.com>
>Content-Type: text/plain; charset="US-ASCII"
>
>Recently, Steve Bonham wrote:
>
>> Intersect doesn't work after all. It appears that one object will
>> intersect with another irregular object's rect and NOT the objects
> > true shape (polygon points).
>> See illustration... at:
>> http://academics.georgiasouthern.edu/cet/SB/ball_fairway.jpg
>>
>> Is there a way to get Rev to:
>> 1. evaluate IF the loc of an object is within the shape (defined by a
>> series of coordinates) of an object?
>>
>> OR
>> 2. evaluate IF the loc of an object intersects with the shape
>> (defined by a series of coordinates) of an object?
>
>I believe some folks on the list have written collision detection routines
>that can detect intersection in several situations. I think Malte Brill
>might know something about this.
>
>That being said, collision detection on irregular shapes can work by using
>images that have a transparent background and point references. Using the
>within() function it is possible to accurately detect whether a point falls
>within the image since Rev will evaluate a point falling within the
>transparent region of the image as false.
>
> get within(img 1,myPoint)
>
>Regards,
>
>Scott Rossi
>Creative Director
>Tactile Media, Multimedia & Design
Steve,
Scott is right. The function you want is "within()", which is
different from "is within." It is very efficient.
If you want to detect whether two polygons Poly1 and Poly2 intersect,
you would first run
function firstWithinSecond grc1,grc2
put the points of grc grc1 into myPolyPoints1
repeat for each line tPoint in myPolyPoints1
if within(grc grc2,tPoint) then return "true"
end repeat
return false
end firstWithinSecond
where grc1 is Poly1 and grc2 is Poly2 and then run the same routine
with Poly1 and Poly2 reversed.
It may be that a point (vertex) of Poly2 is within Poly1, but there
is no vertex of Poly 1 which is within Poly2. You need to run both.
Or write one handler to check both.
I didn't realize it worked for points within images as well. Thanks Scott.
Jim
More information about the use-livecode
mailing list