First of all I'm beginner in "advanced" math. For this reason I don't know how to compute this problem.
Consider we have a generic rectangle with width W and height H. Also, consider that inside the bounds of that rectangle exists a point B and a point M, in any coordinates inside the rectangle. Knowing this, how can we find the coordinates of a point T which lies in a line MBT and that also stays on the edge of that rectangle? The reason to find the coordinates of T is that I will can draw a line between B and T.
To help understand the problem, see this figure: example
To try to solve this, I attempted some stuff:
- I imagined that the rectangle is living inside a circle;
- the center of the circle coincides with the center of the rectangle, then we have the radius of the circle dividing the diagonal of the rectangle by 2;
- Using the center point C, we can create a triangle MCB, which also have all it's sides known from distance of points formula;
- By using it's sides is possible to find the angle at the vertice B using the cosine's law;
- From the angle X above, we can get it's adjacent X' by subtracting it from 180 degree;
- With the angle X', then, is possible to find the length of the line from B to a point T2 formed by the triangle CBT2 (as illustrated below), again using cosine's law;
- After getting the length of the line BT2 called L, is possible to find the coordinates of the point T2 using the way described here: Finding a point along a line a certain distance away from another point! (being L, the related distance).
Those steps are really messy and I was only about to get the coordinate of T2 instead of T. I could go further to find T taking the fact that T is between B and T2 or even creating more triangles and so on.
Then, as I have to use those calculations in programming, are those worth it? If not (and probably not) what a fine way to find the coordinates of the point T in this scenario?