Let's say I have a 2D coordinate space defined by $-5 \leq x,y \leq 5$.
Then let's say I have coordinates $(x_1,y_1)$ and $(x_2,y_2)$ for a line that will run from $(4,4)$ to $(6,7)$.
How do I truncate that line so that it ends at the edge of the coordinate space (but maintains the same slope)? In other words, how do I get the values for $(x_2,y_2)$ so that $y_2$ is 5 (the maximum it could be)?
I originally thought that just using the percentage change in the highest of the out of boundary coordinates would do the trick (e.g. $(X_{max})({x_2}/{y_2})$), but I get a different slope.
If things change when x or y goes negative I need to account for that too.
thank you for any help!!