I have a two points, $A(x_1,y_1)$ and $B(x_2,y_2)$. They are united with a line.

Now I have a 3rd and 4th point $C(x_3,y_3)$, $D(x_4,y_4)$. The line formed by CD is going to intercept AB in point $E(x_5,y_5)$.

I know everything except $y_3, y_4$ and $y_5$, also $x_3, x_4, x_5$ are equal.

How do I find that $y_3,y_4,y_5$? Is there a formula?



Point $E=(x_5,y_5)$ is the intersection of the line $AB$ with the $CD$ (which we know to be perpendicular to the X-axis because $x_3=x_4$). So a formula for the line $AB$ is $$(x_1-x_2)y= (y_1-y_2)x + y_1(x_1-x_2) - x_1(y_1-y_2)$$

and so $$y_5= \frac{(y_1-y_2)x_5 + y_1(x_1-x_2) - x_1(y_1-y_2)}{x_1-x_2}$$

You can't find $y_3$ and $y_4$ because the only thing you know about points $C$ and $D$ is that they lie in the same vertical line and the construction does not change if you move them along that same line (try drawing it).

  • $\begingroup$ This actually came from a drawing. I'll test it out later, thanks a lot for now. I was testing to see if I can make a line AB jump on a randomly generated line CD, sort of like in a platforming game, but on canvas and without using foreign libraries - I hit that bump. $\endgroup$ – Andrei Cristian Prodan Jan 15 '13 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.