Find opposite point on a rectangle

221 Views Asked by At

Consider a rectangle $ABCD$, with the $A$ point in the $(0,0)$ position. Based on a point on the edge of the rectangle ($E$ in the picture) and a point inside the rectangle (multiple examples in the picture - $F$, $G$ and $H$) find the opposite point on the same rectangle (in my example $I$, $J$ and $K$).

rect

This is how I solve it, using Slope–intercept form:

  • if $E$ is on the bottom edge:
    • calculate slope $m$ between $EF$, $EG$ or $EH$
    • calculate $y0$
    • calculate $x$ for $y==height==b==d$
      • if $x$ is negative, then set $x=0$ and $y=y0$ ($I$ in my example)
      • if $0<x<width$ then use x and y ($J$ in my example)
      • if $x>width$ then set $x=width$ and calculate y ($K$ in my example)

I use similar logic for other three scenarios (when edge point is on left edge, top edge or right edge). I feel there should be an easier solution, which doesn't care on which edge the starting point is. My solution is very complex and error prone (additional exception are vertical lines where you cannot calculate $slope$). Any better ideas?

1

There are 1 best solutions below

9
On BEST ANSWER

HINT:

Slant line has given variable slope $m$.

$$ x-y/m= 2 \tag1 $$

We can choose both horizontal /vertical lines of the square from its "equation"

$$ x(4-x)y(4-y)=0 \tag2 $$

Substitute for $x$ and $y$ separately from (1)

Out of the two cases eliminating $x$ we get

$$ (2+y/m)(2-y/m)y(4-y) \tag3$$

a fourth degree polynomial in $y$. Two $y$ values are known as input and the the rest two solutions come out by solving a quadratic equation as:

$$(x,y)= (4\frac{2}{3},-3) \tag 4 $$

Similarly eliminating $y$ is left as an exercise.

Choosing only one typical slope $m=\frac32$ (not given by you) for shown red transversal line we can note all intersections on the graph for any arbitrarily chosen $m.$

Hope you can now set up both the quadratic equations.

enter image description here