In short
The angle between two lines in 3D is the angle between their direction vectors, found using the dot product: \cos\theta = \frac{|\vec{b}_1 \cdot \vec{b}_2|}{|\vec{b}_1||\vec{b}_2|}. Two lines are parallel when their direction vectors are proportional, and perpendicular when their dot product is zero. The perpendicular distance from a point to a line — and the foot of that perpendicular — are computed using the cross product or a parametric approach.
A railway track runs northeast from Jaipur. A highway cuts across the same region heading east. Stand at the crossing and look along both — there is an angle between them, and you can measure it with a protractor flat on the ground.
Now imagine the track is climbing uphill while the highway stays level. The two directions no longer share a flat plane. They tilt away from each other in three-dimensional space, and the angle between them is no longer something a flat protractor can handle. You need a tool that works in 3D.
That tool is the dot product. You already know that the dot product of two vectors encodes the cosine of the angle between them. The entire theory of angles between lines in space falls out of this one fact — combined with the equations of lines you built in the previous article.
Angle between two lines
Take two lines in space:
The direction of L_1 is given by \vec{b}_1 and the direction of L_2 by \vec{b}_2. The "angle between the two lines" means the angle between their directions — the vectors \vec{b}_1 and \vec{b}_2.
There is one subtlety. A line has no preferred "forward" direction: \vec{b} and -\vec{b} define the same line. The dot product \vec{b}_1 \cdot \vec{b}_2 might come out negative if the two direction vectors happen to point in roughly opposite senses, and that would give \cos\theta < 0, meaning an obtuse angle. But the angle between two undirected lines is always taken to be acute (or right). So you take the absolute value of the dot product.
Angle between two lines
If L_1 has direction vector \vec{b}_1 = a_1\hat{i} + b_1\hat{j} + c_1\hat{k} and L_2 has direction vector \vec{b}_2 = a_2\hat{i} + b_2\hat{j} + c_2\hat{k}, the angle \theta between them satisfies
where 0 \leq \theta \leq \dfrac{\pi}{2}.
Why the absolute value? Without it, you get the angle between the two directed vectors, which could be obtuse. The absolute value forces the result to be in [0, \pi/2], giving the acute angle between the undirected lines. If a problem specifically asks for the angle between two directed vectors (say, velocity vectors), drop the absolute value. But for lines, keep it.
Deriving it. The dot product formula says \vec{b}_1 \cdot \vec{b}_2 = |\vec{b}_1||\vec{b}_2|\cos\alpha, where \alpha is the angle between the vectors. Then \cos\alpha = \frac{\vec{b}_1 \cdot \vec{b}_2}{|\vec{b}_1||\vec{b}_2|}. The angle between the lines is \theta = \alpha if \alpha is acute, and \theta = \pi - \alpha if \alpha is obtuse. In both cases, \cos\theta = |\cos\alpha|, which gives the formula.
Parallel and perpendicular lines
Two special cases deserve their own names, because they come up constantly.
Parallel lines
Two lines are parallel if they have the same direction (or opposite directions — a line does not care about sign). This means their direction vectors are proportional:
Equivalently, \vec{b}_1 = k\vec{b}_2 for some non-zero scalar k, or \vec{b}_1 \times \vec{b}_2 = \vec{0} (their cross product is zero).
When lines are parallel, \cos\theta = 1, so \theta = 0.
Perpendicular lines
Two lines are perpendicular if the angle between them is \pi/2. Since \cos(\pi/2) = 0, the condition is:
No absolute value is needed here — if the dot product is zero, it is zero regardless of sign.
Here is a quick summary:
| Condition | Test |
|---|---|
| Parallel | \dfrac{a_1}{a_2} = \dfrac{b_1}{b_2} = \dfrac{c_1}{c_2}, or \vec{b}_1 \times \vec{b}_2 = \vec{0} |
| Perpendicular | a_1 a_2 + b_1 b_2 + c_1 c_2 = 0 |
Perpendicular distance from a point to a line
This is the most useful distance formula in 3D line geometry, and it shows up in nearly every exam.
The setup. You have a line L given in vector form \vec{r} = \vec{a} + \lambda\vec{b}, and a point P not on the line. You want the shortest distance from P to the line.
The geometric idea. Drop a perpendicular from P to the line. The foot of this perpendicular — call it M — is the point on the line closest to P. The distance PM is the perpendicular distance.
The cross-product formula
Let A be the known point on the line (with position vector \vec{a}), and let \vec{b} be the direction vector. The vector from A to P is \vec{AP} = \vec{p} - \vec{a}, where \vec{p} is the position vector of P.
Consider the parallelogram formed by \vec{AP} and \vec{b}. Its area is |\vec{AP} \times \vec{b}|. But this same parallelogram has base |\vec{b}| and height d (the perpendicular distance). So
Solving for d:
This is the formula. It is clean, it is fast, and it works every time.
Reading the formula. The cross product \vec{AP} \times \vec{b} gives you a vector whose magnitude is the area of the parallelogram spanned by \vec{AP} and \vec{b}. Dividing by the base length |\vec{b}| gives the height — which is exactly the perpendicular distance.
The Cartesian version
If the line is \frac{x - x_1}{a} = \frac{y - y_1}{b} = \frac{z - z_1}{c} and the point is P = (\alpha, \beta, \gamma), then \vec{AP} = (\alpha - x_1)\hat{i} + (\beta - y_1)\hat{j} + (\gamma - z_1)\hat{k} and \vec{b} = a\hat{i} + b\hat{j} + c\hat{k}. Compute the cross product, take its magnitude, and divide by \sqrt{a^2 + b^2 + c^2}. There is no need to memorise a separate Cartesian formula — the vector formula does the same job once you plug in components.
Foot of perpendicular
Often you need not just the distance but the foot of the perpendicular — the actual point M on the line closest to P.
The parametric method
Write a general point on the line as M = (x_1 + a\lambda,\; y_1 + b\lambda,\; z_1 + c\lambda) for some unknown parameter \lambda.
The vector \vec{PM} must be perpendicular to the line's direction \vec{b}. So \vec{PM} \cdot \vec{b} = 0.
Compute \vec{PM} = M - P:
The perpendicularity condition is:
This is a single linear equation in \lambda. Solve it:
Substitute this \lambda back into the parametric equations of the line to get M. Then d = PM.
Reading this formula. The numerator a(\alpha - x_1) + b(\beta - y_1) + c(\gamma - z_1) is the dot product \vec{AP} \cdot \vec{b}. The denominator a^2 + b^2 + c^2 is |\vec{b}|^2. So \lambda = \frac{\vec{AP} \cdot \vec{b}}{|\vec{b}|^2}, which is precisely the scalar projection of \vec{AP} onto \vec{b} divided by |\vec{b}| — the signed length along \vec{b} where the foot lands.
In vector form, the foot of the perpendicular is:
This is the projection of P onto the line — the same projection formula from the dot product article, applied to lines.
Two worked examples
Example 1: Angle between two lines
Find the angle between the lines
Step 1. Read off the direction vectors.
Why: the direction ratios are the denominators in the symmetric form.
Step 2. Compute the dot product.
Why: the dot product is the sum of component-wise products.
Step 3. Compute the magnitudes.
Why: each magnitude is the square root of the sum of squares of the direction ratios.
Step 4. Apply the formula.
Why: the absolute value ensures the angle comes out acute, as required for undirected lines.
Step 5. Interpret the result.
Why: the cosine is small and positive, so the angle is close to 90° but not exactly 90°. The lines are nearly perpendicular.
Result: \theta = \cos^{-1}\!\left(\dfrac{1}{3\sqrt{14}}\right) \approx 84.9°.
The near-right angle confirms the small cosine value: the two lines are almost perpendicular, missing 90° by about 5°.
Example 2: Foot and distance of perpendicular from a point to a line
Find the foot of the perpendicular from the point P = (1, 6, 3) to the line
and hence find the perpendicular distance.
Step 1. Set up the parametric point on the line.
A general point on the line is M = (\lambda,\; 1 + 2\lambda,\; 2 + 3\lambda).
Why: from the symmetric form, x = \lambda, y = 1 + 2\lambda, z = 2 + 3\lambda.
Step 2. Write the vector \vec{PM}.
Why: \vec{PM} = M - P = (\lambda - 1, \; 1 + 2\lambda - 6, \; 2 + 3\lambda - 3).
Step 3. Apply the perpendicularity condition \vec{PM} \cdot \vec{b} = 0.
The direction vector is \vec{b} = 1\hat{i} + 2\hat{j} + 3\hat{k}.
Why: this is a single linear equation in \lambda, guaranteed by the perpendicularity condition being linear.
Step 4. Substitute \lambda = 1 to find the foot M.
Why: plug \lambda = 1 into each parametric equation.
Step 5. Compute the distance PM.
Why: the distance formula in 3D, applied between P(1,6,3) and M(1,3,5).
Result: Foot of perpendicular M = (1, 3, 5), distance = \sqrt{13}.
Verification with the cross-product formula. \vec{AP} = (1-0)\hat{i} + (6-1)\hat{j} + (3-2)\hat{k} = \hat{i} + 5\hat{j} + \hat{k}.
Both methods give \sqrt{13}. The cross-product formula gives the distance directly; the parametric method gives you the foot as a bonus.
Common confusions
A few things students reliably get tripped up by.
-
"The angle between two lines in 3D can be obtuse." No — the angle between two undirected lines is always taken as the acute angle (or exactly 90°). The formula with the absolute value on the dot product enforces this. If a problem asks for the angle between two directed vectors, that is a different question and the answer can be obtuse.
-
"If two lines have the same direction ratios, they are the same line." Not necessarily. They are parallel — same direction — but they might not pass through the same points. Two parallel lines are the same line only if one of them passes through a point that also lies on the other.
-
"The perpendicular from P to a line always meets the line." In 3D, yes — there always exists a unique foot of perpendicular from an external point to a line. (This is different from asking whether two lines meet — two lines in 3D can be skew.) The foot is found by the parametric method above, and it is unique because the equation for \lambda is linear and always has exactly one solution.
-
"I can use the 2D distance formula \frac{|ax_0 + by_0 + c|}{\sqrt{a^2 + b^2}} for a line in 3D." That formula is specific to lines in 2D given by ax + by + c = 0. In 3D, a single linear equation defines a plane, not a line. Use the cross-product formula instead.
-
Forgetting the absolute value in the angle formula. Without it, you might report an obtuse angle as the answer. The absolute value is part of the formula for angles between lines. If you are computing the angle between vectors, you may want the signed version — but for lines, always take |\vec{b}_1 \cdot \vec{b}_2|.
Going deeper
If you came here to learn how to find angles between lines and perpendicular distances, you have the tools — you can stop here. The rest is for readers who want the geometric picture behind the formulas and connections to other parts of 3D geometry.
Why the cross product gives the distance
The cross-product distance formula d = \frac{|\vec{AP} \times \vec{b}|}{|\vec{b}|} has a clean geometric proof that is worth seeing in full.
The magnitude of the cross product |\vec{AP} \times \vec{b}| equals the area of the parallelogram formed by \vec{AP} and \vec{b}. This parallelogram has base |\vec{b}| and height equal to the perpendicular distance from P to the line through A in the direction of \vec{b}. So
and therefore d = \frac{\text{Area}}{|\vec{b}|} = \frac{|\vec{AP} \times \vec{b}|}{|\vec{b}|}.
The same idea — interpreting a cross product magnitude as a parallelogram area and then extracting a height — will reappear when you study the shortest distance between two skew lines.
The projection interpretation
The parametric method reveals something about what "foot of perpendicular" really means. When you compute \lambda = \frac{\vec{AP} \cdot \vec{b}}{|\vec{b}|^2} and then set \vec{m} = \vec{a} + \lambda\vec{b}, you are projecting the point P onto the line. The formula for \lambda is the same projection formula from the dot product article.
This means the foot of the perpendicular is the orthogonal projection of P onto L. The perpendicular distance is the "rejection" — the component of \vec{AP} that is perpendicular to \vec{b}. In fact:
This is Pythagoras's theorem in disguise: the hypotenuse is |\vec{AP}|, the base (projection) is \frac{|\vec{AP} \cdot \vec{b}|}{|\vec{b}|}, and the height (rejection) is d.
Direction cosines version
If the direction of the line is given by direction cosines (l, m, n) instead of direction ratios, the formulas simplify slightly because l^2 + m^2 + n^2 = 1. The angle formula becomes \cos\theta = |l_1 l_2 + m_1 m_2 + n_1 n_2|, and the perpendicular distance formula becomes d = |\vec{AP} \times \hat{b}| — no division needed, because |\hat{b}| = 1.
Connection to planes
The angle between a line and a plane is a closely related problem. If the line has direction \vec{b} and the plane has normal \vec{n}, the angle \phi between the line and the plane satisfies \sin\phi = \frac{|\vec{b} \cdot \vec{n}|}{|\vec{b}||\vec{n}|}. Notice the sine instead of cosine — because the angle between a line and a plane is defined as the complement of the angle between the line and the normal. You will see this in the article on Plane — Distances and Angles.
Where this leads next
You now know how to measure angles and distances involving a single line and a point. The next layer of complexity involves two lines at once — lines that may not meet, may not be parallel, and may twist past each other in three-dimensional space.
- Straight Line in 3D — Advanced — shortest distance between two skew lines, the condition for two lines to intersect, the image of a point in a line, and the distance between parallel lines.
- Plane — Basic Equations — the vector and Cartesian equations of a plane, and how three points determine one.
- Dot Product — a deeper look at the operation that powers angle measurement in any dimension.
- Cross Product — the operation behind the distance formula, with its full geometric interpretation.
- Distance Formulas — a unified view of all the distance formulas in 2D and 3D geometry.