I have a set of $3$D points representing a line segment. Points are not equidistant distributed on the line segment. Points are also unordered. I also have the center point and the normal to the line segment All points in this point set definitly belong to the same line, i.e. no outliers
I'd like to calculate the length of this line segment by calculating the start and end points.
My first naive solution is to look for min and max $x,y,z.$ But this is wrong, since it ignores the line rotation. Most probably looking for min/max $x,y,z$ in accordance with the line normal should give the answer. But how can this be done?
Calculating all distances is expensive. A cheaper solution is two find the bounding box in only ${\cal O}(n)$ comparisons.
Perform a linear search through all the points; find and record the six values of $\min x,$ $\max x,$ $\min y,$ $\max y,$ $\min z,$ and $\max z.$ Also, record the six points associated with each extrema: $$ \{ p_{\min x}, p_{\max x}, p_{\min y}, p_{\max y}, p_{\min z}, p_{\max z} \}. $$
If all the points one line, then the intersection of the line with the bounding box is exactly two points, and the list of six points above will have only two unique points: the end points.
Here is a picture of the bounding box from Wikipedia, you can easily see that in the case of a line, the intersection of your points set is just two vertices of the box.