[Math] Calculating start/end points of a line segment given by a set of points and normal direction

3dcomputational geometrygeometry

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?

Best Answer

One way would be to multiply all points by the rotation matrix corresponding to the line pointing in the $z$ direction. Then you simply find $\max z$ and $\min z$. A faster way would be to calculate the distance for each point from the center, and take the farthest points as the endpoints. The distance between them will give you the line's length.