# Fitting a Straight Line to 3D Points, and then finding the nearest point to those lines.

I've been stuck on this problem for over a week now.

Essentially, I have a group of 4 tracks of points from a bunch of detectors in 3 dimensions. I need to map these points to straight lines and then work back to where all 4 lines meet. Obviously, they're not going to meet exactly so I need to do a least squares solution there.

I've only ever done problems like this in 2 dimensions and I'm having a problem translating to 3. There seems to be no information about fitting a least squares line to a set of 3D points - every solution just finds a plane.

So basically I need a way to find a vector line of the form:

 P = a + bt


Where a is a position vector and b the direction vector, and then from that find the nearest point to n number of those lines.

• So are you asking how fit "one track of points to one straightline"? If I understand correctly the opening paragraph is just the background context? ...group of 4 tracks...need to map these points to straight lines...(find) where all 4 lines meet – Lee David Chung Lin Mar 12 at 23:51
• Yes it's a 2 part problem, First I need to fit a straight line to each of the individual tracks - using least squares. And then each of those straight lines should meet at an origin which due to the error of each line they aren't all going to meet at exactly the same point, so I need to find the nearest point to all of those lines. Sort of like triangulating the origin of all the tracks. I think fitting straight lines is the way to go, unless there is another method i should be considering? – jameslfc19 Mar 13 at 0:04
• – Mauricio Cele Lopez Belon Mar 23 at 4:26