I have a point that is always outside of my square. I know the x and y coordinates of my point. I also know the x and y coordinates of the top left corner of the square and the length of the sides of the square. All of these values are variable, but always known.
The point can be at any location around the square, but it will always be outside of it.
I'm pretty bad at math, I've found similar questions and answers, but nothing that actually makes sense or that I can understand.
So I'm looking for a formula that will calculate the distance between my point and the closest point on the edge of the square.
Say the top-left corner is $(a,b)$ and your point is $(x,y)$. Say the side of the square is of length $L$.
If $y\geq b$ and $a\leq y\leq a+L$, the point lies "above" the square, the distance is $y-b$.
If $a+L\leq x$ and $b-L\leq y\leq b$, the point lies on the right of the square, the distance is $x-(a+L)$.
There are two other cases like this. Can you do them?
There are three other cases like this.