I want to compute the intersection point $q$ of multiple lines in 3D space that minimizes the distance from $q$ to the lines. Lines are noisy and can be slightly skew. For this, I solve a linear system.
Lines are expressed as a point $p$ and a vector $v$:
$ l_i \equiv p_i + \lambda v_i $
In the case of two lines, I have that $ q = (p_1 + \lambda_1 v_1) = (p_2 + \lambda_2 v_2)$, for some $\lambda_1, \lambda_2$. I can build this $Ax=b$ linear system to find $\lambda_i$: $ \left[ \begin{matrix} v_1, ~ -v_2 \end{matrix} \right] \left[ \begin{matrix} \lambda_1 \\ \lambda_2 \end{matrix} \right] = p_2 - p_1 $.
For $N$ lines, I can think about the next $Ax=b$ structure:
$ \left[ \begin{matrix} 1 & 0 & 0 & -v_{1x} & 0 & \dots & 0 \\ 0 & 1 & 0 & -v_{1y} & 0 & \dots & 0 \\ 0 & 0 & 1 & -v_{1z} & 0 & \dots & 0 \\ & & & & \dots \\ 1 & 0 & 0 & 0 & 0& \dots & -v_{Nx} \\ 0 & 1 & 0 & 0 & 0& \dots & -v_{Ny}\\ 0 & 0 & 1 & 0 & 0& \dots & -v_{Nz}\\ \end{matrix} \right] \left[ \begin{matrix} q_x \\ q_y \\ q_z \\ \lambda_1 \\ \dots \\ \lambda_N \end{matrix} \right] = \left[ \begin{matrix} p_{1x} \\ p_{1y} \\ p_{1z} \\ \dots \\ p_{Nx} \\ p_{Ny} \\ p_{Nz} \end{matrix} \right] $.
The system finds both the intersection point $q$ and the $\lambda_i$ parameters. However they are not independent, so I have the feeling this system is more complex than it should be.
Is this system correct, or is there a better solution to this? Also, for $N$ lines, how can I check if the system gives me a reliable solution (e.g. to tell if all the lines are parallel)?
Transform each line equation into the intersection of two planes. You can do that by taking two vectors normal to $v_i$ and impose that each plane pass through the point $p_i$.
Then for each couple of lines, you have a linear system of $4$ equations in $3$ unknowns, which - by the usual conditions on the ranks - will tell you if there are $0$,$1$, or infinite solutions.
If you want to check if $n$ lines are concurrent, you may construct the $2n$ x $3$ = $2n$ x $1$ system and examine if there are the conditions for it to admit a unique solution.