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.
Distance between 2 rectangles.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
paul@researchware.com
- VIP Livecode Opensource Backer

- Posts: 153
- Joined: Wed Aug 26, 2009 7:42 pm
- Contact:
Re: Distance between 2 rectangles.
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.
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.
Researchware, Inc.
-
richmond62
- Livecode Opensource Backer

- Posts: 10200
- Joined: Fri Feb 19, 2010 10:17 am
Re: Distance between 2 rectangles.
Indeed.if you have two weird graphics
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?
- -
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 301 times
Re: Distance between 2 rectangles.
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.
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.
Re: Distance between 2 rectangles.
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
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
Re: Distance between 2 rectangles.
Sparkout.
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
See my post just above.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.
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
Re: Distance between 2 rectangles.
Er... I see you actually coded my pseudo method. Duh!
Well done. And yes, the question is something completely different now.
Well done. And yes, the question is something completely different now.
Re: Distance between 2 rectangles.
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:
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
]
[No, I was not Finn. I was fast asleep at the time
Re: Distance between 2 rectangles.
...and I am all of the time, don't let the eyes being open fool you!
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.

Re: Distance between 2 rectangles.
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
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
Re: Distance between 2 rectangles.
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
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

Re: Distance between 2 rectangles.
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