# [OT] Poll: What does it mean for 1 rect to be 'within' a certain distance of another rect?

Henk van der Velden henk at ludisstudio.com
Tue Feb 16 02:45:45 EST 2021

Alex,
No one would challenge your definition I think, but your solution only takes the corner points into account, right? So this wouldn’t give correct results in case the rectangles have different sizes or are positioned obliquely.

Henk

> On 16 Feb 2021, at 03:12, use-livecode-request at lists.runrev.com wrote:
>
> For me, a more precise problem specification is:
>
> Given two rectangles (in regular Livecode format), the distance between
> them is :
>
> ?- if they touch or overlap, distance is zero.
>
> ?- otherwise, it's the smallest distance from any point in R1 to any
> point in R2.
>
> Which leads to a simple solution
>
>> function rdist R1, R2
>> ?? local DX, DY
>> ?? put max( item 1 of R1 - item 3 of R2, item 1 of R2 - item 3 of R1,
>> 0) into DX
>> ?? put max( item 2 of R1 - item 4 of R2, item 2 of R2 - item 4 of R1,
>> 0) into DY
>> ?? return sqrt( DX*DX + DY * DY)
>> end rdist
>>
> Alex.

More information about the use-livecode mailing list