Consider the following diagram
Given that point A is the origin and the center point for the rectangle, and the coordinates for point B, how do you find the intersection between Line AB and the rectangle. Thanks
Consider the following diagram
Given that point A is the origin and the center point for the rectangle, and the coordinates for point B, how do you find the intersection between Line AB and the rectangle. Thanks
On
This also depends on the dimensions of the rectangle. Say the rectangle had length $a$ and height $b$ and say that point $B$ had coordinates $(p,q)$. Then the equation of the line joining $A(0,0)$ and $B(p,q)$ is
$y=\frac{q}{p}x$
The equations of the sides of the rectangle are $x=-\frac{b}{2},x=\frac{b}{2},y=-\frac{a}{2},y=\frac{a}{2}$
The intersection between $AB$ and the rectangle is the intersection between $AB$ and any one of the sides of the rectangle. So there are four simultaneous equations to solve
$y=\frac{q}{p}x$ if$-a\le(q)\le(a)$ and $p>\frac{b}{2}$
$x=\frac{b}{2}$
$y=\frac{q}{p}x$ if$-a\le(q)\le(a)$ and $p<-\frac{b}{2}$
$x=-\frac{b}{2}$
$y=\frac{q}{p}x$ if$-b\le(p)\le(b)$ and $q>\frac{a}{2}$
$y=\frac{a}{2}$
$y=\frac{q}{p}x$ if$-b\le(p)\le(b)$ and $q<-\frac{a}{2}$
$y=-\frac{a}{2}$
So the solutions are $(\frac{b}{2},\frac{bq}{2p}),(\frac{b}{2},-\frac{bq}{2p}),(\frac{pa}{2q},\frac{a}{2})(\frac{pa}{2q},-\frac{a}{2})$
Let $B=(x_B,y_B)$, and let $h$ be the half the vertical height of the rectangle (i.e. the y-coordinate of the top side of the rectangle). The coordinates of the intersection $P$ are then simply the coordinates of B scaled by a factor $\frac{h}{y_B}$, i.e. $P=(\frac{h}{y_B}x_B,h)$.