challenge - find nearest corners of two boxes

Everything else that doesn't fall into one of the other PB categories.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

challenge - find nearest corners of two boxes

Post by blueznl »

here's a nice one: imagine you have two boxes, with known coordinates and sizes x1,y1,w1,h1 and x2,y2,w2,h2

these two are non-overlapping

now how can you find the two corners that are nearest to each other? (that's one corner on each box, obviously :-))

for bonus points, how do you check if they are not overlapping?

sorry, no price attached
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Want us to do your homework?
I bet I could work out something, but not at the moment... :P
I like logic, hence I dislike humans but love computers.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I don't understand the problem. Do you mean like finding the two circled corners because they are the ones that are closest to each other?
Image
That's simple, simply loop through all the distances and check which is the shortest.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Trond wrote:I don't understand the problem. Do you mean like finding the two circled corners because they are the ones that are closest to each other?
Image
That's simple, simply loop through all the distances and check which is the shortest.
That's what I was thinking too!
I like logic, hence I dislike humans but love computers.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

well, that's actually the way i solved it now, but that was after a long detour thinking up all sorts of wrong solutions :-) i was wondering if other people would be smarter than that (appearently: yes :-))

checking if two rectangles overlap provided to be surprisingly easy though...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

We all have those days... :wink:
I like logic, hence I dislike humans but love computers.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

I have one of these years lately... :D
El_Choni
Post Reply