# Relation Between 2 Lines

Given vector equation of 2 Lines

$$\vec{L_1} = \vec{A} + a\vec{B}$$
$$\vec{L_2}= \vec{C} + c\vec{C}$$
In above equations $$\vec{L_1}$$ is a Line having a point with position vector $$\vec{A}$$ and direction vector $$\vec{B}$$ and $$\vec{L_2}$$ is a Line having a point with position vector $$\vec{C}$$ and direction vector $$\vec{D}$$. The following can be the relation between these 2 Lines.

1. If $$\vec{B} \times \vec{D} = 0$$ then the lines do not intersect. Further, if $$(\vec{C} - \vec{A}) \times \vec{D} = 0$$ (or $$(\vec{C} - \vec{A}) \times \vec{B} = 0$$) then the lines are coincident. Otherwise the lines are parallel.
2. If $$\vec{B} \times \vec{D} \neq 0$$ then the lines intersect. The point of intersection is given by the following formula

$$\vec{P} = \vec{A} + (\frac{\vert (\vec{C}-\vec{A})\times \vec{D} \vert}{\vert \vec{B}\times \vec{D} \vert}) s\vec{B}$$
OR
$$\vec{P} = \vec{C} + (\frac{\vert (\vec{A}-\vec{C})\times \vec{B} \vert}{\vert \vec{D}\times \vec{B} \vert}) s\vec{D}$$
The value of s in above equations is 1 if $$((\vec{C}-\vec{A})\times \vec{D}) \cdot (\vec{B}\times \vec{D}) > 0$$ (and $$((\vec{A}-\vec{C})\times \vec{B}) \cdot (\vec{D}\times \vec{B}) > 0$$ ). If these dot products are < 0 then the value of s is -1.
The above formulae can be used for finding point of intersection of 2 Lines in both 2D and 3D.

In 2D only, scalar cartesian equation of two lines are given as follows

$$A_1x + B_1y = C_1$$
$$A_2x + B_2y = C_2$$

These equations can be represented in matrix form as following

$$\begin{bmatrix} A_1 & B_1 \\A_2 & B_2 \end{bmatrix} \begin{bmatrix} x \\ y\end{bmatrix} = \begin{bmatrix} C_1 \\C_2 \end{bmatrix}$$

The following can be the relation between these 2 Lines
1. If $$\frac{A_1}{A_2}=\frac{B_1}{B_2}=\frac{C_1}{C_2}$$ then the lines are coincident.
2. If $$\frac{A_1}{A_2}=\frac{B_1}{B_2}\neq\frac{C_1}{C_2}$$ then the lines are parallel.
3. If $$\frac{A_1}{A_2}\neq\frac{B_1}{B_2}$$ then the lines intersect.
Following are the steps to find the point of intersection between these 2 Lines:
1. Calulate the following determinants

$$D=\begin{vmatrix} A_1 & B_1 \\A_2 & B_2 \end{vmatrix} \hspace{.5cm} D_1=\begin{vmatrix} C_1 & B_1 \\C_2 & B_2 \end{vmatrix} \hspace{.5cm} D_2=\begin{vmatrix} A_1 & C_1 \\A_2 & C_2 \end{vmatrix}$$
2. If $$D=D_1=D_2=0$$ then the lines are coincident.
3. If $$D=0$$ and either $$D_1\neq0$$ or $$D_2\neq0$$ then the lines are parallel.
4. If $$D\neq0$$ then the lines intersect and the coordinates of intersection is given as

$$x=\frac{D_1}{D} \hspace{.5cm} y=\frac{D_2}{D}$$
5. The point of intersection between these 2 Lines can be also be found out by the matrix inversion as following

$$\begin{bmatrix} x \\ y\end{bmatrix} = \begin{bmatrix} A_1 & B_1 \\A_2 & B_2 \end{bmatrix}^{-1} \begin{bmatrix} C_1 \\C_2 \end{bmatrix}$$

$$\Rightarrow \begin{bmatrix} x \\ y\end{bmatrix} = \frac{1}{D}\begin{bmatrix} B_2 & -B_1 \\-A_2 & A_1 \end{bmatrix} \begin{bmatrix} C_1 \\C_2 \end{bmatrix}$$