Distance \(D\) of a Point \(C\) having Position Vector \(\vec{C}\) from any Line in 2D, 3D or Higher Dimensions having Direction Ratio \(\vec{A}\) containing a Point \(B\) having Position Vector \(\vec{B}\)
is calculated as the Length of Rejection of Vector \(\vec{CB}\) from Vector \(\vec{A}\) as follows
\(D=|{\vec{CB}}_{\perp}|=|\vec{CB} - {\vec{CB}}_{||}|=|\vec{CB} - \frac{(\vec{A} \cdot \vec{CB})\vec{A}}{{|\vec{A}|}^2}|\) (In 2D, 3D and Higher Dimensions) ...(1)
\(D = |\vec{CB}| \sin (\theta) = \frac{|\vec{A}||\vec{CB}| sin (\theta)}{|\vec{A}|} = \frac{|\vec{A}\times\vec{CB}|}{|\vec{A}|}\) (In 2D and 3D only) ...(2)
where \(\theta=\)Angle Between the Vectors \(\vec{CB}\) and \(\vec{A}\)
The Distance of a Origin from the Line (i.e. when Position Vector \(\vec{C}=\vec{0}\) or NULL Vector ) is given as
\(D=|{\vec{B}}_{\perp}|=|\vec{B} - {\vec{B}}_{||}|=|\vec{B} - \frac{(\vec{A} \cdot \vec{B})\vec{A}}{{|\vec{A}|}^2}|\) (In 2D, 3D and Higher Dimensions) ...(3)
\(D = |\vec{B}| \sin (\theta) = \frac{|\vec{A}||\vec{B}| sin (\theta)}{|\vec{A}|} = \frac{|\vec{A}\times\vec{B}|}{|\vec{A}|}\) (In 2D and 3D only) ...(4)
where \(\theta=\)Angle Between the Vectors \(\vec{B}\) and \(\vec{A}\)
The Distance \(D\) can also be calculated by First finding the Vector \(\vec{CB_\perp}\) (or \(\vec{B_\perp}\)) and then calculating their Length.
Please note that Distance \(D\) calculated using this method or any of the methods given in equations (1), (2), (3) and (4) is always a Positive Value (i.e. they always calculate an Unsigned Distance Value).
Distance \(D\) of a Point \(C\) having Position Vector \(\vec{C}\) from any Line in 2D (or on any Plane in 3D or on any Hyper-Plane in Higher Dimensions) having Direction Ratio of Normal \(\vec{A}\) containing a Point \(B\) having Position Vector \(\vec{B}\)
is calculated as the Length of Projection of Vector \(\vec{CB}\) on Vector \(\vec{A}\) as follows
Please note that the Distance \(D\) calculated using methods given in equations (5) and (6) can be either Positive or Negative (i.e. they always calculate a Signed Distance Value).
The value of Distance is Positive if Angle Between Vector \(\vec{A}\) and \(\vec{CB}\) (or Angle Between Vector \(\vec{A}\) and \(\vec{B}\)) is less than 90\(^\circ\).
The value of Distance is Negative if Angle Between Vector \(\vec{A}\) and \(\vec{CB}\) (or Angle Between Vector \(\vec{A}\) and \(\vec{B}\)) is greater than 90\(^\circ\).
The Distance \(D\) can also be calculated by First finding the Vector \(\vec{CB_{||}}\) (or \(\vec{B_{||}}\)) and then calculating their Length.
However, the Distance \(D\) calculated using this method is always a Positive Value (i.e. they always calculate an Unsigned Distance Value).
The Signed Distance Value of a Point from any Line in 2D (or on any Plane in 3D or on any Hyper-Plane in Higher Dimensions) can also be calculated from the
Coordinate Equations of the Line / Plane / Hyperplane.
For example, in 2 Dimensions the Signed Distance Value \(D\) of a Point having Coordinates (\(x_c,y_c\)) from Line having Coordinate Equation \(ax + by + c=0\) is given as
\(D=\frac{ax_c + by_c + c}{\sqrt{a^2 + b^2}}\hspace{6mm}\Rightarrow D=\frac{c}{\sqrt{a^2 + b^2}}\) (Distance from the Origin when \(x_c=0\) and \(y_c=0\)) ...(7)
Similarly, in 3 Dimensions the Signed Distance Value \(D\) of a Point having Coordinates (\(x_c,y_c,z_c\)) from Plane having Coordinate Equation \(ax + by + cz +d =0\) is given as
\(D=\frac{ax_c + by_c + cz_c + d}{\sqrt{a^2 + b^2 + c^2}}\hspace{6mm}\Rightarrow D=\frac{d}{\sqrt{a^2 + b^2 + c^2}}\) (Distance from the Origin when \(x_c=0\), \(y_c=0\) and \(z_c=0\)) ...(8)
Likewise, in Any Arbirary N Dimensions (where \(N \geq 2\)) the Signed Distance Value \(D\) of a Point having Coordinates (\(x_{1c},x_{2c},x_{3c},\cdots,x_{nc}\)) from Line / Plane / Hyper Plane having Coordinate Equation \(a_1x_1 + a_2x_2 + a_3x_3 + \cdots + a_nx_n + a_{n+1}=0\) is given as
\(D=\frac{a_1x_{1c}\hspace{1mm}+\hspace{1mm}a_2x_{2c}\hspace{1mm}+\hspace{1mm}a_3x_{3c}\hspace{1mm}+\hspace{1mm}\cdots\hspace{1mm}+\hspace{1mm}a_nx_{nc}\hspace{1mm}+\hspace{1mm}a_{n+1}}{\sqrt{{a_1}^2\hspace{1mm}+\hspace{1mm}{a_2}^2\hspace{1mm}+\hspace{1mm}{a_3}^2\hspace{1mm}+\hspace{1mm}\cdots\hspace{1mm}+\hspace{1mm}{a_n}^2}}\hspace{6mm}\Rightarrow D=\frac{a_{n+1}}{\sqrt{{a_1}^2\hspace{1mm}+\hspace{1mm}{a_2}^2\hspace{1mm}+\hspace{1mm}{a_3}^2\hspace{1mm}+\hspace{1mm}\cdots\hspace{1mm}+\hspace{1mm}{a_n}^2}}\) (Distance from the Origin when \(x_{1c}=x_{2c}=x_{3c}=\cdots=x_{nc}=0\)) ...(9)
The formula for calculating Signed Distance Value \(D\) can be derived as follows
We know that in any Any Arbirary N Dimensions (where \(N \geq 2\)), the Coordinate Equation of Line / Plane / Hyper Plane is given as
Also from equation (5) we know that the Signed Distance \(D\) of a Point \(C\) having Position Vector \(\vec{C}\) from any Line in 2D (or on any Plane in 3D or on any Hyper-Plane in Higher Dimensions) having Direction Ratio of Normal \(\vec{A}\) containing a Point \(B\) having Position Vector \(\vec{B}\)
is given as
Now, the values of Vectors \(\vec{A}\), \(\vec{B}\), \(\vec{C}\) and \(\vec{CB}\) corresponding to Coordinate Equation of Line / Plane / Hyper Plane in Any Arbirary N Dimensions is given as