Since, one and only one line passes through two given points, we can determine the direction cosines of a line passing through the given points P(x1,y1,z1) and Q(x2,y2,z2) as follows
Let l,m and n be the direction cosines of the line PQ and let it makes angles α,β and γ with the X,Y and Z-axes, respectively.
Draw perpendiculars from P and Q to xy-plane to meet at R and S. Draw a perpendicular from P to QS to meet at N. Now, in right angled △PNQ,∠PQN=γ from (figure).
Therefore, cosγ=PQNQ=PQz2−z1
Similarly, cosα=PQx2−x1
and cosβ=PQy2−y1
Hence, the direction cosines of the line segment joining the points P(x1,y1,z1) and Q(x2,y2,z2) are PQx2−x1,PQy2−y1,PQz2−z1 where, PQ=PQx2−x1,PQy2−y1,PQz2−z1