I have a small geometric problem and I am searching for a exact solution. As its a geometric problem I think its best ilustrated as a picture.


I have given A, B, C, D and P. These are on a 2D coordinate system with float accuracy. I want to find a line, that intersects both lines at the same ratio and goes through point P. ultimately I want calculate the ratio that is marked in blue in the description picture and I want to be exact. I could only find approximations so far. I starting to think, that there isnt even a exact solution to this problem...

I hope I described my problem as exact as possible and there is a math genius out there that can help me. I am just a stupid programmer ;-(

Kind regards, Dominik

  • $\begingroup$ Please split the new problem into a separate question. $\endgroup$ – amd Apr 8 '17 at 23:53
  • $\begingroup$ sorry about that. Done. $\endgroup$ – Nutria Apr 9 '17 at 0:39

Suppose we call the unknown ratio (that is, $30\%$ in your diagram) $t$. Then we have these expressions for $L$ and $K$:

$$ L = \begin{pmatrix} x_A+t(x_B-x_A) \\ y_A+t(y_B-y_A) \end{pmatrix} \qquad K = \begin{pmatrix} x_C+t(x_D-x_C) \\ y_C+t(y_D-y_C) \end{pmatrix} $$

and these expressions for the vectors $\vec{PL}$ and $\vec{PK}$:

$$ \tag{1} \vec{PL} = \begin{pmatrix} x_A+t(x_B-x_A)-x_P \\ y_A+t(y_B-y_A) -y_P \end{pmatrix} \qquad \vec{PK} = \begin{pmatrix} x_C+t(x_D-x_C)-x_P \\ y_C+t(y_D-y_C)-y_P \end{pmatrix} $$

We want to find $t$ such that $\vec{PL}$ and $\vec{PK}$ are parallel. There is a nifty condition for 2D vectors being parallel, namely that we must have $$ \tag{2} x_{PL}\cdot y_{PK} = x_{PK}\cdot y_{PL} $$ If you insert the coordinates of $\vec{PL}$ and $\vec{PK}$ from (1) into (2), it simplifies into a quadratic equation in $t$, which you can solve using the quadratic formula. In general there may be either zero, one, or two solutions in the interval between $0$ and $1$. (Or in some degenerate cases, every $t$ may work, such as for $A(0,2), B(2,2), C(2,0), D(0,0), P(1,1)$).

Can you handle the algebra yourself from here?

  • $\begingroup$ Thanks for the really quick and good solution. I updated my question to the underlying problem I originally wanted to solve with the solution to the problem. That there might be more then one or zero solutions might be an indicator that I have to approximate mine :-( $\endgroup$ – Nutria Apr 8 '17 at 13:35

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.