Direction Cosines of a Line Through Two Points in 3D

December 29, 2025

Problem

explain and visualise this

Explanation

We want the direction cosines of the line passing through the two points

P(2,4,5)andQ(1,2,3).P(-2, 4, -5) \quad\text{and}\quad Q(1, 2, 3).

1. Direction vector of the line

A line through two points P(x1,y1,z1)P(x_1, y_1, z_1) and Q(x2,y2,z2)Q(x_2, y_2, z_2) has a direction vector

PQ=(x2x1,  y2y1,  z2z1).\vec{PQ} = (x_2 - x_1,\; y_2 - y_1,\; z_2 - z_1).

For the given points:

  • P(2,4,5)P(-2, 4, -5)
  • Q(1,2,3)Q(1, 2, 3)

Compute PQ\vec{PQ}:

PQ=(1(2),  24,  3(5))=(3,2,8).\vec{PQ} = (1 - (-2),\; 2 - 4,\; 3 - (-5)) = (3, -2, 8).

This vector gives the direction of the line, but not yet the direction cosines.


2. Length of the direction vector PQPQ

The length (magnitude) of PQ\vec{PQ} is

PQ=PQ=(x2x1)2+(y2y1)2+(z2z1)2.PQ = \lVert \vec{PQ} \rVert = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2}.

Substitute the values:

PQ=(1(2))2+(24)2+(3(5))2=32+(2)2+82=9+4+64=77.\begin{aligned} PQ &= \sqrt{(1 - (-2))^2 + (2 - 4)^2 + (3 - (-5))^2} \\ &= \sqrt{3^2 + (-2)^2 + 8^2} \\ &= \sqrt{9 + 4 + 64} \\ &= \sqrt{77}. \end{aligned}

3. Direction cosines

The direction cosines (l,m,n)(l, m, n) of a line are the cosines of the angles that the line makes with the positive xx, yy, and zz axes respectively. If v=(a,b,c)\vec{v} = (a, b, c) is a direction vector, then the unit direction vector is

v^=1v(a,b,c).\hat{v} = \frac{1}{\lVert\vec{v}\rVert}(a, b, c).

Its components are exactly the direction cosines:

(l,m,n)=(av,  bv,  cv).(l, m, n) = \left(\frac{a}{\lVert\vec{v}\rVert},\; \frac{b}{\lVert\vec{v}\rVert},\; \frac{c}{\lVert\vec{v}\rVert}\right).

For our line, PQ=(3,2,8)\vec{PQ} = (3, -2, 8) and PQ=77\lVert\vec{PQ}\rVert = \sqrt{77}, so

(l,m,n)=(377,  277,  877).(l, m, n) = \left(\frac{3}{\sqrt{77}},\; \frac{-2}{\sqrt{77}},\; \frac{8}{\sqrt{77}}\right).

These are the required direction cosines.


4. What the visualization shows

The interactive canvas will display:

  1. A 3D-like coordinate box (x,y,zx, y, z axes) in perspective.
  2. The two points P(2,4,5)P(-2,4,-5) and Q(1,2,3)Q(1,2,3) plotted inside this box.
  3. The vector PQ\vec{PQ} drawn as an arrow from PP to QQ (neon cyan).
  4. A unit direction vector in the same direction (neon yellow), whose components are exactly the direction cosines.
  5. Projections of the direction vector onto the three coordinate axes, to visually connect the components 3,2,83, -2, 8 with the angles and the cosines.

Interactivity

  • Rotation: Use the Rotation slider to rotate the viewing angle around the vertical axis, so you can see how the line sits in 3D space.
  • Scale: Use the Scale slider to zoom in/out on the 3D box and the points.
  • Animate: Use the Auto Rotate toggle to automatically rotate the scene and better perceive the 3D geometry.

As you adjust the view, notice that:

  • The direction of the line is fixed by the vector from PP to QQ.
  • The unit vector in this direction has components (377,  277,  877)\left(\frac{3}{\sqrt{77}},\; \frac{-2}{\sqrt{77}},\; \frac{8}{\sqrt{77}}\right), which are the direction cosines.
  • Even though the drawing is in 2D (on the screen), rotation and projection help you see how this line relates to the three axes and why the cosines describe its orientation.

Interactive Visualization

Parameters

60.00
35.00
20.00
Direction Cosines of a Line Through Two Points in 3D