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:

L_1: \vec{r} = \vec{a}_1 + \lambda\vec{b}_1, \qquad L_2: \vec{r} = \vec{a}_2 + \mu\vec{b}_2

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 in 3D Two lines L1 and L2 pass through different points in space but their direction vectors are shown meeting at a common point. The acute angle theta between the direction vectors is the angle between the lines. z y x O L₁ L₂ b⃗₁ b⃗₂ θ
Two lines $L_1$ and $L_2$ in space. The angle $\theta$ between the lines is the acute angle between their direction vectors $\vec{b}_1$ and $\vec{b}_2$, shown meeting at a common point for clarity.

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

\cos\theta = \frac{|\vec{b}_1 \cdot \vec{b}_2|}{|\vec{b}_1|\,|\vec{b}_2|} = \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}}

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:

\frac{a_1}{a_2} = \frac{b_1}{b_2} = \frac{c_1}{c_2}

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:

\vec{b}_1 \cdot \vec{b}_2 = 0 \qquad \Longleftrightarrow \qquad a_1 a_2 + b_1 b_2 + c_1 c_2 = 0

No absolute value is needed here — if the dot product is zero, it is zero regardless of sign.

Parallel and perpendicular lines in 3D Two diagrams side by side. On the left, two parallel lines with proportional direction vectors. On the right, two perpendicular lines whose direction vectors have zero dot product. Parallel L₁ L₂ b⃗₁ b⃗₂ b⃗₁ × b⃗₂ = 0⃗ Perpendicular L₁ L₂ b⃗₁ b⃗₂ b⃗₁ · b⃗₂ = 0
Left: parallel lines have proportional direction vectors (cross product is zero). Right: perpendicular lines have direction vectors with zero dot product.

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.

Perpendicular distance from a point to a line A line L runs horizontally. A point P sits above the line. A perpendicular is dropped from P to the line, meeting it at the foot M. The distance PM is labelled d. The vector from a point A on the line to P is shown, along with the direction vector b of the line. L P M (foot) d A AP⃗ b⃗
The perpendicular distance $d$ from point $P$ to line $L$. The point $A$ is a known point on the line, $\vec{b}$ is the direction vector. The foot of the perpendicular is $M$.

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

\text{Area} = |\vec{b}| \cdot d = |\vec{AP} \times \vec{b}|

Solving for d:

\boxed{d = \frac{|\vec{AP} \times \vec{b}|}{|\vec{b}|}}

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:

\vec{PM} = (x_1 + a\lambda - \alpha)\hat{i} + (y_1 + b\lambda - \beta)\hat{j} + (z_1 + c\lambda - \gamma)\hat{k}

The perpendicularity condition is:

a(x_1 + a\lambda - \alpha) + b(y_1 + b\lambda - \beta) + c(z_1 + c\lambda - \gamma) = 0

This is a single linear equation in \lambda. Solve it:

\lambda(a^2 + b^2 + c^2) = a(\alpha - x_1) + b(\beta - y_1) + c(\gamma - z_1)
\lambda = \frac{a(\alpha - x_1) + b(\beta - y_1) + c(\gamma - z_1)}{a^2 + b^2 + c^2}

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:

\vec{m} = \vec{a} + \frac{\vec{AP} \cdot \vec{b}}{|\vec{b}|^2}\;\vec{b}

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

L_1: \frac{x - 1}{2} = \frac{y + 3}{1} = \frac{z}{-2}, \qquad L_2: \frac{x}{3} = \frac{y - 1}{-1} = \frac{z + 2}{2}

Step 1. Read off the direction vectors.

\vec{b}_1 = 2\hat{i} + 1\hat{j} - 2\hat{k}, \qquad \vec{b}_2 = 3\hat{i} - 1\hat{j} + 2\hat{k}

Why: the direction ratios are the denominators in the symmetric form.

Step 2. Compute the dot product.

\vec{b}_1 \cdot \vec{b}_2 = (2)(3) + (1)(-1) + (-2)(2) = 6 - 1 - 4 = 1

