CalcWorldHub
Free online calculator · no signup

Distance between two 3D lines calculator

Calculate the shortest distance between two infinite lines in three-dimensional space, including parallel lines.

4,000 tools
Distance between two 3D lines calculator — First line point (x,y,z), First line direction (x,y,z), Second line point (x,y,z) and calculation method
Distance between two 3D lines calculator: inputs and calculation method.

How to use this calculator

Calculate the shortest distance between two infinite lines in three-dimensional space, including parallel lines.

  1. Enter First line point (x,y,z), First line direction (x,y,z), Second line point (x,y,z), Second line direction (x,y,z). Match the units shown beside each field and review the result together with the assumptions below.
  2. Read the worked example below to check the expected input format and result.
  3. Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Original calculation guide

Distance between two 3D lines explained

For nonparallel infinite 3D lines, the shortest separation is the absolute scalar triple product divided by the cross-product magnitude. Parallel lines use perpendicular point-to-line distance; zero direction vectors are invalid.

Shortest infinite-line distance3coordinate units
Shortest infinite-line distance: 3 coordinate units in the worked scenario below.

How the calculation works

For nonparallel lines: distance=|(Q−P)·(u×w)|/|u×w|. For parallel lines use |(Q−P)×u|/|u|.

Inputs and units

First line point (x,y,z)
Any point on the first infinite line.
First line direction (x,y,z)
A nonzero direction vector.
Second line point (x,y,z)
Any point on the second line.
Second line direction (x,y,z)
A nonzero second direction.

Limits of this model

Lines have infinite extent. It does not compute segment-to-segment distance or the nearest endpoint pair.

Point-to-plane distance uses one point and one plane. This page compares two line geometries that may be skew.

Check a numerical scenario

First line point (x,y,z) = 0,0,0; First line direction (x,y,z) = 1,0,0; Second line point (x,y,z) = 0,0,3; Second line direction (x,y,z) = 0,1,0.

  • Shortest infinite-line distance: 3 coordinate units
  • Direction relationship: nonparallel

The sample lines lie along the x and y axes at z=0 and z=3. They are nonparallel and skew, so their shortest separation is 3 coordinate units.

Frequently asked questions

Can nonparallel 3D lines fail to intersect?

Yes. They can be skew and remain separated.

Does scaling a direction change the answer?

No, provided its direction remains the same.

Is zero distance proof of a unique intersection?

Parallel coincident lines also have zero distance.

How do I use the Distance between two 3D lines calculator?

Enter First line point (x,y,z), First line direction (x,y,z), Second line point (x,y,z), Second line direction (x,y,z). Match the units shown beside each field and review the result together with the assumptions below.

What is a worked example of Distance between two 3D lines?

First line point (x,y,z) = 0,0,0; First line direction (x,y,z) = 1,0,0; Second line point (x,y,z) = 0,0,3; Second line direction (x,y,z) = 0,1,0. Shortest infinite-line distance: 3 coordinate units Direction relationship: nonparallel The sample lines lie along the x and y axes at z=0 and z=3. They are nonparallel and skew, so their shortest separation is 3 coordinate units.