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.
The three numbers
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
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
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:
But r^2 = a^2 + b^2 + c^2 by definition. So
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
and they always satisfy
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.
An important consequence: each direction cosine lies between -1 and +1, because the angles \alpha, \beta, \gamma range from 0° 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
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.
Converting d.r.'s to d.c.'s. Given direction ratios (a, b, c), the direction cosines are
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:
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.
Use the cosine rule on triangle AOB. You know OA = 1, OB = 1, and
Expand:
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:
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:
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
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:
Special cases.
- Perpendicular lines: \cos\theta = 0, so l_1 l_2 + m_1 m_2 + n_1 n_2 = 0. In terms of direction ratios: a_1 a_2 + b_1 b_2 + c_1 c_2 = 0.
- Parallel lines: the direction cosines are equal (or negatives of each other): (l_1, m_1, n_1) = \pm(l_2, m_2, n_2). In terms of direction ratios: \dfrac{a_1}{a_2} = \dfrac{b_1}{b_2} = \dfrac{c_1}{c_2}.
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.
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}.
Why: to convert direction ratios to direction cosines, you divide each by this normalising factor r.
Step 3. Divide each direction ratio by r.
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).
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.
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.
Why: this is the sum of pairwise products — the dot product of the two direction-ratio triples.
Step 3. Apply the formula.
Why: dividing the dot product by r_1 r_2 normalises it, giving the cosine of the angle directly.
Step 4. Find \theta.
Result: The angle between the two lines is \cos^{-1}(4/9), approximately 63.6°.
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 0° and 90°. If the dot product had been zero, the lines would be perpendicular.
Common confusions
-
"A line has unique direction cosines." Not quite — a line extends in two opposite directions. If (l, m, n) are direction cosines, so are (-l, -m, -n). By convention, you often pick the one with a positive leading component, but the choice is a convention, not a mathematical fact.
-
"Direction ratios are unique." They are not. Any scalar multiple of a set of direction ratios is also a valid set of direction ratios. (1, 2, 3) and (2, 4, 6) and (-10, -20, -30) all describe the same direction. Direction cosines are the normalised version; direction ratios are the un-normalised version.
-
"\alpha + \beta + \gamma = 180°." This is false. The three angles are measured from different axes and do not have to add up to any specific value. For example, the line toward (1, 1, 1) has \alpha = \beta = \gamma \approx 54.74°, and 54.74° \times 3 \approx 164.2°, which is not 180°. The correct constraint is \cos^2\alpha + \cos^2\beta + \cos^2\gamma = 1.
-
"If one direction cosine is zero, the line lies in a coordinate plane." Partially correct. If n = 0 (\gamma = 90°), the line is perpendicular to the z-axis, meaning it is parallel to the xy-plane. But it need not lie in the xy-plane — it could be at any height. Saying the line is perpendicular to an axis is different from saying it lies in a plane.
-
"The angle between two lines is always acute." By convention, the angle between two undirected lines is taken between 0° and 90°. If the formula gives an obtuse angle, you take the supplement. But if the lines are directed (like vectors), the angle can range from 0° to 180°.
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 0° 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
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.
- Straight Line in 3D — Equations — using direction cosines (or ratios) and a known point to write the equation of a line in vector, Cartesian, and parametric form.
- 3D Coordinates — the coordinate system that direction cosines are built on, if you need to revisit it.
- Dot Product — the vector operation that generalises the angle formula you just derived.
- Collinearity and Coplanarity — using direction ratios to test whether points lie on the same line or in the same plane.
- Straight Line in 3D — Angles and Distances — what happens when you need the angle or shortest distance between two lines that do not intersect.