adjacent objects

-hh hh at livecode.org
Sun Dec 6 20:35:31 EST 2015


Hi Richmond and Walt,

I tried to find out your definitions of "adjacent".

Walt has its own clever situation-dependent, sometimes self-adapting definition of 2D- or 3D-neighbourhoods, perhaps too complicated for your project.

You, Richmond, think at first of 'nearby' rects.
I suggest to do that with LC's intersect in the following way. It's just an idea.

Give each of your object the points of a surrounding "inflated polygon" as custom property, changing with each change of the object's rect:

d is the non-negative "inflation amount", r the rect of the object1. The (hidden) *opaque* polygon "poly1" has points
-d+item 1 of r, -d+item 2 of r
 d+item 3 of r, -d+item 2 of r
 d+item 3 of r,  d+item 4 of r
-d+item 1 of r,  d+item 4 of r
-d+item 1 of r, -d+item 2 of r

Having done that for each object use for example
if intersect (poly1, poly2, "opaque pixels")
to check for 'adjacency' of object1 and object2.

Note that d could be set in an adaptive way, dependent of a game status, or as a fixed proportion of a size parameter of the object or the card or ...

For more complicated shaped 2D-objects than rects one could create surrounding N-gons or surrounding (elliptic) ovals and check with these, using again LC's intersect.

TMO, LC is when creating polygons (even "on the fly") and checking objects for intersection pretty fast.

Hermann



More information about the use-livecode mailing list