Why: the dot product is the sum of component-wise products.

Step 3. Compute the magnitudes.

|\vec{b}_1| = \sqrt{4 + 1 + 4} = 3, \qquad |\vec{b}_2| = \sqrt{9 + 1 + 4} = \sqrt{14}

Why: each magnitude is the square root of the sum of squares of the direction ratios.

Step 4. Apply the formula.

\cos\theta = \frac{|\vec{b}_1 \cdot \vec{b}_2|}{|\vec{b}_1||\vec{b}_2|} = \frac{|1|}{3\sqrt{14}} = \frac{1}{3\sqrt{14}}
\theta = \cos^{-1}\!\left(\frac{1}{3\sqrt{14}}\right)

Why: the absolute value ensures the angle comes out acute, as required for undirected lines.

Step 5. Interpret the result.

\frac{1}{3\sqrt{14}} \approx \frac{1}{11.22} \approx 0.0891
\theta \approx 84.9°

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°.

A 2D projection of the two lines. $L_1$ passes through $(1, -3)$ with direction $(2, 1)$ and $L_2$ passes through $(0, 1)$ with direction $(3, -1)$. The near-right angle between them is visible. (The full 3D picture has a $z$-component that tilts each line out of the screen, but the projected angle is still close to the true value.)

The near-right angle confirms the small cosine value: the two lines are almost perpendicular, missing 90° by about .

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

\frac{x}{1} = \frac{y - 1}{2} = \frac{z - 2}{3}

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}.

\vec{PM} = (\lambda - 1)\hat{i} + (2\lambda - 5)\hat{j} + (3\lambda - 1)\hat{k}

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}.

1(\lambda - 1) + 2(2\lambda - 5) + 3(3\lambda - 1) = 0
\lambda - 1 + 4\lambda - 10 + 9\lambda - 3 = 0
14\lambda - 14 = 0
\lambda = 1

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.

M = (1,\; 1 + 2,\; 2 + 3) = (1, 3, 5)

Why: plug \lambda = 1 into each parametric equation.

Step 5. Compute the distance PM.

PM = \sqrt{(1-1)^2 + (3-6)^2 + (5-3)^2} = \sqrt{0 + 9 + 4} = \sqrt{13}

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}.

Projected view showing the line $L$ (through the origin with direction $(1,2,3)$), the point $P(1,6,3)$, and the foot of perpendicular $M(1,3,5)$. The dashed segment is the perpendicular from $P$ to $L$. Only the $x$-$y$ projection is shown; the full 3D picture has $M$ above $P$ in the $z$-direction.

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}.

\vec{AP} \times \vec{b} = \begin{vmatrix} \hat{i} & \hat{j} & \hat{k} \\ 1 & 5 & 1 \\ 1 & 2 & 3 \end{vmatrix} = (15 - 2)\hat{i} - (3 - 1)\hat{j} + (2 - 5)\hat{k} = 13\hat{i} - 2\hat{j} - 3\hat{k}
|\vec{AP} \times \vec{b}| = \sqrt{169 + 4 + 9} = \sqrt{182}, \qquad |\vec{b}| = \sqrt{14}
d = \frac{\sqrt{182}}{\sqrt{14}} = \sqrt{\frac{182}{14}} = \sqrt{13}

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.

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

\text{Area} = |\vec{b}| \times d

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:

d^2 = |\vec{AP}|^2 - \left(\frac{\vec{AP} \cdot \vec{b}}{|\vec{b}|}\right)^2

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.

Pythagoras decomposition of the distance A right triangle showing the vector AP as the hypotenuse, the projection of AP onto the line as the base, and the perpendicular distance d as the height. The relationship d squared equals AP squared minus projection squared is shown. L A M P |AP⃗| (hypotenuse) projection d
The Pythagorean decomposition. The vector $\vec{AP}$ (hypotenuse) splits into a projection along the line (base) and the perpendicular distance $d$ (height). This gives $d^2 = |\vec{AP}|^2 - (\text{projection})^2$.

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.