I've been struggling with this problem for weeks, and couldn't find an appropriate algorithm to solve it. Could you guys please give me some advices or suggestions in addressing this question. Or if you know anyone who could answer this question, please send it to them. I really need the solution as I have been trying to figure it out for quite long time :| Many thanks!
As can be seen in the picture below, I have more than 200 lines in 3D. They consist of 3 different groups of lines, and the common property of the lines in each group is that they pass close to the same point. However, in this problem, we don't know which line belongs to which group. What is given are only the 3D coordinates (x,y,z) of the 2 ends of all the lines.
My job is to find an algorithm to match/fit/register a triangle (a rigid body) to those lines such that the sum of the sum of distances between 3 vertexes of the triangle and their corresponding lines is minimized. In some cases, one vertex may be the closest point in a group, but the other vertexes would be dragged further away from their corresponding lines (because they are in a rigid body), thus this sum will not be minimal. What I need is the best positions of the 3 vertexes (the best fit of the triangle) to minimize the global sum.
In conclusion, given more than 200 sets of (x1,y1,z1,x2,y2,z2) (which are coordinates of 2 ends of a line), I need to find the best positions of 3 vertexes of a triangle to fit in those lines (given the relative distance between the 3 vertexes).
Without the rigid-body condition, I have successfully determined the positions of the 3 independent points using the Expectation-Maximization (EM) clustering algorithm. However, sometimes 2 or 3 points are assigned to the same position. Then, I realized I had forgotten the "rigid-body" condition. With this added condition, this error will not occur. In the EM algorithm, I can derive the formula for each repositioning step for each point. But when it comes to a rigid-body, I don't know how to figure out the translation and rotation matrix to fit the triangle to the lines.
Thank you for reading this post. Your help would be greatly appreciated!

Minimizing a sum of distances is a bit more hassle than minimizing a sum of squares of distances. Unless you have a really good theoretical reason to focus on the sum of distances, I would suggest to minimize the sum of squares.
In that case, a simple iterative approach to this might work and converge quickly. You can alternatingly optimize the positions of the points and the assigments of the lines to the points. Start by randomly (e.g. uniformly) assigning each line to a point. Then obtain a first estimate for the position of each point by solving the linear equation you get from differentiating the sum of the squares of its distances to the lines assigned to it. Then reassign each line to the point closest to it, reposition, reassign, ... – this should converge rather quickly; it can't get stuck in a loop because each step that changes the configuration decreases the objective function. If you ever get into a degenerate situation where one of the points has less than two lines assigned to it, just assign a random line to it if necessary, and then place it somewhere on the one line assigned to it.
The same approach should also work if you really do want to minimize the sum of distances, but then you don't get a linear equation in the positioning step, and you'll have to do perform a non-linear optimization for the point positions.
[Update:]
Both Steven and I forgot to address the problem of optimizing the triangle's position, given an assignment of the lines to the points, taking into account the rigid body constraint. Here's how I'd go about this; this approach can be used either with Steven's or with my suggestion for assigning the lines.
I had taken your use of the term "line" at face value, but I see from Steven's answer that since you speak of two ends of a line you may have meant line segments. That would complicate things, and since the diagrams look like you might get away with extending the line segments to lines, I'll only deal with lines.
The distance of a point $\vec p$ from a line through $\vec x$ in the direction of unit vector $\vec n$ can be expressed as $(\vec p-\vec x)\times\vec n$. You can write the objective function as
$$ f(\Omega,\vec a)=\sum_{i,j}\left|(\Omega\vec p_i+\vec a-\vec x_{ij})\times\vec n_{ij}\right|^2\;, $$
where the variables represent the rigid body motions, $\Omega$ a rotation matrix and $\vec a$ a translation vector, $\vec p_i$ are the three vertices in some reference position of the triangle, and $\vec x_{ij}$ and $\vec n_{ij}$ describe the $j$-th line assigned to the $i$-th point.
We can first differentiate this with respect to $\vec a$ to obtain
$$ \sum_{i,j}\left((\Omega\vec p_i+\vec a-\vec x_{ij})\times\vec n_{ij}\right)\times\vec n_{ij}=\vec0\;. $$
This is a linear equation for $\vec a$ that you can solve by inverting a $3\times3$ matrix that doesn't depend on $\Omega$, which gives you $\vec a$ as a linear function of $\Omega$. Substituting that into the objective function reduces it to
$$ f(\Omega)=\sum_{i,j}\left|(\Omega\vec p_i+\vec a(\Omega)-\vec x_{ij})\times\vec n_{ij}\right|^2\;. $$
To minimize this with respect to $\Omega$, I would write $\Omega=\Omega_0\exp(\mathrm iA)$, with $\Omega_0$ the current value of $\Omega$ and $A$ antisymmetric, differentiate with respect to $A$ and set $A=0$ to get a gradient with respect to $A$. Then you can satisfy the constraint by antisymmetrizing the gradient; this gives you the direction of $A$ along which to search, which defines a family of rotations parametrized by a single angle, which you can optimize by standard one-dimensional optimization.
This is an iterative approach. To find the optimal $\Omega$ for a given assignment of the lines to the points, you'd have to iterate until you achieve the desired accuracy, but if you're using this together with my approach of optimizing the assignment of the lines to the points, it might be more efficient to alternate between single one-dimensional optimizations and reassignment of the lines until the assignment no longer changes, and only then iterate the search to full convergence.