Direction in three dimensions
A line in space needs a point and a direction. If a line makes angles α, β and γ with the positive x-, y- and z-axes, its direction cosines are:
l = cos α, m = cos β, n = cos γ
They satisfy l² + m² + n² = 1.
Any three numbers proportional to l, m and n are called direction ratios. If a, b and c are direction ratios, the corresponding direction cosines are:
a/√(a² + b² + c²), b/√(a² + b² + c²), c/√(a² + b² + c²).
For two points A(x₁, y₁, z₁) and B(x₂, y₂, z₂), direction ratios of AB are x₂ − x₁, y₂ − y₁, z₂ − z₁.
Equation of a line
Let a line pass through the point with position vector a and be parallel to a non-zero vector b. Its vector equation is:
r = a + λb, where λ is a real parameter.
As λ changes, the point r moves along the entire line.
If the line passes through (x₁, y₁, z₁) and has direction ratios a, b, c, its Cartesian equation is:
(x − x₁)/a = (y − y₁)/b = (z − z₁)/c.
When one direction ratio is zero, do not divide by it. For example, a line through (1, 2, 3) with direction (2, 0, −1) has y = 2 and (x − 1)/2 = (z − 3)/(−1).
Line through two points
The line through position vectors a and c has direction c − a, so:
r = a + λ(c − a).
Angle between two lines
The angle θ between lines with direction vectors b₁ and b₂ is the acute angle between those vectors:
cos θ = ∣b₁ · b₂∣ / (∣b₁∣ ∣b₂∣).
The absolute value selects the acute angle between the lines.
If b₁ · b₂ = 0, the lines are perpendicular.
If b₁ = k b₂ for some non-zero k, the lines are parallel.
Example. Direction vectors (1, 1, 0) and (1, −1, 0) have dot product 1 − 1 = 0, so the lines are perpendicular.
Intersecting, parallel and skew lines
Two lines in space can be:
intersecting, if they share a point,
parallel, if their direction vectors are proportional and they do not meet,
coincident, if they describe the same line,
skew, if they neither meet nor are parallel.
To test for intersection, equate the coordinate expressions of the two lines and check whether one pair of parameter values satisfies all three coordinates. Satisfying only two coordinates is not enough in three dimensions.
Shortest distance between lines
Parallel lines
For parallel lines r = a₁ + λb and r = a₂ + μb, their shortest distance is:
d = ∣(a₂ − a₁) × b∣ / ∣b∣.
This is the height of the parallelogram formed by the connecting vector and the common direction.
Skew lines
For skew lines r = a₁ + λb₁ and r = a₂ + μb₂:
d = ∣(a₂ − a₁) · (b₁ × b₂)∣ / ∣b₁ × b₂∣.
The cross product is perpendicular to both line directions. Projecting the vector between the lines onto this common perpendicular gives the shortest distance.
If the numerator is zero, the two lines are coplanar. Non-parallel coplanar lines intersect, so their shortest distance is zero.
A reliable workflow
Read a point and direction vector from each line.
First test whether the direction vectors are proportional.
If they are parallel, use the parallel-distance formula.
Otherwise, solve for an intersection or use the scalar triple product.
Keep vectors in a consistent order; the absolute value removes a final sign difference in a distance.
Summary
A point and a direction determine a line in space.
Direction cosines have unit length: l² + m² + n² = 1.
Dot products give angles; proportional direction vectors identify parallel lines.
A scalar triple product gives the shortest distance between skew lines.