How do I find a points distance from a rectangle that is defined by half-width/height, two vectors and a middle point?

165 Views Asked by At

So I've been trying to figure this out for days and I feel like I'm close but I think the solution I came up with only works for a rect that is aligned to a vertical/horizontal axis because the rect my program drew was not rotated.

Also, I'm not sure how the rotation is being represented: There are two directional vectors given along with the half-width/height and middle point of the rectangle, are these supposed to represent the rotation of the rectangle? If so, how do I determine the rotation from these two vectors, dot product?

1

There are 1 best solutions below

2
On

First translate the point and the rectangle to center the rectangle on the origin, and counter-rotate to make the rectangle axis-aligned. (Moving a corner to the origin also works.)

The extended sides of the rectangle define nine regions of the plane, and depending on the region the closest point is either on the nearest edge or is the nearest corner.

These are elementary computations.

enter image description here