1

I have two sets of coordinates (2D vectors) on a rectangular grid. A and B. The grid has a finite width and height which are known. What i'm looking to do is get the direction from A to B, and then project that out as far as I can go, to get the farthest grid point in that direction. This will be one of the outer edge tiles

I've gotten as far as normalising (B - A), and that gives a direction. But from there I have no idea to figure out how far I can go before this line reaches the edge

The best solution i can think of is making guesses and refining it, but that seems horribly inefficient. I know at least that it's got to be shorter than the line from B to the nearest corner, but longer than the line from B to the nearest edge

Any thoughts? Point me in the right direction?

Nanako
  • 59
  • 7
  • Not sure that I understand what you need, but look [at this](https://stackoverflow.com/questions/58055629/intersection-between-a-line-and-square/58055928#58055928) – MBo Nov 08 '19 at 04:41
  • This picture from that page is pretty perfect https://i.stack.imgur.com/effhT.png Essentially, I have both of those points inside the rectangle, and i want to find the border one. There is no outside point That answer looks pretty useful, ill see if i can figure it out from that. But any farther assistance would be helpful too – Nanako Nov 08 '19 at 05:10
  • There is no difference - whether the second point lies outside or inside, algorithms remains the same. – MBo Nov 08 '19 at 05:28

0 Answers0