3D Distance Calculator
Find the straight-line distance between any two points in three-dimensional space. Enter the (x, y, z) coordinates of both points and instantly receive the 3D Euclidean distance, midpoint, direction vector, direction cosines, unit vector, and distance from origin — with full step-by-step formula explanations.
📋 Table of Contents
- Interactive 3D Distance Calculator
- What Is 3D Distance? — Three-Dimensional Space Fundamentals
- The 3D Distance Formula — Double Pythagorean Derivation
- The Midpoint Formula in 3D
- Direction Vector, Direction Cosines, and Unit Vectors
- Distance from a Point to the Origin
- Worked Examples — Step-by-Step Solutions
- 2D vs. 3D Distance — Key Differences and Connections
- n-Dimensional Distance — The General Formula
- Real-World Applications of 3D Distance
- Common Mistakes to Avoid
- Quick Reference Table
- Frequently Asked Questions (FAQ)
🧮 3D Distance Calculator
Enter the (x, y, z) coordinates of both points. All six fields are required. The calculator applies the full 3D distance formula and returns a comprehensive geometric analysis of the segment between the two points.
Figure: The 3D distance d (orange line) is the space diagonal of the rectangular box formed by the coordinate differences Δx, Δy, and Δz. The intermediate diagonal d_xy runs across the base of the box.
📘 What Is 3D Distance? — Three-Dimensional Space Fundamentals
In three-dimensional Euclidean space (commonly called 3D space), every point is uniquely identified by three coordinates: an ordered triple (x, y, z). The x-coordinate gives horizontal position, the y-coordinate gives depth (or the second horizontal direction), and the z-coordinate gives vertical height. These three values locate a point precisely in the three mutually perpendicular dimensions that describe the physical world we live in.
The 3D distance between two such points is the length of the straight-line segment connecting them — the shortest possible path through three-dimensional space between the two locations. This distance is also called the Euclidean distance in 3D or the straight-line distance in space, to distinguish it from other distance concepts (path distance, surface distance, network distance) that are longer.
The 3D Cartesian Coordinate System
The Cartesian coordinate system in three dimensions consists of three mutually perpendicular number lines — the x-axis, y-axis, and z-axis — all passing through a common point called the origin (0, 0, 0). This was a natural extension of Descartes' 2D coordinate plane (introduced in 1637) to three dimensions, formalized in the 18th century as analytical geometry matured.
- x-axis: Typically horizontal, pointing right (positive) or left (negative).
- y-axis: Typically horizontal but perpendicular to x, pointing forward/away in a 3D scene, or upward in some conventions.
- z-axis: Typically vertical, pointing up (positive) or down (negative).
- Eight octants: The three axes divide 3D space into eight regions, analogous to the four quadrants of the 2D plane. A point's octant is determined by the signs of its coordinates: (+,+,+) is Octant I, (−,+,+) is Octant II, etc.
Why 3D Distance Matters
Understanding distance in 3D space is essential for every field that deals with physical objects, spatial data, or simulation of the real world. From the GPS in your phone (which computes distances to satellites orbiting in 3D space) to the medical imaging systems that measure distances within your body, to the physics engine of a video game computing whether a bullet reached its target — 3D distance is the fundamental measurement that ties spatial reasoning to quantitative analysis.
📐 The 3D Distance Formula — Double Pythagorean Derivation
The 3D distance formula is the natural extension of the 2D formula. Its derivation is elegant: it applies the Pythagorean theorem not once but twice — first to find the diagonal across the base of a rectangular box, then again to find the full space diagonal that represents the true 3D distance.
Where:
• d = Straight-line distance between the two points (in same units as coordinates)
• (x₁, y₁, z₁) = Coordinates of Point A
• (x₂, y₂, z₂) = Coordinates of Point B
The formula is symmetric: interchanging A and B gives the same distance.
Step-by-Step Derivation (Double Pythagorean Theorem)
- Set up the rectangular box. Place Point A at one corner and Point B at the diagonally opposite corner of a rectangular box (cuboid) aligned with the coordinate axes. The box's edges have lengths |Δx|, |Δy|, and |Δz|.
- Find the base diagonal d_xy. In the base of the box (parallel to the xy-plane), apply the 2D Pythagorean theorem to the horizontal rectangle: \(d_{xy}^2 = \Delta x^2 + \Delta y^2\), so \(d_{xy} = \sqrt{\Delta x^2 + \Delta y^2}\).
- Build the vertical right triangle. The base diagonal d_xy and the vertical edge |Δz| form a right triangle. The hypotenuse of this triangle is the full 3D distance d.
- Apply Pythagorean theorem again. \(d^2 = d_{xy}^2 + \Delta z^2 = \Delta x^2 + \Delta y^2 + \Delta z^2\).
- Take the square root: \(d = \sqrt{\Delta x^2 + \Delta y^2 + \Delta z^2}\) — the 3D distance formula.
The key insight is that d_xy (the 2D distance in the base plane) and Δz are perpendicular — they form a right triangle in a vertical plane. Therefore, the Pythagorean theorem applies a second time, adding (z₂−z₁)² under the same square root.
Delta Notation
In vector notation, the distance d is the magnitude (or norm) of the displacement vector \(\vec{AB} = (\Delta x, \Delta y, \Delta z)\). The notation ‖·‖ denotes the Euclidean norm (length) of a vector.
⊕ The Midpoint Formula in 3D
Just as the 2D midpoint is the average of the two endpoints' coordinates in x and y, the 3D midpoint adds the average z-coordinate. The formula is a straightforward three-coordinate generalization:
The midpoint M lies exactly halfway along the segment AB:
• Distance from A to M = Distance from M to B = d/2
• Each coordinate of M is the arithmetic mean of the corresponding coordinates of A and B
• The midpoint divides the segment into two equal halves in all three dimensions simultaneously
Finding a Missing Endpoint from the Midpoint
If you know the midpoint M(m_x, m_y, m_z) and one endpoint A(x₁, y₁, z₁), you can find the other endpoint B:
This rearrangement of the midpoint formula is used in structural engineering (finding the far end of a beam given its center), in computer graphics (reflection operations), and in mathematical proofs involving segment bisectors.
The Section Formula in 3D (Generalization)
The midpoint is the special case of dividing the segment AB in the ratio 1:1. The section formula divides AB in any ratio m:n:
When m = n = 1, this reduces to the midpoint formula. P divides AB internally in the ratio m:n from point A toward point B. This formula is used in computer graphics for interpolation, in physics for center-of-mass calculations, and in geometry for Apollonius circle constructions.
🧭 Direction Vector, Direction Cosines, and Unit Vectors
The line segment from A to B in 3D has not just a length (distance) but also a direction. Three quantities fully describe this direction: the direction vector, the direction cosines, and the unit vector.
Direction Vector
The direction vector of the segment from A to B is the displacement vector:
The direction vector points from A to B. Its magnitude is the distance d = ‖AB⃗‖. The direction vector from B to A is the negative: (−Δx, −Δy, −Δz).
Direction Cosines
The direction cosines are the cosines of the angles that the segment makes with each of the three coordinate axes. They are denoted cos α (angle with x-axis), cos β (angle with y-axis), and cos γ (angle with z-axis):
Direction cosines are dimensionless and always satisfy the fundamental identity cos²α + cos²β + cos²γ = 1. This identity follows directly from the distance formula: dividing (Δx² + Δy² + Δz²) = d² by d² gives (Δx/d)² + (Δy/d)² + (Δz/d)² = 1.
Unit Vector
The unit vector in the direction from A to B has magnitude exactly 1 and points in the same direction as the segment. It is obtained by dividing the direction vector by the distance:
The unit vector components ARE the direction cosines. This reveals that direction cosines have a double meaning: they are both (1) the cosines of the angles with the coordinate axes and (2) the x, y, z components of the unit vector in the direction of the segment. The magnitude of the unit vector is always exactly 1: ‖û‖ = √(cos²α + cos²β + cos²γ) = √1 = 1.
🎯 Distance from a Point to the Origin in 3D
The distance from any point P(x, y, z) to the origin O(0, 0, 0) is a special case of the 3D distance formula where x₁ = y₁ = z₁ = 0:
This is also called the magnitude, norm, or length of the position vector r = (x, y, z). In physics, this appears as the distance from the origin in spherical coordinates — the radial coordinate ρ (or r). In complex number theory, for a pure imaginary 3D extension, this is the modulus.
Interpretation in Different Contexts
- Physics: The distance from a particle at (x, y, z) to the origin is ρ = √(x² + y² + z²), used in Newton's gravitational law F = GMm/ρ².
- Spherical coordinates: (ρ, θ, φ) — ρ is the radial distance from the origin, the 3D distance to the origin formula.
- Machine learning: The L₂ norm of a feature vector measures how far a data point is from the zero vector — crucial in regularization and normalization.
- Computer graphics: Testing whether a point is inside a sphere of radius R centered at the origin: the point is inside if √(x²+y²+z²) < R.
✏️ Worked Examples — Step-by-Step Solutions
Master the 3D distance formula and its related calculations through these fully solved examples. Each example is worked from first principles.
Example 1 — Basic 3D Distance
Problem: Find the distance between A(1, 2, 3) and B(4, 6, 3).
- Δx = 4−1 = 3, Δy = 6−2 = 4, Δz = 3−3 = 0
- Apply formula: d = √(3² + 4² + 0²) = √(9 + 16 + 0) = √25
- Result: d = 5
- Note: Since Δz = 0, both points lie in the same z-plane — this reduces to a 2D calculation (3-4-5 triangle).
Example 2 — True 3D Distance (All Three Differences)
Problem: Find the distance between A(1, 2, 3) and B(4, 6, 15).
- Δx = 3, Δy = 4, Δz = 15−3 = 12
- Base diagonal: d_xy = √(3² + 4²) = √25 = 5
- Full 3D distance: d = √(d_xy² + Δz²) = √(25 + 144) = √169
- Result: d = 13 (a 5-12-13 Pythagorean triple!)
Example 3 — Distance from Origin
Problem: Find the distance from P(2, 6, 9) to the origin.
- Apply formula: d = √(2² + 6² + 9²)
- Calculate: d = √(4 + 36 + 81) = √121
- Result: d = 11
Example 4 — Full Analysis: Distance, Midpoint, Direction Cosines
Problem: For A(0, 0, 0) and B(1, 2, 2), find the distance, midpoint, and direction cosines.
- Δx=1, Δy=2, Δz=2
- Distance: d = √(1² + 2² + 2²) = √(1+4+4) = √9 = 3
- Midpoint: M = ((0+1)/2, (0+2)/2, (0+2)/2) = (0.5, 1, 1)
- cos α = 1/3, cos β = 2/3, cos γ = 2/3
- Verify: (1/3)² + (2/3)² + (2/3)² = 1/9 + 4/9 + 4/9 = 9/9 = 1 ✅
- Angles: α = arccos(1/3) ≈ 70.53°, β = γ = arccos(2/3) ≈ 48.19°
Example 5 — Negative Coordinates
Problem: Find the distance between A(−3, −4, −5) and B(1, 2, 7).
- Δx = 1−(−3) = 4, Δy = 2−(−4) = 6, Δz = 7−(−5) = 12
- Apply formula: d = √(4² + 6² + 12²) = √(16 + 36 + 144) = √196
- Result: d = 14
🔍 2D vs. 3D Distance — Key Differences and Connections
Understanding how the 2D and 3D distance formulas relate — and differ — builds deep intuition for coordinate geometry and prepares you for higher-dimensional generalizations.
| Feature | 2D Distance | 3D Distance |
|---|---|---|
| Input coordinates | (x₁, y₁) and (x₂, y₂) | (x₁, y₁, z₁) and (x₂, y₂, z₂) |
| Formula | d = √(Δx² + Δy²) | d = √(Δx² + Δy² + Δz²) |
| Midpoint | ((x₁+x₂)/2, (y₁+y₂)/2) | ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2) |
| Pythagorean derivation | 1 application | 2 applications (base diagonal, then vertical) |
| Direction angle | 1 angle θ from +x axis (atan2) | 3 direction angles α, β, γ (one per axis) |
| Direction cosine identity | cos²θ + sin²θ = 1 | cos²α + cos²β + cos²γ = 1 |
| Distance from origin | √(x² + y²) | √(x² + y² + z²) |
| Number of octants/quadrants | 4 quadrants | 8 octants |
| Special case | z₁ = z₂ = 0 in 3D formula | Reduces to 2D when Δz = 0 |
🌐 n-Dimensional Distance — The General Formula
The pattern established by the 2D and 3D distance formulas generalizes perfectly to any number of dimensions. In n-dimensional Euclidean space, every point is represented as an n-tuple (p₁, p₂, ..., pₙ), and the distance between two such points follows the same Pythagorean structure.
Where P = (p₁, p₂, ..., pₙ) and Q = (q₁, q₂, ..., qₙ) are two points in n-dimensional space.
• n = 1: d = |q₁ − p₁| (distance on a number line)
• n = 2: d = √(Δx² + Δy²) — the 2D formula
• n = 3: d = √(Δx² + Δy² + Δz²) — the 3D formula
• n = 4, 5, ...: Abstract higher-dimensional spaces used in mathematics, physics, and data science
Machine Learning — Distance in High-Dimensional Feature Space
Modern machine learning algorithms routinely work in thousands of dimensions. In the MNIST handwritten digit recognition dataset, each 28×28 pixel image is a 784-dimensional vector. The K-Nearest Neighbors (KNN) algorithm classifies a new digit by finding the k training images with the smallest Euclidean distance in this 784-dimensional space. The distance formula, extended to n = 784, is computed millions of times during training and inference.
🌍 Real-World Applications of 3D Distance
The 3D distance formula is one of the most widely applied mathematical tools in science, engineering, and technology. Here are the most important domains where 3D distance calculations are essential.
1. GPS — Trilateration and Satellite Navigation
Your smartphone's GPS determines your location using trilateration — measuring your distance to at least four GPS satellites simultaneously. Each satellite's position is a known 3D point in space (x, y, z in an Earth-centered coordinate system), and the GPS signal travel time gives the 3D distance to each satellite. The intersection of spheres centered at four satellite positions (each sphere radius equals the measured distance) gives your unique 3D location. The 3D distance formula is the mathematical foundation of every GPS calculation.
2. Aerospace Engineering — Orbital Mechanics
The distance between a spacecraft and another body (planet, moon, another spacecraft) in 3D space is fundamental to mission planning, gravity calculations, and docking operations. NASA's Mission Design Centers compute trajectories continuously using the gravitational force equation F = GMm/d², where d is the 3D distance. For the Parker Solar Probe approaching the Sun, or the International Space Station docking operations, 3D distance calculations are safety-critical computations performed thousands of times per second.
3. Medical Imaging — CT, MRI, and 3D Reconstruction
CT and MRI scanners produce 3D volumetric data — effectively a 3D array of voxel (3D pixel) values representing tissue density or signal intensity. Measuring the 3D distance between anatomical landmarks (for surgical planning, tumor monitoring, or prosthetics fitting) requires the full 3D distance formula applied to voxel coordinates. Surgical robots performing minimally invasive procedures use 3D distance calculations to navigate instruments through the patient's body with millimeter precision.
4. Computer Graphics and Game Development
Every modern 3D game, animated film, and virtual reality application relies constantly on 3D distance. Collision detection (has this bullet reached its target?), spatial audio (how far is the explosion?), level-of-detail (should we render this object in high resolution?), physics simulation, and AI navigation systems all use 3D distance calculations every frame. A game running at 60 FPS on a complex scene may perform millions of distance calculations per second.
5. Robotics — Path Planning in 3D Space
Industrial robots welding car frames, surgical robots operating inside the body, and autonomous drones navigating warehouses all operate in 3D space. The A* pathfinding algorithm uses 3D Euclidean distance as a heuristic to find efficient paths from current position to target, while obstacle avoidance algorithms continuously compute distances from the robot's body to surrounding objects. A drone's flight control system updates its distance calculations at hundreds of Hz to maintain stable flight.
6. Structural Engineering — 3D Modeling and Analysis
Building Information Modeling (BIM) and Finite Element Analysis (FEA) software represent structures as millions of nodes in 3D space. Computing inter-node distances is essential for generating the element stiffness matrices that determine how structures deform under load. The 3D distance formula is embedded in every structural analysis computation — from bridges to skyscrapers to airplane fuselages.
7. Particle Physics — Detector Reconstruction
At facilities like CERN, particle detectors record the 3D positions (x, y, z) of thousands of particle interactions per second. Reconstructing particle tracks, identifying decay vertices, and measuring particle momenta all require computing 3D distances between detected hits. The distance formula is one of the most frequently called functions in particle physics reconstruction software.
8. Astronomy — Stellar Distances and Galaxy Mapping
Astronomers map the 3D positions of stars and galaxies using coordinates expressed in parsecs or light-years. The 3D distance formula (combined with parallax measurements, red-shift data, and standard candles like Type Ia supernovae) allows construction of the cosmic distance ladder — the sequence of techniques used to determine distances to increasingly remote objects in the universe.
❌ Common Mistakes to Avoid
Mistake 1: Forgetting the z-Component
Applying the 2D formula d = √(Δx² + Δy²) when the problem requires the 3D formula gives a shorter — and incorrect — answer. If any of the z-coordinates are non-zero and different from each other (Δz ≠ 0), you MUST include the Δz² term. Always check whether your problem is 2D (all points share the same z-value, or z is not given) or true 3D.
Wrong (2D formula): d = √(3² + 4²) = √25 = 5 ✗
Correct (3D formula): d = √(3²+4²+12²) = √(9+16+144) = √169 = 13 ✅
Mistake 2: Sign Errors with Negative Coordinates
Subtracting a negative coordinate: x₂ − x₁ = 3 − (−5) = 3 + 5 = 8, NOT 3 − 5 = −2. This is the same error as in 2D, but with an extra coordinate it creates three separate opportunities for sign mistakes. Always write out all three differences explicitly before squaring.
Mistake 3: Forgetting to Square Each Difference Individually
√(Δx + Δy + Δz) is NOT the distance formula. Each of the three differences must be squared BEFORE summing. The correct formula squares each: √(Δx² + Δy² + Δz²). This is the Pythagorean theorem applied twice — the squaring is fundamental to its derivation.
Mistake 4: Computing Partial Distance from Origin Incorrectly
The distance from point (x, y, z) to the origin is √(x² + y² + z²), using the point's actual coordinate values. A common error is to use Δ values when there are none (the origin is simply (0,0,0), so Δx = x, Δy = y, Δz = z). Also, never forget the z term — even if the point is on the xy-plane (z = 0), confirm z = 0 explicitly before dropping the z term.
Mistake 5: Confusing Direction Cosines with the Actual Angles
Direction cosines are the cosines of the angles, not the angles themselves. To find the angle α, you must take the inverse cosine: α = arccos(Δx/d). Writing "α = Δx/d" confuses the cosine with the angle. A direction cosine can range from −1 to +1; an angle ranges from 0° to 180°.
Mistake 6: Assuming the Midpoint Formula Gives the Closest Point on a Line
The midpoint formula gives the point exactly halfway between A and B along the segment AB — it is not the closest point on the infinite line AB to any external point. Computing the closest point on a line to an external point requires the more complex foot of perpendicular formula (projection formula), which is different from and more complex than the midpoint formula.
📊 Quick Reference Table
| Property | Formula in 3D | Notes |
|---|---|---|
| 3D Distance | d = √(Δx² + Δy² + Δz²) | Primary formula — Pythagorean theorem applied twice |
| Midpoint | M = ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2) | Average of each coordinate pair |
| Direction Vector | v⃗ = (Δx, Δy, Δz) | Points from A to B |
| Distance from origin | |OP| = √(x² + y² + z²) | Magnitude of position vector |
| Direction cosines | cos α = Δx/d, cos β = Δy/d, cos γ = Δz/d | Satisfy cos²α + cos²β + cos²γ = 1 |
| Unit vector | û = (Δx/d, Δy/d, Δz/d) | Components = direction cosines |
| Base diagonal | d_xy = √(Δx² + Δy²) | Intermediate 2D distance in xy-plane |
| Section formula (m:n) | P = ((mx₂+nx₁)/(m+n), (my₂+ny₁)/(m+n), (mz₂+nz₁)/(m+n)) | Internal division; midpoint: m=n=1 |
| Missing endpoint | x₂ = 2m_x − x₁ (similarly y₂, z₂) | Given midpoint M and one endpoint A |
| n-D generalization | d = √(Σᵢ(qᵢ−pᵢ)²) | 2D: n=2; 3D: n=3 |
Notable 3D Pythagorean Triples
| Δx | Δy | Δz | Distance d | How to Verify |
|---|---|---|---|---|
| 1 | 2 | 2 | 3 | √(1+4+4) = √9 = 3 |
| 2 | 3 | 6 | 7 | √(4+9+36) = √49 = 7 |
| 3 | 4 | 12 | 13 | √(9+16+144) = √169 = 13 |
| 2 | 6 | 9 | 11 | √(4+36+81) = √121 = 11 |
| 4 | 6 | 12 | 14 | √(16+36+144) = √196 = 14 |
| 1 | 4 | 8 | 9 | √(1+16+64) = √81 = 9 |
❓ Frequently Asked Questions (FAQ)
HeLovesMath.com — Free Math Calculators, Geometry Tools & Algebra Help
© 2026 HeLovesMath. All calculators are provided free for educational and academic use.
← Back to HeLovesMath Home |
2D Distance Calculator |
Circumference Calculator |
All Calculators


