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$?
Given the cartesian coordinates of four points, how to calculate the interection of two lines they form?
-
0@tlatev: I don't have *Mathematica* with me at the moment, but if memory serves, I used Cramer's rule and some massaging with `ComplexExpand[]` and `Simplify[]` in all the right places... – 2012-04-10
2 Answers
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].