Shortest distance between a rectangle and a point

Iamadam

New member
Joined
Feb 20, 2006
Messages
26
Hello :)

I have a rectangle (of any given size) who's sides run parallel to the x and y axes.
I then have a point, outside of this rectangle. I need to find the shortest distance between that point, and the given rectangle.
I know it will (obviously) lie somewhere on the perimeter, but I am unsure of how to figure it out. Any help would be appreciated

- Adam :D
 
Well..... the shortest distance is a straight line: so any point within the outer region's x and y field of view will have a point whose x coordinate hits the x parameter coordinate.... or those y coordinate hits the parameter y coordinate.

And then use the distance formula sqrt( (x2-x1)^2 + (y2-y1)^2 )

If the point is beyond the outer edges of the x and y parameter's field of view.... such as my green dot going diagonal than how would you solve for this distance?

The shortest distance of any point outside the parameter's x / y field of view will alway have the closest corner of the rectangle as its target.


Do you see why?



block.png
 
Ah, thanks a lot :) I was hoping there was some formula I could just plug values into - but this is nice and easy too. Thanks!
 
Top