Intersection between a line section and square 
The green dot is the center of the square. Red dot is outside the square. We know the coordinates of the green dot and red dot, and also the size of the square.
How can I find the coordinates of the blue dot?
 A: I assume the sides of the square are parallel to the axes. Then it is easy to obtain the coordinates of the 4 endpoints of the square. Thus you get the equation of the four lines that constitute the sides of the square. Now the point of intersection will be a convex combination of the green and red point, i.e., if the coordinates of the green point is $(x_g,y_g)$ and those of the red point are the $(x_r,y_r)$, then the coordinates of the point of intersection is $\lambda(x_g,y_g)+(1-\lambda)(x_r,y_r)$ for some $0<\lambda<1$. Now put these coordinates, $\lambda(x_g,y_g)+(1-\lambda)(x_r,y_r)$, in the equation of the four lines, and find which if the four gives a legitimate value of $\lambda$ in the interval $(0,1)$. Thus you get which side of the square the line intersects and also the value of $\lambda$, which will give you the coordinates of the point of intersection.
A: Let the green dot be at $(0,0)$ and the red dot at $(x_r,y_r)$.
The equation of the line connecting the two is therefore:
$$(x,y)=t(x_r,y_r)$$
The boundaries of the square are $\pm x_s, \pm y_s$.
The line from the red dot to the green dot intersects both the $\pm x_s$ and the $\pm y_s$ lines.
Choose the two with the smaller components, and decide which one you want, which will be the one with the same signed components as the red dot.
