% of traversal for a point between two other points along a line

630 Views Asked by At

I'd like to solve for some "phase" or percentage, involving an arbitrary location (xC, yC) between two points. I'm not familiar with how to phrase this question, so please excuse my ignorance. Not sure if this is closer to Trig or LA. Currently I'd like to solve this for 2D, but might expand to 3D in the future.

point moving along a line

1

There are 1 best solutions below

2
On BEST ANSWER

The movement from $A$ to $B$ is the vector $B-A$.

Some partial amount of that movement is the vector $t(B-A)$, for some value of $t$ between $0$ and $1$.

Making such a movement starting at $A$, you end up at $A + t(B-A)$.

What you want is $A + t(B-A) = C$. In coordinates: \begin{align*} x_A + t(x_B - x_A) &= x_C \\ y_A + t(y_B - y_A) &= y_C \end{align*} This is a system of two equations with one unknown, namely $t$. If $C$ is in fact on the line through $A$ and $B$, this system will have a unique solution; if $C$ is between $A$ and $B$, that solution will be between $0$ and $1$.