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!

  • $\begingroup$ Find unit vector $ \hat{u}$ in the direction $PQ$, then the other end of the line segment is $ ~ P + \epsilon ( \hat{u})$ $\endgroup$
    – Math Lover
    Oct 9, 2021 at 16:04
  • $\begingroup$ Should the unit vector in the direction of PQ simply be (Q - P)/norm(Q - P)? How do I ensure that the segments do not go out of the line connecting the points PQ? $\endgroup$ Oct 9, 2021 at 16:06
  • $\begingroup$ unit vector? Yes $(Q-P) / |Q-P|$ $\endgroup$
    – Math Lover
    Oct 9, 2021 at 16:08
  • $\begingroup$ I tried this, but I can not figure out how to check that it does not go beyond Q. If you write it as an answer, I can "checkmark" it. $\endgroup$ Oct 9, 2021 at 16:09
  • $\begingroup$ But that depends on $\epsilon$. If you want the point to be between $P$ and $Q$ then you must ensure $ \epsilon \leq |Q-P|$ $\endgroup$
    – Math Lover
    Oct 9, 2021 at 16:11

1 Answer 1


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}$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .