Distance from Point to Line in 3D Calculator

Enter the point, a point on the line and the line's direction to get the distance.

How it is calculated

The line is described by a point A = (ax, ay, az) on it and a direction vector D = (dx, dy, dz); the point you test is P = (px, py, pz). All nine numbers are needed, and coordinates share one length unit, so the distance comes out in that same unit (shown as generic units). The tool forms w = P − A, takes the cross product w × D, and returns distance = |w × D| ÷ |D|. It also shows |D| and |w × D| (the parallelogram area, in square units). D cannot be (0, 0, 0): a zero direction defines no line, so no result is shown. Results are given to four decimals.

Worked example

Let P = (3, 1, 4), A = (0, 0, 0) and D = (1, 2, 2). Then w = P − A = (3, 1, 4) and |D| = √(1 + 4 + 4) = 3. The cross product w × D = (1·2 − 4·2, 4·1 − 3·2, 3·2 − 1·1) = (−6, −2, 5), whose length is √(36 + 4 + 25) = √65 = 8.0623. Divide: 8.0623 ÷ 3 = 2.6874 units, which is the shortest distance from the point to the line.

Try this example →

Common mistakes

  • Entering a second point on the line as the direction. D must be the difference between two points on the line (B − A), not B itself.
  • Using a zero direction vector, for example when the two points picked on the line are the same point. No line is defined and nothing is calculated.
  • Expecting the length of D to matter. Scaling D by 2 changes |D| and |w × D| but not the distance, which stays 2.6874 in the example.
  • Treating the line as a segment. The line is infinite, so the distance can be smaller than the distance to the nearest end of a finite segment.
  • Mixing units between coordinates (metres for P, centimetres for A). All nine values must use one unit.

Sources

About this calculator

In three-dimensional space, the shortest distance from a point to a line is found with the vector formula |(P−A)×D| / |D|, where A is any known point on the line, D is its direction vector, and P is the point in question. The cross product (P−A)×D produces a vector whose magnitude equals the area of the parallelogram formed by the two vectors, and dividing by the length of D collapses that area into a perpendicular distance — a compact application of vector algebra that avoids needing to find the closest point explicitly.

This calculation is routine in computer graphics, robotics, and CAD/CAM software, where it's used for collision detection, ray-to-axis distance checks, camera and light positioning, and verifying tool paths against reference lines. Engineers and 3D programmers rely on it whenever a system needs to know how far an object sits from a defined trajectory or edge without computing a full nearest-point projection.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Only the distance comes back, not the spot where the perpendicular lands. If you also need that closest point, take t = (P − A)·D / |D|², and the foot of the perpendicular is A + t·D. A handy self-check is to enter a point you know lies on the line, which should give 0.0000. Would the closest point itself be useful as an extra output?

Popular calculators

All Calculators