{
  "id": "distance-formula",
  "version": "3cad7127c9c0",
  "status": "published",
  "name": "Distance Formula Calculator",
  "question": "How do I use the distance formula?",
  "summary": "Finds the distance between two points in 2D or 3D with the distance formula, as an exact square root and a decimal, with each step of the working.",
  "category": "math",
  "subcategory": "geometry",
  "url": "https://www.acalculator.org/math/distance-formula-calculator",
  "markdown": "https://www.acalculator.org/math/distance-formula-calculator.md",
  "kind": "function",
  "method": "d = √((x₂ − x₁)² + (y₂ − y₁)²), with + (z₂ − z₁)² inside the root for points in 3D.",
  "assumptions": [
    "Coordinates are read exactly as typed (0.1 is 1/10), so d² is exact; the decimal distance is its square root rounded for display.",
    "The distance is in the same unit as the coordinates.",
    "The drawing shows the x and y coordinates only, also for points in 3D."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "dim": {
        "title": "Points in",
        "description": "Points on a plane (x, y) or in space (x, y, z).",
        "type": "string",
        "enum": [
          "2d",
          "3d"
        ]
      },
      "x1": {
        "title": "x₁",
        "description": "The x coordinate of the first point.",
        "type": "number"
      },
      "y1": {
        "title": "y₁",
        "description": "The y coordinate of the first point.",
        "type": "number"
      },
      "z1": {
        "title": "z₁",
        "description": "The z coordinate of the first point (3D only).",
        "type": "number"
      },
      "x2": {
        "title": "x₂",
        "description": "The x coordinate of the second point.",
        "type": "number"
      },
      "y2": {
        "title": "y₂",
        "description": "The y coordinate of the second point.",
        "type": "number"
      },
      "z2": {
        "title": "z₂",
        "description": "The z coordinate of the second point (3D only).",
        "type": "number"
      }
    }
  },
  "outputs": {
    "distance": {
      "label": "Distance d",
      "description": "The straight-line distance between the two points.",
      "format": "number"
    },
    "exact": {
      "label": "Exact distance",
      "description": "The distance as a simplified square root, such as 3√5 or √2/2.",
      "format": "text"
    },
    "squared": {
      "label": "Distance squared d²",
      "description": "The sum of the squared differences.",
      "format": "number"
    },
    "dx": {
      "label": "Δx = x₂ − x₁",
      "description": "The change in x from the first point to the second.",
      "format": "number"
    },
    "dy": {
      "label": "Δy = y₂ − y₁",
      "description": "The change in y from the first point to the second.",
      "format": "number"
    },
    "dz": {
      "label": "Δz = z₂ − z₁",
      "description": "The change in z (3D only).",
      "format": "number"
    },
    "steps": {
      "label": "Working",
      "description": "The distance formula with the numbers put in, step by step.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "dim": "2d",
      "x1": 1,
      "y1": 2,
      "z1": 3,
      "x2": 4,
      "y2": 6,
      "z2": 15
    },
    "outputs": {
      "distance": 5,
      "exact": "5",
      "squared": 25,
      "dx": 3,
      "dy": 4,
      "steps": "d = √((4 − 1)² + (6 − 2)²); d = √(3² + 4²) = √(9 + 16) = √25; d = 5"
    },
    "text": "The distance between the two points is 5."
  },
  "examples": [
    {
      "given": {
        "dim": "2d",
        "x1": 1,
        "y1": 2,
        "x2": 4,
        "y2": 6
      },
      "expect": {
        "distance": 5,
        "exact": "5",
        "squared": 25,
        "dx": 3,
        "dy": 4,
        "steps": "d = √((4 − 1)² + (6 − 2)²); d = √(3² + 4²) = √(9 + 16) = √25; d = 5"
      },
      "source": "OpenStax, College Algebra 2e, §2.1, the distance formula (https://openstax.org/books/college-algebra-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs); hand calculation in content.mdx: √(3² + 4²) = √25 = 5 (OpenStax College Algebra 2e §2.1)"
    },
    {
      "given": {
        "dim": "2d",
        "x1": -3,
        "y1": 5,
        "x2": 3,
        "y2": 2
      },
      "expect": {
        "distance": 6.708203932499369,
        "exact": "3√5",
        "squared": 45,
        "dx": 6,
        "dy": -3
      },
      "source": "hand calculation in content.mdx: √(6² + (−3)²) = √45 = 3√5; Python 3: math.sqrt(45)"
    },
    {
      "given": {
        "dim": "3d",
        "x1": 1,
        "y1": 2,
        "z1": 3,
        "x2": 4,
        "y2": 6,
        "z2": 15
      },
      "expect": {
        "distance": 13,
        "exact": "13",
        "squared": 169,
        "dz": 12
      },
      "source": "hand calculation in content.mdx: √(3² + 4² + 12²) = √169 = 13"
    },
    {
      "given": {
        "dim": "2d",
        "x1": 0,
        "y1": 0,
        "x2": 0.5,
        "y2": 0.5
      },
      "expect": {
        "distance": 0.7071067811865476,
        "exact": "√2/2",
        "squared": 0.5
      },
      "source": "hand calculation in content.mdx: √(0.25 + 0.25) = √(1/2) = √2/2; Python 3: math.sqrt(0.5)"
    },
    {
      "given": {
        "dim": "2d",
        "x1": 0.1,
        "y1": 0,
        "x2": 0.4,
        "y2": 0.4
      },
      "expect": {
        "distance": 0.5,
        "exact": "1/2",
        "squared": 0.25
      },
      "source": "hand calculation in content.mdx: decimals read exactly, Δx = 0.3, Δy = 0.4, √(0.09 + 0.16) = √0.25 = 0.5"
    }
  ],
  "sources": [
    "OpenStax, College Algebra 2e, §2.1 The Rectangular Coordinate Systems and Graphs (the distance formula). https://openstax.org/books/college-algebra-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs",
    "OpenStax, Calculus Volume 3, §2.2 Vectors in Three Dimensions (the distance between two points in space). https://openstax.org/books/calculus-volume-3/pages/2-2-vectors-in-three-dimensions"
  ],
  "related": [
    "midpoint",
    "slope",
    "pythagorean-theorem",
    "triangle"
  ],
  "changelog": []
}
