Skip to content
Omnikalc

Line equation calculator: find the equation of a line through two points

Enter two points to get the slope, the y-intercept, the x-intercept, the angle, the distance between the points and the midpoint of the line segment.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Value out of range

Results

Slope m

2.0000

y-intercept b

-1.0000

x-intercept (0 for a horizontal line)
0.5000
Angle with the x-axis
63.43 °
Distance between the points
8.9443
Midpoint x
4.0000
Midpoint y
7.0000

Two points define exactly one straight line. This line equation calculator takes the coordinates of two points and returns the slope, the y-intercept, the x-intercept, the angle with the x-axis, the distance between the points and the midpoint, so you can write the line as y = mx + b.

How the calculation works

  • Slope m = (y₂ − y₁) ÷ (x₂ − x₁). It is undefined when x₁ = x₂, which is a vertical line.
  • y-intercept b = y₁ − m × x₁, so the equation is y = mx + b.
  • x-intercept = −b ÷ m, the point where the line crosses the x-axis.
  • Distance = √[(x₂ − x₁)² + (y₂ − y₁)²], midpoint = the average of the coordinates and angle = arctangent of the slope.

Example

Find the line through (2, 3) and (6, 11). The slope is (11 − 3) ÷ (6 − 2) = 2. The y-intercept is 3 − 2 × 2 = −1, so the equation is y = 2x − 1. The line crosses the x-axis at 0.5, makes an angle of 63.43° with it, the points are 8.944 apart and the midpoint is (4, 7).

Why it matters

Finding the line through two points is one of the first skills in algebra and comes back in physics, economics, graphics and data analysis. A straight-line model through two measurements gives a quick prediction, a break-even point, a price-demand relation or the slope of a road. The calculator checks homework and saves the steps.

Good to know

Enter the points in the same units on both axes if you want the angle and the distance to make sense, since the angle depends on the scale of the axes. For real data with more than two points, a regression line is better than a line through two of them. The x-intercept is shown as zero for a horizontal line only because it does not exist, so ignore it in that case. Rounding to four decimals can hide an exact fraction, so convert the slope to a fraction by hand when needed.

The triangle calculator solves shapes from sides and angles, the parabola calculator handles curves and the point-line distance calculator measures how far a point is from a line.

Frequently asked questions

How do I find the equation of a line from two points?

Compute the slope m = (y₂ − y₁) ÷ (x₂ − x₁), then the intercept b = y₁ − m × x₁. The line is y = mx + b.

What if the line is vertical?

When x₁ = x₂ the slope is undefined and the equation is x = x₁. The calculator then shows a warning, and the intercept values are not meaningful.

What does the slope tell me?

It is the rise for each unit of run. A positive slope goes up to the right, a negative one goes down and zero is horizontal. Equal slopes mean parallel lines, and slopes whose product is −1 mean perpendicular lines.

How do I write the equation in other forms?

Point-slope form is y − y₁ = m(x − x₁). Standard form is Ax + By = C, where A = −m, B = 1 and C = b, or multiply to clear fractions.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.