🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Shortest Distance Between Lines

CBSE Class 12 Maths3D GeometryđŸŸĸ Free Lesson

Which formula applies: skew, parallel or intersecting

Before any arithmetic, the configuration has to be identified, because two of the three cases use different formulas and the third returns zero. The cross product of the two direction vectors separates them cleanly:

ConfigurationTestShortest distance
Skew and scalar triple product formula
Parallel, distinct while is not along that directioncross product with one direction
Intersecting but
The same line and along that direction

The first row of the table hides a trap. When the directions are parallel the cross product in the denominator is the zero vector, so the skew formula becomes a division by zero, or worse, a numerically plausible answer near zero that reads as "the lines intersect". Switching to the parallel formula is a decision that must be made before substituting, not after a strange result appears.

Where the formula comes from

The common perpendicular is perpendicular to both direction vectors, so its direction must be parallel to . Call the resulting unit vector . Now take any point on the first line and any point on the second, and form the vector from to . The separation between the two lines, measured along the common perpendicular, is simply the component of in the direction of , which is the projection . Substituting gives the standard formula at once.

The numerator is a scalar triple product, and the geometric meaning of that triple product is the signed volume of the parallelepiped spanned by , and . Dividing a volume by the base area leaves a height, and that height is precisely the gap between the two lines. The absolute value discards the sign, because a distance is never negative and the two lines have no preferred order.

For Parallel Lines

Example: Shortest Distance Between Skew Lines

Find the shortest distance between:

The non-zero value is doing double duty: it proves the lines are skew as well as supplying the numerator. Rationallyising the denominator is a presentational step that examiners expect, and and are the same number written in the two conventional ways.

Example: Shortest Distance Between Parallel Lines

Find the shortest distance between:

When the shortest distance drops to zero

A zero in the numerator is not a failure of the method, it is a statement about the geometry. If the directions are independent, so the two lines determine a plane together with the segment joining them; if in addition , the separation vector lies in that same plane and the lines cross. Take through the origin with direction and through with direction . Their cross product is , which is not zero, and the separation vector has zero dot product with it, so the distance is . Substituting the parameter values confirms the picture: reaches at and reaches at , so that point belongs to both lines.

Equation of Shortest Distance Line

Writing that line down needs one point from each side, and the two points are found by insisting that the segment joining them be perpendicular to both directions. With on and on , the vector must satisfy two dot-product equations, which is a linear system in the two parameters and rather than a new formula to memorise.

Example: Find Points of Shortest Distance

For the skew lines in the first example, find the points where the shortest distance is achieved.

Computing shortest distances in Python

The first block reproduces both worked answers and, more usefully, refuses to run the skew formula when the directions are parallel instead of returning a meaningless number.

python
import numpy as np

def shortest_skew(a1, b1, a2, b2):
    a1 = np.asarray(a1, float); a2 = np.asarray(a2, float)
    w = a2 - a1
    n = np.cross(b1, b2)
    if np.allclose(n, 0):
        raise ValueError("directions are parallel: use the cross-product formula")
    return abs(float(np.dot(w, n))) / np.linalg.norm(n)

def shortest_parallel(a1, a2, b):
    w = np.asarray(a2, float) - np.asarray(a1, float)
    return float(np.linalg.norm(np.cross(w, b)) / np.linalg.norm(b))

print(round(shortest_skew([1,2,3], [2,-1,1], [4,5,6], [1,2,-1]), 4))   # 3.5497
print(round(shortest_parallel([1,-1,0], [2,-2,1], [2,3,1]), 4))        # 1.7321
print(round(shortest_skew([0,0,0], [1,1,1], [1,0,0], [0,1,1]), 4))     # 0.0

Three numbers come out, and each one tells a different story: a genuine skew separation of , the parallel gap of , and the intersecting pair returning exactly zero. Any implementation that skips the guard in the first function would divide by a zero-length cross product and produce nan or inf, which is the computational version of using the wrong formula.

Recovering the common perpendicular numerically

The two feet are obtained by solving the pair of perpendicularity conditions derived above. The system is linear in and , so a two-by-two solve is enough, and the returned points give an independent check on the distance.

python
import numpy as np

def common_perpendicular(a1, b1, a2, b2):
    a1 = np.asarray(a1, float); a2 = np.asarray(a2, float)
    b1 = np.asarray(b1, float); b2 = np.asarray(b2, float)
    w = a2 - a1
    A = np.array([[np.dot(b1, b1), -np.dot(b1, b2)],
                  [np.dot(b1, b2), -np.dot(b2, b2)]])
    rhs = np.array([np.dot(b1, w), np.dot(b2, w)])
    lam, mu = np.linalg.solve(A, rhs)
    return lam, mu, a1 + lam * b1, a2 + mu * b2

lam, mu, p, q = common_perpendicular([1,2,3], [2,-1,1], [4,5,6], [1,2,-1])
print("lambda, mu      :", round(lam, 6), round(mu, 6))       # 1.2 -1.2
print("P               :", np.round(p, 4))                    # [3.4 0.8 4.2]
print("Q               :", np.round(q, 4))                    # [2.8 2.6 7.2]
print("|PQ|            :", round(float(np.linalg.norm(q - p)), 4))   # 3.5497
print("PQ perp to b1   :", np.isclose(np.dot(q - p, [2,-1,1]), 0))   # True
print("PQ perp to b2   :", np.isclose(np.dot(q - p, [1,2,-1]), 0))   # True

The parameters and match the hand solution exactly, the points match and , and the measured length agrees with . Both orthogonality flags coming back True confirm that the joining segment really is perpendicular to both directions, which is the property the whole construction was built on.

Common Mistakes

Applying the scalar triple product formula when the two direction vectors are parallel

Fix: Check the cross product first; if it vanishes, switch to the cross-product-with-one-direction formula for parallel lines.

Forgetting the absolute value and reporting a negative shortest distance

Fix: Wrap the scalar triple product in an absolute value, because the sign only records the orientation of the two lines.

Treating a zero distance as an error and rewriting the answer

Fix: Report the zero and state the configuration: with non-parallel directions the lines intersect, and the meeting point can be recovered from the two parameters.

Mixing the points of one line into the separation vector of the other

Fix: Build the separation vector as a2 minus a1 using one point from each line, then keep it separate from the direction vectors throughout.

Key Takeaways

  • The shortest distance is the projection of any separation vector onto the unit common perpendicular, which is why the numerator is a scalar triple product and the denominator is the length of the cross product of the directions.
  • Parallel lines need their own formula because the cross product of the directions, and with it the denominator of the skew formula, vanishes.
  • A vanishing scalar triple product with non-parallel directions means the lines are coplanar and therefore intersect, so the shortest distance is zero.
  • The feet of the common perpendicular come from two linear equations in the parameters, and their separation vector is always a multiple of the cross product of the two directions.
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-16

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert CBSE Class 12 Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement