In short

A line in 3D has a direction, described by three direction cosines l, m, n — the cosines of the angles the line makes with the x-, y-, and z-axes. They always satisfy l^2 + m^2 + n^2 = 1. Direction ratios are any triple proportional to (l, m, n), easier to work with but not unique. The angle between two lines follows from the dot product of their direction cosines.

Hold a stick in the air. Tilt it any way you like. Now ask: which way is it pointing?

In two dimensions, a single angle answered this question — the angle the line makes with the positive x-axis. But a stick floating in 3D space can tilt forward, sideways, and vertically, all at once. One angle is no longer enough. You need three.

The idea is simple. Measure the angle your stick makes with each of the three coordinate axes. Call them \alpha, \beta, and \gamma — the angles with the x-, y-, and z-axes respectively. These three angles, or more precisely their cosines, pin down the direction of the stick completely.

Why cosines and not the angles themselves? Because cosines behave algebraically — you can add them, square them, and plug them into formulas. Raw angles do not combine as cleanly. The cosines \cos\alpha, \cos\beta, \cos\gamma turn direction into numbers you can compute with.

Direction cosines

Take a line L passing through the origin. (Any parallel line has the same direction, so you can always shift it to pass through the origin without changing the direction.) Let this line make angles \alpha, \beta, \gamma with the positive x-axis, the positive y-axis, and the positive z-axis respectively.

A line in 3D making angles alpha, beta, gamma with the three axes A perspective drawing showing a line through the origin and the three angles it makes with the x, y, and z axes. The angle alpha is between the line and the x-axis, beta is between the line and the y-axis, and gamma is between the line and the z-axis. z y x L O α β γ
A line $L$ through the origin makes angles $\alpha$, $\beta$, $\gamma$ with the $x$-, $y$-, and $z$-axes. The cosines of these three angles are the direction cosines of the line.

The three numbers

l = \cos\alpha, \quad m = \cos\beta, \quad n = \cos\gamma

are called the direction cosines (d.c.'s) of the line.

If the line does not pass through the origin, draw a parallel line that does, and use its angles. Parallel lines share the same direction, so they have the same direction cosines.

Reading them off from a point

Here is a concrete way to compute direction cosines. Suppose a line passes through the origin O and through a point P = (a, b, c). The distance from O to P is r = \sqrt{a^2 + b^2 + c^2}.

Look at the angle \alpha between the line OP and the x-axis. The projection of OP onto the x-axis has length a (the x-coordinate of P). By the definition of cosine in a right triangle — adjacent over hypotenuse — you get

\cos\alpha = \frac{a}{r}

Similarly, \cos\beta = \dfrac{b}{r} and \cos\gamma = \dfrac{c}{r}.

So the direction cosines of the line from the origin to (a, b, c) are

l = \frac{a}{r}, \quad m = \frac{b}{r}, \quad n = \frac{c}{r}

where r = \sqrt{a^2 + b^2 + c^2}.

Quick check: the line from the origin to (1, 1, 1) has r = \sqrt{3} and direction cosines \left(\frac{1}{\sqrt{3}},\; \frac{1}{\sqrt{3}},\; \frac{1}{\sqrt{3}}\right). This line makes equal angles with all three axes — it is the "main diagonal" of a cube, and by symmetry, the three angles \alpha = \beta = \gamma must all be equal. Indeed they are: each is \cos^{-1}(1/\sqrt{3}) \approx 54.74°.

Another check: the line from the origin to (1, 0, 0) has r = 1 and direction cosines (1, 0, 0). That is the positive x-axis itself — it makes \alpha = 0° with the x-axis (so \cos\alpha = 1) and \beta = \gamma = 90° with the other two axes (so \cos 90° = 0). The formula confirms what the picture says.

Notice that the formula l = a/r uses the signed coordinate a, not its absolute value. If a is negative, then l is negative, meaning the angle \alpha is obtuse (between 90° and 180°). The sign carries geometric information: a negative direction cosine tells you the line tilts away from the corresponding positive axis direction.

The fundamental identity: l^2 + m^2 + n^2 = 1

Direction cosines always satisfy a clean identity.

Derivation

Start from the formulas l = a/r, m = b/r, n = c/r. Square each and add:

l^2 + m^2 + n^2 = \frac{a^2}{r^2} + \frac{b^2}{r^2} + \frac{c^2}{r^2} = \frac{a^2 + b^2 + c^2}{r^2}

But r^2 = a^2 + b^2 + c^2 by definition. So

l^2 + m^2 + n^2 = \frac{r^2}{r^2} = 1

That is the entire proof. It is a consequence of the Pythagorean theorem — the same theorem that gave you the distance formula.

Direction cosines and the fundamental identity

If a line makes angles \alpha, \beta, \gamma with the positive x-, y-, z-axes, its direction cosines are

l = \cos\alpha, \quad m = \cos\beta, \quad n = \cos\gamma

and they always satisfy

l^2 + m^2 + n^2 = 1

This identity is a constraint. You cannot choose l, m, n independently — once you know any two, the third is determined (up to sign). Geometrically, the point (l, m, n) always lies on the unit sphere x^2 + y^2 + z^2 = 1. The direction cosines of a line are a unit vector pointing along that line.

A 2D cross-section of the unit sphere: the circle $l^2 + m^2 = 1$ (setting $n = 0$). Every point on this circle represents a valid pair of direction cosines for a line in the $xy$-plane. The constraint $l^2 + m^2 + n^2 = 1$ forces all direction-cosine triples onto the surface of the unit sphere in 3D.

An important consequence: each direction cosine lies between -1 and +1, because the angles \alpha, \beta, \gamma range from to 180°. (Each angle is measured from a positive axis direction to the line, so 0° \leq \alpha, \beta, \gamma \leq 180°.)

Another way to read the identity: since \cos^2\alpha + \cos^2\beta + \cos^2\gamma = 1, you can think of l^2, m^2, n^2 as three non-negative numbers that add up to 1. They tell you how the line's direction is "distributed" among the three coordinate axes. A line pointing mostly along the x-axis has l^2 close to 1 and m^2, n^2 close to 0. A line equally inclined to all three axes has l^2 = m^2 = n^2 = 1/3 — each axis gets an equal share of the direction.

Direction ratios

Working with direction cosines requires computing r = \sqrt{a^2 + b^2 + c^2} and dividing — messy when r is irrational. Often you do not need the exact direction cosines; you just need some set of numbers proportional to them. These are called direction ratios (d.r.'s).

Direction ratios

Any three numbers a, b, c (not all zero) such that

\frac{l}{a} = \frac{m}{b} = \frac{n}{c}

are called direction ratios of the line with direction cosines (l, m, n).

Equivalently, a, b, c are direction ratios of a line if (l, m, n) = \left(\frac{a}{r},\; \frac{b}{r},\; \frac{c}{r}\right) where r = \sqrt{a^2 + b^2 + c^2}.

Key difference: direction cosines are unique (up to sign — each line has two opposite directions), but direction ratios are not unique. If (2, 3, 6) are direction ratios, so are (4, 6, 12), (-2, -3, -6), and (20, 30, 60). Any scalar multiple works. Direction ratios tell you the proportion of the direction, not its exact cosines.

Direction ratios $(2, 3)$, $(4, 6)$, and $(1, 1.5)$ all point in the same direction — they are scalar multiples of each other. The red arrow and both dashed arrows lie on the same line through the origin. Direction ratios encode *proportion*, not magnitude.

Converting d.r.'s to d.c.'s. Given direction ratios (a, b, c), the direction cosines are

l = \frac{a}{\sqrt{a^2 + b^2 + c^2}}, \quad m = \frac{b}{\sqrt{a^2 + b^2 + c^2}}, \quad n = \frac{c}{\sqrt{a^2 + b^2 + c^2}}

with a \pm in front (depending on which direction along the line you choose).

Direction ratios from two points. If a line passes through P(x_1, y_1, z_1) and Q(x_2, y_2, z_2), then the direction ratios are simply the differences:

(x_2 - x_1, \; y_2 - y_1, \; z_2 - z_1)

This is the most common way direction ratios arise in problems. You do not need the distance formula — just subtract coordinates.

The angle between two lines

If two lines have direction cosines (l_1, m_1, n_1) and (l_2, m_2, n_2), you can find the angle between them without drawing anything.

Derivation

Place both lines through the origin (they define the same angle regardless of where they start). Take a point A = (l_1, m_1, n_1) on the first line at unit distance from O, and a point B = (l_2, m_2, n_2) on the second line at unit distance from O. The angle \theta between the two lines is the angle \angle AOB.

Triangle OAB for the angle between two lines A triangle with vertex O at the origin and points A and B each at unit distance from O. The angle theta is at vertex O. The sides OA and OB both have length 1 because A and B are chosen on the unit sphere. The side AB connects the two points. O A B OA = 1 OB = 1 AB θ
The triangle $OAB$: both $A$ and $B$ are at unit distance from $O$ (they lie on the unit sphere). The angle $\theta$ at $O$ is the angle between the two lines. The cosine rule applied to this triangle gives the angle formula.

Use the cosine rule on triangle AOB. You know OA = 1, OB = 1, and

AB^2 = (l_2 - l_1)^2 + (m_2 - m_1)^2 + (n_2 - n_1)^2

Expand:

AB^2 = l_2^2 - 2l_1l_2 + l_1^2 + m_2^2 - 2m_1m_2 + m_1^2 + n_2^2 - 2n_1n_2 + n_1^2

Group the squared terms. Since l_1^2 + m_1^2 + n_1^2 = 1 and l_2^2 + m_2^2 + n_2^2 = 1:

AB^2 = 1 + 1 - 2(l_1l_2 + m_1m_2 + n_1n_2) = 2 - 2(l_1l_2 + m_1m_2 + n_1n_2)

Now apply the cosine rule: AB^2 = OA^2 + OB^2 - 2 \cdot OA \cdot OB \cdot \cos\theta = 2 - 2\cos\theta.

Comparing the two expressions for AB^2:

2 - 2\cos\theta = 2 - 2(l_1l_2 + m_1m_2 + n_1n_2)
\cos\theta = l_1l_2 + m_1m_2 + n_1n_2

This is a remarkably clean result. The angle between two directions in 3D — a question that sounds like it should involve complicated trigonometry — reduces to multiplying the corresponding direction cosines and adding.

Angle between two lines

If two lines have direction cosines (l_1, m_1, n_1) and (l_2, m_2, n_2), the angle \theta between them satisfies

\cos\theta = l_1 l_2 + m_1 m_2 + n_1 n_2

This is the dot product of the two direction-cosine triples. If you have already met vectors, this is the same as \hat{a} \cdot \hat{b} where \hat{a} and \hat{b} are unit vectors along the two lines. The formula shows that the dot product has a geometric meaning: it is the cosine of the angle.

Using direction ratios. If you have direction ratios (a_1, b_1, c_1) and (a_2, b_2, c_2) instead of direction cosines, you can still find the angle. Replace each l with a/r and simplify:

\cos\theta = \frac{a_1 a_2 + b_1 b_2 + c_1 c_2}{\sqrt{a_1^2 + b_1^2 + c_1^2}\;\sqrt{a_2^2 + b_2^2 + c_2^2}}

Special cases.

Computing one from start to finish

Example 1: Direction cosines of a line joining two points

Find the direction cosines of the line joining A(2, 1, -2) and B(4, 4, -5).

Step 1. Compute the direction ratios from the coordinate differences.

a = 4 - 2 = 2, \quad b = 4 - 1 = 3, \quad c = -5 - (-2) = -3

Why: direction ratios are simply the differences in coordinates — they encode how much you move along each axis to get from A to B.

Step 2. Compute r = \sqrt{a^2 + b^2 + c^2}.

r = \sqrt{4 + 9 + 9} = \sqrt{22}

Why: to convert direction ratios to direction cosines, you divide each by this normalising factor r.

Step 3. Divide each direction ratio by r.

l = \frac{2}{\sqrt{22}}, \quad m = \frac{3}{\sqrt{22}}, \quad n = \frac{-3}{\sqrt{22}}

Why: after dividing, the triple (l, m, n) satisfies l^2 + m^2 + n^2 = 1, confirming these are proper direction cosines.

Step 4. Verify: l^2 + m^2 + n^2 = \dfrac{4}{22} + \dfrac{9}{22} + \dfrac{9}{22} = \dfrac{22}{22} = 1. Confirmed.

Result: The direction cosines are \left(\dfrac{2}{\sqrt{22}},\;\dfrac{3}{\sqrt{22}},\;\dfrac{-3}{\sqrt{22}}\right).

A projection of the segment $AB$ onto the $x$-$z$ plane (horizontal axis is $x$, vertical axis is $z$). The dashed lines show the component displacements: $\Delta x = 2$ and $\Delta z = -3$. The full direction has three components $(2, 3, -3)$, but only two are visible in this projection.

The direction ratios (2, 3, -3) tell you the "recipe" for moving from A to B: go 2 in x, 3 in y, and -3 in z. The direction cosines normalise this recipe to unit length.

Example 2: Angle between two lines

Find the angle between the line with direction ratios (1, 2, 2) and the line with direction ratios (2, -1, 2).

Step 1. Compute r_1 and r_2.

r_1 = \sqrt{1 + 4 + 4} = \sqrt{9} = 3, \quad r_2 = \sqrt{4 + 1 + 4} = \sqrt{9} = 3

Why: to use the angle formula, you need either direction cosines or the general formula with direction ratios in the denominator. Here r_1 and r_2 both turn out to be 3, which keeps the arithmetic clean.

Step 2. Compute the numerator a_1 a_2 + b_1 b_2 + c_1 c_2.

1 \cdot 2 + 2 \cdot (-1) + 2 \cdot 2 = 2 - 2 + 4 = 4

Why: this is the sum of pairwise products — the dot product of the two direction-ratio triples.

Step 3. Apply the formula.

\cos\theta = \frac{4}{3 \times 3} = \frac{4}{9}

Why: dividing the dot product by r_1 r_2 normalises it, giving the cosine of the angle directly.

Step 4. Find \theta.

\theta = \cos^{-1}\!\left(\frac{4}{9}\right) \approx 63.6°

Result: The angle between the two lines is \cos^{-1}(4/9), approximately 63.6°.

A 2D projection showing the $x$- and $y$-components of the two direction vectors emanating from the origin. The actual angle in 3D is $\cos^{-1}(4/9) \approx 63.6°$ — the projection distorts this, but the two directions are clearly not parallel and not perpendicular.

The dot product a_1 a_2 + b_1 b_2 + c_1 c_2 = 4 is positive but less than r_1 r_2 = 9, confirming an acute angle between and 90°. If the dot product had been zero, the lines would be perpendicular.

Common confusions

Going deeper

If you are comfortable finding direction cosines from direction ratios and computing angles between lines, you have the essentials — you can stop here. The following sections cover subtleties and connections that appear in harder problems.

Direction cosines of the coordinate axes

The three coordinate axes have the simplest possible direction cosines:

Axis Direction cosines (l, m, n)
x-axis (1, 0, 0)
y-axis (0, 1, 0)
z-axis (0, 0, 1)

The x-axis makes an angle of with itself, 90° with the y-axis, and 90° with the z-axis. So l = \cos 0° = 1, m = \cos 90° = 0, n = \cos 90° = 0. The other two rows follow the same pattern. You can verify l^2 + m^2 + n^2 = 1 for each.

Check the angle formula: the angle between the x-axis (1, 0, 0) and the y-axis (0, 1, 0) is \cos\theta = 1 \cdot 0 + 0 \cdot 1 + 0 \cdot 0 = 0, so \theta = 90°. The axes are perpendicular — exactly right.

Lines equally inclined to all three axes

What if \alpha = \beta = \gamma? Then l = m = n, and from l^2 + m^2 + n^2 = 1 you get 3l^2 = 1, so l = \pm 1/\sqrt{3}.

The direction cosines are (1/\sqrt{3}, 1/\sqrt{3}, 1/\sqrt{3}) — or the same triple with all signs flipped, which gives the opposite direction along the same line. This is the line from the origin toward the corner (1, 1, 1) of a unit cube — the main diagonal of the cube.

A common trap: the triple (1/\sqrt{3}, -1/\sqrt{3}, -1/\sqrt{3}) has l^2 + m^2 + n^2 = 1, so it is a valid set of direction cosines. But it does not represent a line equally inclined to all three axes. The angle with the x-axis is \cos^{-1}(1/\sqrt{3}) \approx 54.7°, while the angles with the y- and z-axes are \cos^{-1}(-1/\sqrt{3}) \approx 125.3°. The three angles are not equal. For \alpha = \beta = \gamma, you need all three cosines to be equal in sign as well as magnitude.

Direction cosines of a line not through the origin

Given a line through two general points P_1(x_1, y_1, z_1) and P_2(x_2, y_2, z_2), the direction ratios are the coordinate differences (x_2 - x_1, y_2 - y_1, z_2 - z_1). Letting d = P_1P_2 = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}, the direction cosines are

l = \frac{x_2 - x_1}{d}, \quad m = \frac{y_2 - y_1}{d}, \quad n = \frac{z_2 - z_1}{d}

This is consistent with the earlier formula: you are taking the displacement vector from P_1 to P_2 and dividing by its magnitude to get a unit vector. The direction cosines do not depend on where the line is — only on which way it points.

Connection to unit vectors

If you have studied vectors, you already know that a unit vector \hat{r} = l\,\hat{i} + m\,\hat{j} + n\,\hat{k} has components (l, m, n) that are the direction cosines of the line along \hat{r}. The condition l^2 + m^2 + n^2 = 1 is the same as |\hat{r}| = 1. Direction cosines are the scalar components of a unit vector — two languages for the same object.

The angle formula \cos\theta = l_1 l_2 + m_1 m_2 + n_1 n_2 is the dot product \hat{r}_1 \cdot \hat{r}_2. So the entire theory of direction cosines is a special case of vector algebra applied to unit vectors. When you reach vectors, you will see these results again from a more powerful vantage point.

Condition for perpendicularity — a pattern

Two lines are perpendicular when l_1 l_2 + m_1 m_2 + n_1 n_2 = 0, or equivalently a_1 a_2 + b_1 b_2 + c_1 c_2 = 0 in terms of direction ratios. This looks the same as the 2D condition a_1 a_2 + b_1 b_2 = 0 for slopes -a/b — but extended to three dimensions. In 2D, perpendicularity is one equation in two unknowns. In 3D, it is one equation in three unknowns, which means there are infinitely many directions perpendicular to a given line. They form a plane. This idea — that perpendicularity in 3D defines a plane, not just one line — is crucial for understanding planes and normal vectors.

Where this leads next

Direction cosines give you the language to describe directions in space. The next step is to combine a direction with a point to write down the equation of a line.