Distance between 2 rectangles.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

paul@researchware.com
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Wed Aug 26, 2009 7:42 pm
Contact:

Re: Distance between 2 rectangles.

Post by paul@researchware.com » Tue Feb 16, 2021 7:32 pm

Well! I was only asking about Rectangles, but, yes it can be done for blobs too :-)

I've closed my un-scientific poll over on the USE-LIST. The consensus is (as Richard chimed in) nearest edges, vertices, or (for blobs) points). While there are certainly a *lot* of ways to figure distance between rectangles, most people apparently do think of distance as being between nearest points. So thank you everyone here and on the USE-LIST for this. Much appreciated.
Paul Dupuis
Researchware, Inc.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Distance between 2 rectangles.

Post by richmond62 » Tue Feb 16, 2021 7:53 pm

if you have two weird graphics
Indeed.

But, suppose (just to justify my reputation for being a pain-in-the-bum), you had two amorphous shapes that were NOT graphics:
is there a way one could derive edges based on their transparency thresholds?
-
Screenshot 2021-02-16 at 21.06.13.png
-
And I don't just suppose, there is any chance of working out how one might trace a PNG image and end up with a vector inwith LiveCode.

The fact that one can do this in Inkscape (an open source program) may point the way to future ideas.

https://inkscape.org/
Attachments
Blobs.livecode.zip
Here's the stack.
(5.71 KiB) Downloaded 283 times

SparkOut
Posts: 2946
Joined: Sun Sep 23, 2007 4:58 pm

Re: Distance between 2 rectangles.

Post by SparkOut » Tue Feb 16, 2021 8:18 pm

Just for the helluvitt (no serious attempt to help here)

A pseudo-method to approximate Richmond's island blobs measurement: (Away in the Western Isles with only a phone, can't see what the stack produces but I suspect it is more to do with edge detection than measurement. )
Measure from the centre of one rectangle or blob to "every" point on the perimeter of the other. For the shortest, note the point on the perimeter of the target shape. Then do the same for the other in reverse. Measure the distance between the two points noted.
Last edited by SparkOut on Tue Feb 16, 2021 8:21 pm, edited 2 times in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Distance between 2 rectangles.

Post by dunbarx » Tue Feb 16, 2021 8:19 pm

Richmond.

I used curve graphics from the tools palette, which gave me points for free. If you use one of those fancy imported gadgets, I doubt you will find that feature, or rather, property.

You can raster- scan the card window, logging changes in color, and collect those points, but then you need to manage that so only the change from "white-to-color" and "color-to-white" are logged, or you will end up with a LOT of points. This seems simple enough.

Anyway, once you have those points, my handler should work the same.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Distance between 2 rectangles.

Post by dunbarx » Tue Feb 16, 2021 8:22 pm

Sparkout.
Measure from the centre of one rectangle or blob to "every" point on the perimeter of the other. For the shortest, note the point on the perimeter of the target shape. Then do the same for the other in reverse. Measure the distance between the two points noted.
See my post just above.

The question is: do these imported blobs have extractable perimeter points? They certainly have a fixed shape, and a computer must need something like those those in order to draw it at all. I am just asking.

Craig

SparkOut
Posts: 2946
Joined: Sun Sep 23, 2007 4:58 pm

Re: Distance between 2 rectangles.

Post by SparkOut » Tue Feb 16, 2021 8:25 pm

Er... I see you actually coded my pseudo method. Duh!
Well done. And yes, the question is something completely different now.

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am

Re: Distance between 2 rectangles.

Post by Davidv » Tue Feb 16, 2021 11:05 pm

Knowing that the question is about how most people might think of the distance between the rectangles, I think my query about overlap still needs an answer. If overlap is permitted, then consider these:
rectangles.png
rectangles.png (6.12 KiB) Viewed 7289 times
If we are discussing edges or vertices then is the second a greater negative offset or similar? Does it depend on a direction of movement before the overlap? Now, centres make more sense. Perhaps it is that we can truncate processing on finding any overlap. It depends on the game or other context.

[No, I was not Finn. I was fast asleep at the time :)]

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Distance between 2 rectangles.

Post by bogs » Tue Feb 16, 2021 11:21 pm

Davidv wrote:
Tue Feb 16, 2021 11:05 pm
[No, I was not Finn. I was fast asleep at the time :)]
...and I am all of the time, don't let the eyes being open fool you! :twisted:

Your examples are why I was wondering if it weren't centers being discussed, but apparently they just wanted to know 'what do most people think your measuring'.

I dunno how you would come up with an answer to that question, short of asking a large % of the world's population what they think.
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Distance between 2 rectangles.

Post by dunbarx » Wed Feb 17, 2021 3:33 am

Overlaps can be reckoned if you simply remove the "abs" function from my handler. You will then get both positive and negative distances. Negative ones will be overlap distances.

As for what constitutes "closeness", I would bet 99% of the planet would say edges to edges, centers never occurring to anyone at all.

Craig

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Distance between 2 rectangles.

Post by bogs » Wed Feb 17, 2021 11:46 am

You might bet that, but suspecting something doesn't prove it.

I might bet that the greater number of people in our country know right from wrong, but visually it appears to be a 50/50 thing, if you see what I mean. I'm pretty sure neither my suspicion nor the visual evidence is conclusive.

Other questions that *might* seem likely bets for the 99% target would be
Whether the earth is spherical
Whether the earth orbits the sun
What comprises true wealth.

I don't know any of those for sure, I only know that people seem to believe one or the other, or in some cases, something completely different :twisted:
Image

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am

Re: Distance between 2 rectangles.

Post by Davidv » Wed Feb 17, 2021 12:09 pm

dunbarx wrote:
Wed Feb 17, 2021 3:33 am
Overlaps can be reckoned if you simply remove the "abs" function from my handler. You will then get both positive and negative distances. Negative ones will be overlap distances.
Craig, looking at my image examples, would not your code produce the same number in each case (I haven't tested it), one negative and one positive (or both positive and the same if using abs)?

If we are guessing general views of closeness, then I will conjecture that once overlap occurs, degree of same becomes the highest priority; that is, people would mentally switch from edge closeness to centre closeness. As I said earlier, this may be immaterial. It depends on context.

David

Post Reply