Friday, February 28, 2014

Thursday, February 13, 2014

Finding the intersection point of many lines in 3D (point closest to all lines)

http://math.stackexchange.com/questions/61719/finding-the-intersection-point-of-many-lines-in-3d-point-closest-to-all-lines
I have many lines (let's say 4) which are supposed to be intersected. (Please consider lines are represented as a pair of points). I want to find the point in space which minimizes the sum of the square distances to all of the lines or in other words, the point which is closest to all the lines.
I want to formulate this as a Least Squares Problem, but I'm not quite sure how it would be. I found the way to compute the distance between line and point. So, I need help to go further.
In some degenerate cases there may be no such a one point (for instance, if all the lines are parallel). However there's a single solution in the general case.
I assume you're trying to solve a more general problem where all the lines are not required to intersect exactly (otherwise there's a much simpler solution than the least squares).
Derivation:
You say the every line is represented by two points. Let's rather work in the convention where a line is represented by one point and a direction vector, which is just a vector subtraction of those two points. That is, instead of describing a line by points a and b we'll describe it by a point a and a vector dwhereas d=ba.
Our point (which we're trying to find) is c.
The distance of this point to the line is:
H=(ca)×dd
Using identity (a×b)(a×b)=a2b2(ab)2
we have:
H2=ca2d2(ca)d2d2
H2=ca2(ca)d2d2
The square sum of the distances of the point c to all the lines is just the sum of the above expressions for all the lines. The problem is to minimize this sum. This sum depends on a variable c (which is actually 3 variables, the components of c). This is a standard least squares problem, which generally has a single solution (unless there's a degeneracy).
Solving the least squares for this specific case.
Since we want find such a c that minimizes this sum, its derivative with regard to c should be zero. In other words:
d(H2)dc=2(ca)2d(ca)dd2
0=mi=0ca(i)d(i)(ca(i))d(i)d(i)2
This gives 3 equations (since it's a vector equation) with 3 unknowns (components of c).