Finding points on the line connecting two 3D points

3danalytic geometryeuclidean-geometrylinear algebravectors

I have two points in 3D space. Say these are P = (x, y, z) and Q = (u, v, w). Now, I would like to get line segments from P to Q of length epsilon each. So, for that, I need all the points on the line from P to Q that are apart by length epsilon. I can do this for a line in 2D, but I am confused with how to do this for a line in 3D?

Here is what I tried.

Set current point to be P and the next point to be current point + epsilon * (Q-P)/|Q-P|.

Z = {current point, next point}

Then, iteratively, went through adding to the set Z, next point + epsilon * (Q-P)/|Q-P|.

However, I can not figure out how to stop this iterative process.

What is the correct way of thinking about this in 3D?

Thank you in advance!

Best Answer

The number of line segments ($n$) of length $\epsilon$ starting from point $P$ and ending at or before point $Q$ must be,

$ \displaystyle n = \left \lfloor \frac{|\textbf{Q}-\textbf{P}|}{\epsilon} \right \rfloor$

At the start of the iteration, $ \textbf{P}_{1} = \textbf{P}$

Iterate for $1 \leq m \leq n$,

$ \displaystyle \small \textbf{Q}_m = \textbf {P}_m + \frac{\textbf{Q}-\textbf{P}}{|\textbf{Q}-\textbf{P}|} \epsilon ~$

and $\textbf{P}_{m+1} = \textbf{Q}_{m}$