Home ↓
CalculatorsVerified

Math & Geometry

Equation of a Line Calculator (Through Two Points)

Two points determine exactly one straight line, and finding its equation is one of the first skills in coordinate geometry. The slope, usually written m, measures how steep the line is: the change in y divided by the change in x between the two points, often described as rise over run. A positive slope rises from left to right, a negative slope falls, a zero slope is horizontal and an undefined slope, which happens when both points have the same x value, is vertical. Once the slope is known, the y-intercept b, where the line crosses the y-axis, follows from substituting either point into y equals m x plus b, the slope-intercept form. The same line can be written in standard form, A x plus B y equals C, which also works for vertical lines. Several other useful quantities come from the same two points: the distance between them, from the Pythagorean theorem; the midpoint, the average of the coordinates; the x-intercept, where the line crosses the x-axis; the slope of any line perpendicular to it, the negative reciprocal; and the angle of inclination, the angle the line makes with the positive x-axis. These ideas are used in algebra and geometry classes, but also in data analysis, computer graphics, surveying and engineering whenever a straight-line relationship is needed. This calculator takes the coordinates of two points and returns all of these values, handling horizontal and vertical lines correctly.

How to use this calculator

  1. Enter the x and y coordinates of the first point.
  2. Enter the coordinates of the second point.
  3. Read the equation in slope-intercept form.
  4. Check the standard form, intercepts and slope.
  5. Use the distance, midpoint and perpendicular slope as needed.

Other forms of a line

Point-slope form, y − y₁ = m(x − x₁), is often the quickest way to write the line from one point and a slope. Expanding it gives the slope-intercept form.

Two lines are parallel if their slopes are equal and perpendicular if their slopes multiply to −1. A vertical and a horizontal line are always perpendicular.

Lines in data and science

When data points fall roughly on a line, linear regression finds the best-fitting slope and intercept for all the points, not just two. The slope then measures how much one variable changes per unit of the other.

Linear interpolation uses the line through two known points to estimate values in between, a technique used with tables, sensors and engineering charts.

Formula & method

Slope m = (y₂ − y₁) ÷ (x₂ − x₁)y-intercept b = y₁ − m x₁, so y = m x + bDistance = √((x₂ − x₁)² + (y₂ − y₁)²); midpoint = ((x₁ + x₂)/2, (y₁ + y₂)/2)Perpendicular slope = −1 ÷ m; angle of inclination = arctan m

m = (y₂ − y₁)/(x₂ − x₁), b = y₁ − m x₁, distance = √(Δx² + Δy²), midpoint = ((x₁ + x₂)/2, (y₁ + y₂)/2) and perpendicular slope = −1/m.

Worked example

The line through (1, 3) and (3, 7)

  1. m = (7 − 3) ÷ (3 − 1) = 2
  2. b = 3 − 2 × 1 = 1, so y = 2x + 1
  3. Distance = √(2² + 4²) ≈ 4.4721; midpoint (2, 5)

Answer: The line rises 2 units for every unit to the right and crosses the y-axis at 1.

Frequently asked questions

What if both points have the same x value?

The line is vertical, with an undefined slope. Its equation is x = constant, and the calculator reports it that way.

What if both points have the same y value?

The line is horizontal, with a slope of zero. Its equation is y = constant and it has no x-intercept unless it is the x-axis.

What is the angle of inclination?

It is the angle between the line and the positive x-axis, equal to the arctangent of the slope. A slope of 1 gives 45°.

Is the standard form simplified?

It is written with A positive using the differences between the points. You can divide all three numbers by a common factor to simplify it.

How is the distance calculated?

It uses the Pythagorean theorem: the square root of the horizontal difference squared plus the vertical difference squared.

Can I use decimals and negative numbers?

Yes. Any real coordinates work, and the results are rounded to four decimal places.