Position of a point on a line segent relative to the segent's length

155 Views Asked by At

I would like to ask for help with clarifying the following formula for calculation of relative position of a point on a line segment with respect to the line segment's length in two-dimensional Euclidean space:

$$t = \frac{(P-A)(B-A)}{\lVert B-A \rVert^2}$$

where P is a point of line segment AB and $t \in [0; 1]$.

This is a formula we have had in our OpenGL course but unfortunately our teacher skipped the explanation saing it is elementary.

I tried to derive the formula somehow from the standard Euclidean distance $t = \frac{\lVert P-A \rVert}{\lVert B-A \rVert}$ but I wasn't successful at all. The only other source I was able to find citing this formula was an old OpenGL on-line manual, however, it doesn't provide any explanation either. The formulas seem to be equivalent anyway.

Thank you.

1

There are 1 best solutions below

4
On BEST ANSWER

$t$ is a scalar and can be defined as: $$t=\frac{||P-A||}{||B-A||}$$ Since $P$ is on the line segment $AB$, the vectors $P-A$ and $B-A$ would be in the same direction and $(P-A).(B-A)$ = $||P-A||||B-A||$. Using this condition and by multiplying numerator and denominator by $||B-A||$ in defintion of $t$, we arrive at the formula.