# How to translate a 3d point along a line?

I have two points (vectors) in 3d space. Given some value I want to translate point A by that value along the line that connects point A and B. Is there a simple formula for this? I'm trying to implement it in python.

Let $$a,b$$ be the two vectors in question. We can define a third vector $$d=b-a$$. This vector will point from $$a$$ to $$b$$. Normalize this to the unit vector $$n$$:

$$n=\frac{d}{|d|}$$

Now, if you have some distance $$\lambda$$ you want to move towards $$b$$ you create the new point $$a'$$ as

$$a' = a + \lambda n$$

Any point $$M$$ on the line going through $$A$$ and $$B$$ can be represented as $$M = A + t\cdot \overrightarrow{AB}$$ where $$t$$ is a real number. For instance, $$t=0$$ gets you $$M=A$$, while $$t=1$$ gets you $$M=B$$. So $$t$$ represents the amount of displacement along the line, starting from point $$A$$. Plugging in any other value of $$t$$ will get you some other point on the line.

So the simple formula for the $$3D$$ coordinates $$(x_M, y_M, z_M)$$ of $$M$$ is $$\left\{ \begin{split} x_M &= x_A + t (x_B-x_A)\\ y_M &= y_A + t (y_B-y_A)\\ z_M &= z_A + t (y_B-z_A)\\ \end{split}\right.$$

• I like your answer but distance t is not represented in the same coordinate space Aug 18 at 0:04