Given a known line segment and two known horizontal lines, how do I find the line subsegment between the two parallels?

815 Views Asked by At

I am trying to clip a line segment between two parallel horizontal lines.

I know the location of the two vertices on the larger segment, but need to know the points at which it intersects the horizontal lines.

enter image description here

What is the best way to calculate this?

1

There are 1 best solutions below

4
On BEST ANSWER

The equation of the diagonal line is $y-y_1=\frac{y_1-y_2}{x_1-x_2}(x-x_1)$, i.e. $y=\frac{y_1-y_2}{x_1-x_2}(x-x_1)+y_1$ So, the $x$ coordinate of the upper point satisfies $$75=\frac{y_1-y_2}{x_1-x_2}(x-x_1)+y_1$$ and the $x$ coordinate of the lower point satisfies $$25=\frac{y_1-y_2}{x_1-x_2}(x-x_1)+y_1.$$

Now you can solve these for $x$.