0

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.

  • A point on the line segment can be written in vector form as $P = A+t(B-A)$ where t is in [0,1]. If t = 0 you are at A and if t = 1 you are at B. Now dot product $(P-A) = t(B-A)$ with $(B-A)$ and you are done. – Paul Mar 19 '15 at 20:34
  • Thank you, I really didn't think of it that way. This was nice and clear and I would surely accept it as an answer. – Kyselejsyreček Mar 19 '15 at 21:34

1 Answers1

0

$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.

N.M.
  • 48
  • Oh, I am sorry for my mistake that I originally told that $t = \frac{P-A}{||B-A||}$ - I really meant the formula you have written in the beginning of our answer. I just must be missing something in the condition where you claim that $(P-A)\cdot(B-A) = ||P-A|| \cdot ||B-A||$. Could you please explain how can $(P-A)\cdot(B-A) = (x_p - x_a)(x_b - x_a) + (y_p - y_a)(y_b - y_a)$ be equal to $||P-A|| \cdot ||B-A|| = \sqrt{(x_p - x_a)^2 + (y_p - y_a)^2} \cdot \sqrt{(x_b - x_a)^2 + (y_b - y_a)^2}$? Thank you. – Kyselejsyreček Mar 19 '15 at 21:53
  • $X.Y = ||X|||Y||cos(\theta)$ where $\theta$ is the angle between $X$ and $Y$. In case of $P-A$ and $B-A$, $\theta$ simply is zero because $P$ is on the line segment $AB$. Therefore, $$(P-A).(B-A) = ||P-A||B-A||cos(0) = ||P-A||B-A||$$ – N.M. Mar 20 '15 at 04:03
  • @Kyselejsyreček, in your way of representing scalar product, use the fact that $$\frac{x_p-x_a}{x_b-x_a}=\frac{y_p-y_a}{y_b-y_a} = t$$ where $t$ is in $[0,1]$. – N.M. Mar 20 '15 at 04:13
  • These equations are awesome, thank you very much. :-) I feel really stupid for not realizing such elementary facts. – Kyselejsyreček Mar 20 '15 at 21:55