How to create parallel offset lines in 3D space

503 Views Asked by At

I'm working with a $~3$D visualization toolkit in python.I want to draw lines (which will be converted to tubes) between given $~3$D points. I have a function that given two $~3$D points $~(P1(X,Y,Z), ~~P2(X,Y,Z))~$ draws a line between them and converted to a tube.

However, in some cases I need to convert the line to two offset parallel lines with small distance between them. Thus I need to calculate the new points for the two lines $~(P1',P1'', P2' and P2'')~$.

This following image summarizes the starting point and the desired result :

enter image description here

1

There are 1 best solutions below

0
On

If you want the new tubes to be in a particular plane, I would approach the problem as follows:

  • We need to describe the plane. The easy way is to use 3 points, $P_1$, $P_2$ and an additional $P_3$, not on the $P_1P_2$ line.
  • Next step is to find a vector in the plane, perpendicular to $P_2-P_1$. You can write this using the dot product: $$\begin{align}\vec a&=P_2-P_1\\\vec b&=P_3-P_1\\\vec b_{||}&=\vec a(\vec b\cdot\vec a)/|\vec a|^2\\\vec b_\perp&=\vec b-\vec b_\perp\\\hat b_\perp&=\vec b_\perp/|\vec b_\perp|\end{align}$$
  • If the distance between the new tubes is $d$, write the new positions of the ends of the tubes as$$P_{1,2}^{',''}=P_{1,2}\pm\frac d2 \hat b_\perp$$