We have $\cos \theta$ = Angle between two lines (expressed in terms of direction ratios). So for line segment AB we have the direction ratios as $(x_2-x_1, y_2-y_1, z_2-z_1)$ and the line on which it is to be projected has direction ratios proportional to $l,m,n$ respectively.
Hence we have $$\cos \theta = \frac{(x_2-x_1)l + (y_2-y_1)m + (z_2-z_1)n}{\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2} \times \sqrt{l^2 + m^2 + n^2}}$$. But we have the property $$l^2 + m^2 + n^2 =1$$. So, our angle simplifies into $$\cos \theta = \frac{(x_2-x_1)l + (y_2-y_1)m + (z_2-z_1)n}{\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2}}$$. Hope it helps.
We have $\cos \theta$ = Angle between two lines (expressed in terms of direction ratios). So for line segment AB we have the direction ratios as $(x_2-x_1, y_2-y_1, z_2-z_1)$ and the line on which it is to be projected has direction ratios proportional to $l,m,n$ respectively.
Hence we have $$\cos \theta = \frac{(x_2-x_1)l + (y_2-y_1)m + (z_2-z_1)n}{\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2} \times \sqrt{l^2 + m^2 + n^2}}$$. But we have the property $$l^2 + m^2 + n^2 =1$$. So, our angle simplifies into $$\cos \theta = \frac{(x_2-x_1)l + (y_2-y_1)m + (z_2-z_1)n}{\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2}}$$. Hope it helps.