I am working with many 3D planes and looking for a Least square solution for below case.
IF I am having many number of 3D planes knowing only one point and the normal vector (for eg. O1 and N1), and all those planes intersect each other and make nearly very close 3d lines, then how to compute the least square adjusted one single 3d line to represent all those intersections.
To get a clear idea, I have inserted a figure.
- Known: one point and the normal vector of each plane.
- Find: Least Square fitted single line3d

By kowing the 3d lines like O1-B1 and O1-E1, I know this can be done taking pairwise planes and then by finding 3dline segments. i.e. end points and then by finding the best fitted 3dline. but I heard without doing this and considering many planes at once, can also do this. SO, looking for the solution for that with Least Square. thanks in advance
In order to get that "optimal" line, the key is to establish the objective functions. In order to determine a line in 3D, we need to determine a point $p\in\mathbb{R}^3$ on this line, and the vector $v\in\mathbb{R}^3$ which is parallel to the line. Next I will first determine the optimal $p$ and then the optimal $v$.
Step 1: determine $p$
It is natural to choose $p$ as the point that is closest to all of the planes. For plane $i$, denote $n_i\in\mathbb{R}^3$ and $o_i\in\mathbb{R}^3$ respectively as its normal vector and a point on the plane. Then the distance between a point $p$ and the plane can be expressed as
$$\left\|\left(\frac{n_i n_i^T}{n_i^Tn_i}\right)(p-o_i)\right\|$$
Hence to determine the point $p$, we can minimize the objective function $$J_p= \sum_{i=1}^n \left\|\left(\frac{n_i n_i^T}{n_i^Tn_i}\right)(p-o_i)\right\|^2 $$ Denote $P_i=\frac{n_i n_i^T}{n_i^Tn_i}$, then $J_p$ can be written as $$ J_p=\sum_{i=1}^n (p-o_i)^T P_i (p-o_i) $$ Note $P_i$ is an orthogonal projection matrix satisfying $P_i=P_i^T$ and $P_i^2=P_i$. A short calculation shows that $$ p^* = \left(\sum_{i=1}^n P_i\right)^{-1}\left(\sum_{i=1}^nP_io_i\right)$$ You can check the condition under which $\sum_{i=1}^n P_i$ is invertible.
Step 2: determine $v$
Intuitively speaking, the angle between the vector $v$ and a plane should be as small as possible. In other words, $v$ should be perpendicular to the normal vector $n_i$ as much as possible. Or we can say the orthogonal projection of $v$ on $n_i$ should as small as possible. Note we only need to determine the direction of $v$. Hence we can assume $v^Tv=1$. To determine $v$ we can minimize the objective function $$ J_v= \sum_{i=1}^n \left\|\left(\frac{n_i n_i^T}{n_i^Tn_i}\right) v \right\|^2 = v^T \left(\sum_{i=1}^n P_i\right) v$$ Denote $A=\sum_{i=1}^n P_i $. Clearly $A$ is positive definite (you need to check under what condition $A$ is invertible). Let the SVD of $A$ be $A=U\Lambda U^T$. Hence $$ J_v=v^T A v \ge \lambda_{\mathrm{min}}(A) v^T v = \lambda_{\mathrm{min}}(A)$$ where the equality holds when $v$ is the last column of $U$.