[Math] Calculate a point on the line at a specific distance .

geometry

I have two points which make a line $l$ , lets say $(x_1,y_1) , (x_2,y_2)$ . I want a new point $(x_3,y_3)$ on the line $l$ at a distance $d$ from $(x_2,y_2)$ in the direction away from $(x_1,y_1)$ . How should i do this in one or two equation .

Best Answer

A point $(x,y)$ is on the line between $(x_1,y_1)$ and $(x_2,y_2)$ if and only if, for some $t\in\mathbb{R}$, $$(x,y)=t(x_1,y_1)+(1-t)(x_2,y_2)=(tx_1+(1-t)x_2,ty_1+(1-t)y_2)$$ You need to solve $$\begin{align*}d&=\|(x_2,y_2)-(tx_1+(1-t)x_2,ty_1+(1-t)y_2)\|=\sqrt{(tx_2-tx_1)^2+(ty_2-ty_1)^2}\\ &=\sqrt{t^2}\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\hspace{5pt}\Rightarrow\hspace{5pt} |t|=\frac{d}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}\end{align*}$$ You will have two values of $t$. For $t>0$ this point will be in the direction to $(x_1,y_1)$ and for $t<0$ it will be in the direction away from $(x_1,y_1)$.

Related Question