3
$\begingroup$

When drawing an angle line (45 degrees) in a rectangle from a general point $p = (x,y)$ that located on the right or the top line of the rectangle. How can I find the intersection point $p2$ of this line with the rectangle?

In other words, I want to write the target point, $p2$, with my current information: $x, y, w, h$. (This variables are described in the picture below).

The point $(0,0)$ is in the top-right corner.

rect

  • 2
    Could you rephrase your question? I can't tell what is being asked. Does the line passing through `???` and `(x,y)` have slope 1?2010-07-28
  • 0
    The line is going from `p` (a point in the right or top line) to `p2` a point in the left or bottom line. p coordinates are `x` and `y`. How can I represent `p2` by `x,y,w,h`?2010-07-28
  • 0
    I would just construct the line, given the fact that you have it's point ((x,y)) by assumption, and you have it's slope $m=1$. Then find the point that this line intersects the rectangle.2015-12-24
  • 0
    In your example if$(x,y)=(-5,0)$ Given we have the slope $m=1$, we can use the point-slope equation of a line to find an explicit equation for the line. In this example the line is given by $y=x+5$. The line that describes the left hand side of your picture is given by $x=-10$. These curves intersect at $(-10,-5)$.2015-12-24
  • 0
    In general you'll have to look at each rectangle as a separate case, but you could find a single formula (or maybe two formulae) that completely gives you $P_2$ as a function of $P_1$ if you consider only one rectangle.2015-12-24

2 Answers 2