How to find the closest point on a line from a point ?
How to find the vector on the line that best approximates the given vector b (the closest point on the line)
then p is the point on the line that is closest to b.
Among all the points on the line <math>\{ \alpha.a : \alpha \in \mathbb{R}\}</math> , the closest to b is the point p on such that b − p is orthogonal to a
Line is the x-axis, i.e. the set <math>\{(x, y) : y = 0\}</math>
, and point is (b1, b2).
Lemma states: closest point on the line is p = (b1, 0).
Let q be any point on L. The three points q, p, and b
form a triangle.
For any vector b and any vector a, define vectors <math>b^{||a}</math> and <math>b^{\perp a}</math> to be the projection of b onto Span {a} and the projection of b orthogonal to a if: <MATH> b = b^{||a} + b^{\perp a} </MATH> where:
Then the following formulas are equivalent: <MATH> \begin{array}{lrlll} b & = & b^{||a} & + & b^{\perp a} \\ b & = & \sigma a & + & b^{\perp a} \\ b^{\perp a} & = & b & - & \sigma a \\ \end{array} </MATH>
One-dimensional Lemma: The point in Span {a} closest to b is <math>b^{||a}</math> and the distance is the norm <math>\|b^{\perp a}\|</math> .
For any vector b and vector a over the reals,
<math> \begin{array}{llll} \langle b^{\perp a}, a \rangle & = & 0 & \text{as } b^{\perp a} \text{ is orthogonal to a} \\ \langle b - b^{|| a}, a \rangle & = & 0 & \text{Substituion of b} \\ \langle b, a \rangle - sigma \langle a, a \rangle & = & 0 & \text{Using linearity and homogeneity of inner product} \\ \sigma & = & \frac{\displaystyle \langle b, a \rangle}{\displaystyle \langle a, a \rangle} & \text{Solving for } \sigma \end{array} </math>
# �Find the vector (point) in Span a (line) that is closest to vector b (point):
# Projection along (or onto) a
# b || a
def project_along(b, a):
# because of floating-point roundoff error a*a > 1e-20 in place of a*a = 0
sigma = (b*a)/(a*a) if a*a > 1e-20 else 0
return sigma * a
# Projection to a
# b perp a
def project_orthogonal(b, a):
return b - project_along(b, a)
a = [6, 2] and b = [2, 4].
The closest point on the line <math>\{ \alpha a : \alpha \in \mathbb{R}\}</math> is the point <math>b^{||a} = \sigma a</math> where:
<MATH> \begin{array}{rrr} \sigma & = & \frac{a.b}{a.a} & = & \frac{6.2 + 2.4}{6.6 + 2.2} & = & \frac{20}{40} & = & \frac{1}{2} \end{array} </MATH>
thus: