I need to find the point of intersection between some square xy + N,N where N is the size of the square and some line x1,y1,x2,y2 where x1,y1 lies on the center point of the square. Assume that the square is parallel to the x-axis & y-axis.
Related Questions:
The answer in #1 provided essentially explains that you clamp one of the coordinates of the line to the square, which is inaccurate and produces incorrect results. The answer in #2 provides some obscure formula which isn't explained.
I've worked out the answer. You find the long-side of the triangle formed by the line
x1,y1,x2,y2and multiplex2,y2by a scalar which is the difference between the long side of the triangle and1/2the length of the square.See example on Shadertoy: https://www.shadertoy.com/view/mtdyDn