[Math] Given starting point and length of line, find end point which lies on a given line

geometry

In a 2D plot, I know three points: $P_1, P_2,P_3$ and distance $k$.

I can't come up with the formula of finding coordinates of the 3rd point $P_x$.

Interested plot

Best Answer

Given the coordinates of $P_1, P_2$ and $P_3$, you can find the lengths of the sides of the triangle $P_1P_2P_3$. (Build the difference vectors $P_i-P_j$, then use Pythagoras to compute the lengths $|P_i-P_j|$).

Using trigonometry, you can compute the angle $\alpha$ at $P_2$, which belongs to both the big triangle $P_1P_2P_3$ and the small triangle $P_1P_2P_x$. Now that you have two sides ($P_1P_2$ and $k$) and one angle ($\alpha$) for the small triangle, you can compute the length of the side $P_2P_x$.

You can now compute $P_x$ by going into the direction of $P_3$ starting from $P_2$:

$$P_x = P_2 + \frac{|P_2-P_x|}{|P_3-P_2|} \cdot (P_3-P_2)$$