Skip to content
Quaestio

Coordinate geometry

Enter two points in the plane and the distance, midpoint and equation of the line are worked out.

Point A
Point B

Distance

7.2111026

Computed with Pythagoras from the differences in x and y.

AB
  • Midpoint(4, 4)
  • GradientChange in y divided by change in x.0.66666667
  • y-intercept1.3333333
  • Equation of the liney = 0.66666667x + 1.3333333
  • Angle to the x-axisPositive anticlockwise, between −90 and 90 degrees.33.690068°
  • Δx · Δy6 · 4

The formulas

  • d = √((x₂ − x₁)² + (y₂ − y₁)²)
  • M = ((x₁ + x₂) / 2, (y₁ + y₂) / 2)
  • m = (y₂ − y₁) / (x₂ − x₁)
  • c = y₁ − m · x₁
  • θ = arctan(m)
Embed

Embed this tool on your site

Copy the code and paste it where the tool should appear, such as a blog post or a school page. It is free, the box has no ads and the tool calculates in the visitor’s browser.

How it works

The distance between two points follows from Pythagoras: the difference in x and the difference in y are the two shorter sides, and the distance is the hypotenuse.

The midpoint is the average of the coordinates, the point halfway along the line between them.

The gradient is the change in y divided by the change in x. A gradient of 2 means the line rises two steps for every step to the right.

The equation of a straight line is written y = mx + c, where m is the gradient and c is where the line crosses the y-axis.

A vertical line has no gradient, because the change in x is zero and division by zero is undefined. Such a line is written as x = a number instead.

The angle is measured against the x-axis and counted positive anticlockwise. A gradient of 1 corresponds to 45 degrees.

Example

The tool starts with A = (1, 2) and B = (7, 6). The differences are Δx = 6 and Δy = 4. The distance is √(6² + 4²) = √52 ≈ 7.2111026 and the midpoint (4, 4).

The gradient is 4 / 6 = 2/3, shown as 0.66666667. The line crosses the y-axis where y = 2 − 2/3 × 1 = 4/3, shown as 1.3333333, and the equation reads y = 0.66666667x + 1.3333333. The angle to the x-axis is arctan(2/3) ≈ 33.690068 degrees.

Rounded numbers in the equation

Every number is shown to at most eight significant figures, so the equation above is a rounding of the exact line y = 2/3 × x + 4/3. If you need exact coefficients, work them out from Δx and Δy, shown in the last row: the gradient is Δy / Δx and the intercept y₁ − Δy / Δx × x₁. Multiplied by 3, the example becomes 3y = 2x + 4.

If you swap the points, Δx and Δy change sign, but everything else stays the same. That includes the angle, which is arctan(m) and lies between −90 and 90 degrees; a vertical line gets 90 degrees.

Edge cases and the diagram

The fields take decimals and negative coordinates, so points in all four quadrants can be used. A comma also works as a decimal point, as in 2,5, except where it separates thousands, as in 1,500, which is fifteen hundred. If the points coincide there is no line, and the tool says so rather than showing a distance of zero. A horizontal line has a gradient of 0 and is written y = 0x + c. A vertical line is written x = a number, and the gradient and intercept are shown as vertical.

The diagram below the answers uses the same scale on both axes, so a line with a gradient of 1 also looks like 45 degrees. The larger of the differences in x and y sets the scale, and the points are centred in the frame. The coordinate axes are drawn where they lie and labelled x and y. An axis that falls outside the frame is not drawn, so with the points in the example, where the origin lies just below and to the left of the frame, neither appears.

Sources

How the tools are checked