Page 1 of 1
challenge - find nearest corners of two boxes
Posted: Sat Jan 28, 2006 9:28 pm
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
Posted: Sat Jan 28, 2006 9:37 pm
by Joakim Christiansen
Want us to do your homework?
I bet I could work out something, but not at the moment...

Posted: Sat Jan 28, 2006 9:39 pm
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?

That's simple, simply loop through all the distances and check which is the shortest.
Posted: Sat Jan 28, 2006 9:46 pm
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?

That's simple, simply loop through all the distances and check which is the shortest.
That's what I was thinking too!
Posted: Sun Jan 29, 2006 12:02 am
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...
Posted: Sun Jan 29, 2006 1:16 am
by Joakim Christiansen
We all have those days...

Posted: Sun Jan 29, 2006 3:36 am
by El_Choni
I have one of these years lately...
