# Given the cartesian coordinates of four points, how to calculate the interection of two lines they form?

Given four complex numbers $A, B, C, D$ interpreted as points on the plane, how can I calculate the number that represents the intersection of the lines formed by $A, B$ and $C, D$?

-
Assuming $\arg(B-A)\neq\arg(D-C)$ of course... – J. M. Jan 8 '12 at 16:05
@J.M. Of course. This possibility is ruled out. – FUZxxl Jan 8 '12 at 16:08
Mathematica says: $$\frac{(A-B)\Re(D\Im C-C\Im D)+(C-D)\Re(A\Im B-B\Im A)}{\Re((A-B)\Im(C-D)-(C-D)\Im(A-B))}$$ – J. M. Jan 8 '12 at 16:22
@J.M. Oh yeah. That looks good. THank you! BTW, is there a solution that use the $r,\vartheta$ representation instead? – FUZxxl Jan 8 '12 at 16:34
@J.M. Could you please provide the Mathematica input that you used to generate your equation: (A−B)R(DJC−CJD)+(C−D)R(AJB−BJA)R((A−B)J(C−D)−(C−D)J(A−B)) I imagine you used Solve[..], but I'm wondering how you told Mathematica to split up the complex numbers like that Thanks – user28419 Apr 5 '12 at 19:04

If $P$ is the intersection, then we're seeking $r,s\in\mathbb{R}$ with $$P = A + r(B-A) = C + s(D-C).$$ (If you are familiar with linear fractional transformations, note that the map $P\rightarrow\frac{P-A}{B-A}=r$ takes $A$ to $0$, $B$ to $1$ and fixes $\infty$, and similarly for $P\rightarrow s$.)

This can be rewritten using constant "vectors" $X=A-B$, $Y=D-C$ & $Z=A-C$ as $$\begin{matrix} r(A-B) &+& s(D-C) &=& A-C \\ rX &+& sY &=& Z \end{matrix}$$ which becomes two equations in two unknowns over $\mathbb{R}$: $$\begin{matrix} r\;\Re{X} &+& s\;\Re{Y} &=& \Re{Z} \\ r\;\Im{X} &+& s\;\Im{Y} &=& \Im{Z} \end{matrix}$$ where $\Re{(x+yi)}=x$ and $\Im{(x+yi)}=y$ are the real and imaginary components of any complex number in the identification $\mathbb{C}=\mathbb{R}^2$. This has solution $$r = \frac{ \left| \begin{matrix} \Re{Z} & \Re{Y} \\ \Im{Z} & \Im{Y} \end{matrix} \right| }{ \left| \begin{matrix} \Re{X} & \Re{Y} \\ \Im{X} & \Im{Y} \end{matrix} \right| } = \frac{\Im{(Z\overline{Y})}}{\Im{(X\overline{Y})}} \qquad \text{and} \qquad P=A-rX,$$ since for any $X,Y\in\mathbb{C}$ (as is easy to verify), the determinants above can be expressed in several equivalent ways: $$\begin{eqnarray} \left| \begin{matrix} \Re{X} & \Re{Y} \\ \Im{X} & \Im{Y} \end{matrix} \right| &=& \Re{X}\Im{Y}-\Re{Y}\Im{X} & \\ &=& \Re(X\Im{Y}-Y\Im{X}) & \qquad\text{(as in the Mathematica answer)} \\ &=& -\Im{(X\overline{Y})} & \qquad\text{(as used above)}. \end{eqnarray}$$

-

Let $A = (x_1,y_1), \dots , D = (x_4, y_4)$ be your four complex numbers. The pair of straight lines joinning the first and the second and the third and the fourth can be represented by the parametric equations

$$(x,y) = s(x_1, y_1) + (1-s) (x_2, y_2) \ , \qquad s \in \mathbb{R} \qquad\qquad [1]$$

and

$$(x,y) = t(x_3, y_3) + (1-t) (x_4, y_4) \ , \qquad t \in \mathbb{R} \qquad\qquad [2]$$

So we have to solve

$$s(x_1, y_1) + (1-s) (x_2, y_2) = t(x_3, y_3) + (1-t) (x_4, y_4) \ .$$

That is,

$$\begin{eqnarray*} (x_1 -x_2)s + (x_4 - x_3)t & = & x_4 - x_2 \\ (y_1 -y_2)s + (y_4 - y_3)t & = & y_4 - y_2 \end{eqnarray*}$$

So, you just find the solutions, $s$ or $t$, of this system of linear equations, and then replace in [1] or [2].

-