# Computing the average coordinate for more than 2 points on a 3d line segment

Suppose, I have many 3d line segments which suppose to be intersected with another given line segment. So, I wish to take a line segment and the given line to get the intersection point. Again, I wish to get the next line segment and the same given line segment to find their intersection point. So, at the end of this process I will have many points which lie on that given line segment (I guess). Now, I want to get an average coordinate for all those point, but that point also should be located on the same given line segment. Could you please let me know an easy way to implement this process? Thanks in advance.

-
If you have a set of points which lies on a given straight line then their avearge (average of x co-ordinates, av. of y, av. of z) will also lie on that line – Henry Jan 26 '12 at 12:27
@Henry: thank you. if i ask you for the clarification, does it always true for a 3d line irrespective from the number of points, lies on it? – niro Jan 26 '12 at 15:09
See my answer below – Henry Jan 26 '12 at 16:19

## 1 Answer

Points on a 3D line can be expressed by the paramentric equations $$x_i=k+at_i, \; y_i=l+bt_i, \; z_i=m+ct_i$$

If you take the sum of the co-ordinates of $n$ such points you get $$\sum x_i=nk+a \sum t_i, \; \sum y_i=nl+b \sum t_i, \; \sum z_i=nm+c \sum t_i$$

so if you take the average of the co-ordinates you get $$\frac{\sum x_i}{n}=k+a \frac{\sum t_i}{n}, \; \frac{\sum y_i}{n}=l+b \frac{\sum t_i}{n}, \; \frac{\sum z_i}{n}=m+c \frac{\sum t_i}{n}$$ which satisfies the original parametric equation and so lies on the line.

-
thank you very much for your explanation. – niro Jan 27 '12 at 19:06