Find point on line between two rectangle centers where line hits edge

368 Views Asked by At

I have two rectangles as in the picture below which can be located anywhere relative to each other.
I have the coordinates of the rectangle centers (c1 and c2) and the lenght/height of both rectangles.

How can I find the coordinates of points p1 and p2 - where the line between the centers crosses the edges?

enter image description here

2

There are 2 best solutions below

0
On

If you know the two center points' coordinates, you can come up with an equation for the line between them. Then, say for P2, you can plug in $C2-\frac{L2}{2}$ into your equation for the line for the $x$ value and solve for $y$.

Then solve for P1 similarly.

0
On

Say the rectangle has dimensions $ (L,h) $

Equation of inclined line

$ \dfrac{y}{x}= \dfrac{c_2}{c1} \tag{1} $

Equation of vertical lines

$ x= L/2 \tag{11}$

$ x= -L/2 \tag{12}$

$ x= c_1+L/2 \tag{13}$

$ x= c_1-L/2 \tag{14}$

Equation of horizontal lines

$ y= h/2 \tag{21}$

$ y= -h/2 \tag{22}$

$ y= c_2+h/2 \tag{23}$

$ y= c_2-L/2 \tag{24}$

Now choosing four out of the eight lines, find points of intersection ( choose which line you want to cut which line) with the inclined line.