When drawing an angle line ($45$ degrees) in a rectangle from a general point $p = (x,y)$ that located on the right or the top line of the rectangle. How can I find the intersection point $p2$ of this line with the rectangle?
In other words, I want to write the target point, $p2$, with my current information: $x, y, w, h$. (This variables are described in the picture below).
The point $(0,0)$ is in the top-right corner.

If it is just $45$ degrees, then the answer is not very difficult. Center a coordinate system at the bottom left hand corner of the rectangle. Hence the coordinates of the (???) point are $(q,0)$ for some $q<w$.
Note that the because theta is $45$ degrees, $y=w-q$ (Isosceles right triangle). Hence $q=w-y$, and our point is simply $(w-y, 0)\dots$