# how to get optimal vector, which is parallel to intersection line of many plane (Least Square way)

My idea is to construct the best optimal 3D line representing the intersection of many 3D planes. (As we know, due to fitting errors or data errors, the fitted planes might not intersect exactly through a line but close to each other.)

So, to get the optimal 3D line which represent intersection of many planes, I first want to find the optimal point and then optimal vector as 3D cline can be represented as a point and 3D vector.

Actually, I found a way to do this. But, according to the explanation, the way to get optimal $v$ is not clear to me. If I say it here,

" 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$$
$$----(1)$$ where $P_i=\frac{n_i n_i^T}{n_i^Tn_i}$, 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$.
"

So, I have the following questions to understand this problem. So, can anyone explain what should I do to get my optimal vector?

Q1. I am not clear on the meaning of equation (1). Does it equal to $v^Tv=1$.

Q2. What does this mean "you need to check under what condition A is invertible"?

Q3. That explanation says, in SVD $A$ be $A=U\Lambda U^T$. what does $A=U\Lambda U^T$ mean?

Q4. my most important question is what condition should I check to get my required optimal vector.

-
I don't understand the whole thing, but: 1) no, eq (1) isn't the same as $v^{T}v=1$, rather it's a sum of the measure of the projections of $v$ onto the normals of the planes. 2) In a degenerate case, say with planes that turn out to be coplanar, you'll likely get linearly dependent matrix that has no inverse. 3) SVD means "Singular value decomposition" which is a topic in itself -- I've used it in the past but don't really understand it. –  Mark Ping Jul 11 '13 at 15:39
@Shiyu: I am also working with intersecting of multiple planes. for me, It is difficult to think the second part. for this what should i implement. does it the whole $$J_v=v^T A v \ge \lambda_{\mathrm{min}}(A) v^T v = \lambda_{\mathrm{min}}(A)$$ then how to get optimal v? –  slinga Jul 12 '13 at 8:43
From the answer you linked to: "the equality holds when v is the last column of U", so you do the SVD, then look at the last column of U, if I understand it correctly. –  Mark Ping Jul 12 '13 at 18:48
@Mark Ping: thanks for the response. if you can, please explain the equation (1) and rest of the equations in the form of matrices (with correct dimensions, as i need to implement this in c++). but not very sure how it would be. –  slinga Jul 19 '13 at 19:47
The first equation is just an odd way to write "projection of $v$ onto $n_i$". As for the rest, I used SVD as implemented by "Numerical Recipes in C" in the past, but their license is quite restrictive, and there are tons of implementations out there, especially for small matrices. –  Mark Ping Jul 19 '13 at 20:12