
I am trying to figure out the formula for finding where my grey lines intersect with the green box (circled in red). This would be for any grid or coordinate system. Orange represents a single point within a set of points and green represents the coordinate system minimum and maximum point range. The grey lines represent cardinal and diagonal direction. We are trying to find the formula that calculates at which point each direction would intersect maximum or minimum bounds based on a direction value from a single position within the bounds.
All you have to do is get the distance between you and the boundary, then subtract that from your coordinate in the other direction. So if you measure the distance to the boundary north, you would subtract that from your X
To figure out which side to use you could test the sum of your x and y coordinates for northwest/southeast diagonals, and for the other direction...wait I'm confused. I have to run to the store...
:P
EDIT: Okay I'm back and I figured it out. For northeast/southwest diagonals, just test if x > y or if x < y. Here's a quick diagram to show what I mean: