Slope, Distance and Midpoint Calculator

Slope, line equation, distance and midpoint from two points, as exact fractions and square roots, with the steps and a graph.

Inputs

These are example values. Change any of them to calculate your own.

Try:
What you know

Type whole numbers, decimals, fractions (3/4) or mixed numbers (2 1/2). An x box also takes a whole point, like (3, 4).

Point 1
Point 2

For the decimal forms.

Results

Slope

−2/3

≈ −0.6667. Going right, the line falls 2 units for every 3 units across.

Distance
3√13≈ 10.8167
Midpoint
(1/2, 2)= (0.5, 2)
Rise over run
−6 over 9Δy over Δx, from point 1 to point 2
Angle of inclination
146.3099°Falls at 33.6901° below the horizontal
Percent grade
−66.67%Rise : run = 2 : 3 (1 in 1.5)
Perpendicular bisector
6x − 4y = −5y = (3/2)x + 5/4, slope 3/2

Equation of the line

  • Slope-intercept form: y = −(2/3)x + 7/3; with decimals, y = −0.6667x + 2.3333
  • Point-slope form through point 1: y − 5 = −(2/3)(x + 4)
  • Standard form: 2x + 3y = 7; general form 2x + 3y − 7 = 0
  • x-intercept: (7/2, 0) = (3.5, 0)
  • y-intercept: (0, 7/3) ≈ (0, 2.3333)
  • Perpendicular slope: 3/2, the negative reciprocal of −2/3
Graph of the two points
Graph of the two pointsThe line through A (−4, 5) and B (5, −1), with slope −2/3. From A, the run is 9 and the rise is −6. The midpoint M is (1/2, 2). The line crosses the y-axis at (0, 7/3) and the x-axis at (7/2, 0).−6−5−4−3−2−101234567−2−10123456A (−4, 5)B (5, −1)M (1/2, 2)run 9rise −6

Solid: the segment and the line through it. Dashed: run and rise. Hollow dot: the midpoint. Both axes use the same scale.

Key points
Pointxy
A (point 1)−45
B (point 2)5−1
M (midpoint)1/2 (0.5)2
x-intercept7/2 (3.5)0
y-intercept07/3 (≈ 2.3333)
Slope, step by step
  1. Rise: Δy = y₂ − y₁ = −1 − 5 = −6
  2. Run: Δx = x₂ − x₁ = 5 − (−4) = 9
  3. Slope: m = Δy ÷ Δx = −6 ÷ 9 = −2/3 ≈ −0.6667
  4. Angle of inclination: tan⁻¹(−2/3) = −33.6901°. The angle is measured counterclockwise from the positive x-axis, so θ = 180° − 33.6901° = 146.3099°
  5. Percent grade: m × 100% = −66.67%
  6. In a spreadsheet: =SLOPE({5,-1},{-4,5})
Distance, step by step
  1. d = √(Δx² + Δy²) = √(9² + (−6)²)
  2. d = √(81 + 36) = √117
  3. 117 = 3² × 13, so d = 3√13
  4. d ≈ 10.8167
  5. In a spreadsheet: =SQRT((5-(-4))^2+(-1-5)^2)
Midpoint, step by step
  1. Midpoint x = (x₁ + x₂) ÷ 2 = (−4 + 5) ÷ 2 = 1/2
  2. Midpoint y = (y₁ + y₂) ÷ 2 = (5 + (−1)) ÷ 2 = 2
  3. Midpoint M = (1/2, 2) = (0.5, 2)
Equation, step by step
  1. Point-slope form through point 1 (−4, 5): y − 5 = −(2/3)(x + 4)
  2. y-intercept: b = y₁ − m × x₁ = 5 − (−2/3) × (−4) = 5 − (8/3) = 7/3
  3. Slope-intercept form: y = −(2/3)x + 7/3
  4. Standard form: move the x-term to the left, (2/3)x + y = 7/3, then multiply both sides by 3 to clear the fractions: 2x + 3y = 7
  5. General form: 2x + 3y − 7 = 0
  6. x-intercept: set y = 0 in 2x + 3y = 7, so x = 7 ÷ 2 = 7/2
  7. Perpendicular bisector: slope 3/2 (the negative reciprocal of −2/3) through M (1/2, 2): y − 2 = (3/2)(x − 1/2), which is 6x − 4y = −5

Assumptions

  • Both axes use the same unit, as on graph paper. The angle and percent grade depend on that: with x in feet and y in inches, rise ÷ run is still correct in those units, but the angle is not.
  • Coordinates are read exactly as typed: 0.1 is 1/10 and 0.(3) is 1/3. Decimals are rounded to 4 places for display only.
  • The angle of inclination is measured counterclockwise from the positive x-axis, from 0° up to but not including 180°. A negative percent grade means the line falls from left to right.
  • Standard form uses whole numbers with no common factor and a positive x-coefficient (a positive y-coefficient for a horizontal line). Some textbooks allow other signs or fractions.
  • Distance is the straight-line distance on a flat plane. Latitude and longitude are angles on a sphere, so this formula does not give map distances from them.

Calculated in your browser. This site doesn't send the numbers you enter anywhere. “Continue in” links pass them to the next calculator within this browser tab only.

Continue in the Triangle Calculator (rise and run as legs)

Updated Report a problem with this calculator

One pair of points, four answers

Give it two points on a coordinate plane, (x₁, y₁) and (x₂, y₂), and it returns everything about the segment between them in one pass: the slope, the equation of the line through them, the distance between them and the midpoint of the segment. Results are exact where the math allows, so a slope shows as 5/3 rather than 1.6666666667 and a distance as 3√13 before its decimal. It also works backward: from one endpoint and the midpoint, it finds the other endpoint.

How to use it

  1. Choose Two points, or Endpoint and midpoint if you know the middle of the segment and one end.
  2. Type each coordinate. Whole numbers, decimals, fractions such as 3/4, mixed numbers such as 2 1/2 and negatives all work, and they are read exactly: 0.1 is 1/10. A point copied as (3, 4) can go straight into an x box; the matching y box then disappears, and the line under the box says how the entry was read.
  3. Decimal places sets the rounding of the decimal forms only. Exact fractions and square roots are never rounded.

The Try chips load a vertical line, a horizontal line, fraction coordinates, a 1 in 12 ramp and an endpoint-from-midpoint problem. Save for comparison keeps up to three results side by side, and for a sloped line the Triangle Calculator link carries the rise and run over as the legs of a right triangle.

How to find the slope from two points

Subtract the y-coordinates, subtract the x-coordinates in the same order, and divide:

m=y2−y1x2−x1=riserunm = \frac{y_2 - y_1}{x_2 - x_1} = \frac{\text{rise}}{\text{run}}

  • Δy=y2−y1\Delta y = y_2 - y_1 is the rise, the vertical change from point 1 to point 2.
  • Δx=x2−x1\Delta x = x_2 - x_1 is the run, the horizontal change.
  • A positive slope rises from left to right, a negative one falls, and a bigger size means steeper.

Which point you call point 1 doesn’t matter, as long as both subtractions start from the same point: swapping the points flips the sign of the rise and the run together, and the quotient stays the same.

Worked example: (−4, 5) and (5, −1)

  1. Rise: Δy = −1 − 5 = −6. Run: Δx = 5 − (−4) = 9.
  2. Slope: m = −6 ÷ 9 = −2/3 ≈ −0.6667. Going right, the line falls 2 units for every 3 units across.
  3. Angle of inclination: tan⁻¹(−2/3) = −33.6901°. Angles are measured counterclockwise from the positive x-axis, so θ = 180° − 33.6901° = 146.3099°. The percent grade is −2/3 × 100% = −66.67%.
  4. Distance: d = √(9² + (−6)²) = √(81 + 36) = √117. Since 117 = 3² × 13, d = 3√13 ≈ 10.8167.
  5. Midpoint: ((−4 + 5) ÷ 2, (5 + (−1)) ÷ 2) = (1/2, 2).
  6. Line: the y-intercept is b = 5 − (−2/3)(−4) = 5 − 8/3 = 7/3, so y = −(2/3)x + 7/3. Moving the x-term gives (2/3)x + y = 7/3, and multiplying by 3 gives the standard form 2x + 3y = 7, which crosses the x-axis at x = 7/2.
  7. Perpendicular bisector: slope 3/2, the negative reciprocal of −2/3, through (1/2, 2). In standard form that is 6x − 4y = −5.

Undefined vs zero slope: vertical and horizontal lines

A horizontal line has slope 0: the rise is 0, and 0 divided by any run is 0. Through (−5, 4) and (7, 4) the line is y = 4, with an angle of 0° and a grade of 0%.

A vertical line’s slope is not infinite; it doesn’t exist. Undefined is the word textbooks use: the run is 0, and division by 0 has no answer. Through (3, −2) and (3, 6) the line is x = 3. It has no slope-intercept or point-slope form, it never meets the y-axis, and its perpendicular bisector is the horizontal line y = 2 through the midpoint (3, 2). The distance is simply the difference in y, 8.

Horizontal and vertical lines are perpendicular even though the “product of slopes is −1” rule can’t be applied to them, because one of the slopes doesn’t exist.

The same point typed twice is a third special case. Every line through that point passes through “both” points, so there is no single slope or equation; the distance is 0 and the midpoint is the point itself.

Equation of a line: slope-intercept, point-slope and standard form

The same line can be written three common ways. For the worked example:

FormPatternExample
Slope-intercepty = mx + by = −(2/3)x + 7/3
Point-slopey − y₁ = m(x − x₁)y − 5 = −(2/3)(x + 4)
StandardAx + By = C2x + 3y = 7

To turn slope-intercept form into standard form, move the x-term to the left, multiply both sides by the common denominator to clear the fractions, and multiply by −1 if the x-coefficient is negative. This page writes standard form with whole numbers that share no common factor and a positive A (a positive B for a horizontal line), the usual preference for standard form. With the Fractions chip, (1/2, 3/4) and (2 1/2, −1/4), the steps give y = −(1/2)x + 1 and then x + 2y = 2.

Distance formula between two points

The distance is the length of the hypotenuse of the right triangle whose legs are the run and the rise:

d=(x2−x1)2+(y2−y1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

To simplify the root, pull out the largest perfect-square factor: √117 = √(9 × 13) = 3√13. A number with no square factor stays as it is, so the distance from (0, 0) to (2, 5) is √29 ≈ 5.3852. Squaring removes the signs, so it doesn’t matter which point comes first.

Midpoint formula (and finding a missing endpoint)

The midpoint of a segment averages the coordinates of its endpoints:

M=(x1+x22, y1+y22)M = \left(\frac{x_1 + x_2}{2},\ \frac{y_1 + y_2}{2}\right)

Solving that for point 2 finds a missing endpoint: x2=2xM−x1x_2 = 2x_M - x_1 and y2=2yM−y1y_2 = 2y_M - y_1. If one endpoint is (2, −3) and the midpoint is (5, 1), the other endpoint is (2 × 5 − 2, 2 × 1 − (−3)) = (8, 5). Check it by averaging: ((2 + 8) ÷ 2, (−3 + 5) ÷ 2) = (5, 1). That segment has slope 4/3 and length 10.

Slope as an angle, percent grade or ratio

Outside a math class, the same steepness is often given in one of three other ways:

  • Angle of inclination: θ = tan⁻¹(m), measured counterclockwise from the positive x-axis, from 0° up to 180°. A falling line gets an angle over 90°.
  • Percent grade: 100 × m. A rise of 1 over a run of 12 is 8.33%.
  • Ratio: rise : run, often written “1 in N” with N = run ÷ rise. The U.S. Access Board’s guide to the ADA Standards writes ramp slopes this way, as 1:12, and gives the same slope as 8.33%.
RatioPercent gradeAngle
1 in 205%2.8624°
1 in 128.33%4.7636°
1 in 1010%5.7106°
1 in 520%11.3099°
1 in 425%14.0362°
1 in 250%26.5651°
1 in 1100%45°

So a 10% slope is about 5.71°, and a 1 to 5 slope is about 11.31°. A 100% grade is 45°, not a vertical wall: a vertical line has no percent grade at all.

Reading the result

  • Headline: the slope as an exact fraction with its decimal, or the other endpoint when you started from a midpoint.
  • Tiles: distance, midpoint, rise over run, angle of inclination, percent grade with the rise : run ratio, and the perpendicular bisector of the segment.
  • Equation of the line: slope-intercept, point-slope, standard and general forms, both intercepts and the slope of perpendicular lines.
  • Graph: both points, the segment and the line, the run and rise as dashed legs and the midpoint as a hollow dot, drawn with the same scale on both axes so the angle looks right. The key-points table under it lists the same points and downloads as CSV.
  • Steps: one list per result with your numbers substituted, plus the spreadsheet formulas =SLOPE() and =SQRT() that give the same decimals.

Assumptions and limitations

  • Both axes are in the same unit. The slope is correct in any units, but the angle and percent grade only mean something physical when x and y are measured the same way.
  • Distance is on a flat plane. Latitude and longitude are angles on a sphere, so the distance formula doesn’t turn them into miles or kilometers.
  • Coordinates can be between −1,000,000,000,000 and 1,000,000,000,000, and non-zero ones at least 0.000000000001 in size. All arithmetic is exact; a square root is shown in simplified form when its numbers are small enough to factor quickly, and as a decimal otherwise.

Common mistakes

  • Mixing the order of subtraction: (y₂ − y₁) ÷ (x₁ − x₂) flips the sign of the slope. Start both subtractions from the same point.
  • Run over rise: dividing Δx by Δy gives the reciprocal, −3/2 instead of −2/3 in the worked example.
  • Calling a vertical slope infinity or 0: no number fits. Undefined is the answer, the line is written x = a, and zero belongs to horizontal lines.
  • Losing a sign when squaring: (−6)² is 36, so the example’s distance is √(81 + 36), not √(81 − 36).
  • Subtracting in the midpoint formula: the midpoint adds the coordinates before halving; (x₂ − x₁) ÷ 2 is half the run, not a coordinate.
  • Leaving fractions or a negative A in standard form: (2/3)x + y = 7/3 and −2x − 3y = −7 describe the same line as 2x + 3y = 7, but only the last one is in the usual standard form.

Questions

Is rate of change the same as slope?

For a straight line, yes. The slope is the constant rate of change of y with respect to x, so any two points on the line give the same answer. For a curve, the slope between two points is the average rate of change over that stretch, and it changes when you pick other points.

How do I find the slope from an equation?

Solve for y. In y = mx + b the slope is the number in front of x. From standard form Ax + By = C it is −A/B, as long as B isn’t 0, so 2x + 3y = 7 has slope −2/3. If B is 0 the line is vertical and has no slope.

Should I round the midpoint?

Usually not. Two whole-number coordinates always average to a whole number or a number ending in .5, so the exact midpoint is short anyway, like (1/2, 2) or (0.5, 2). Round only when the problem asks for it, and only at the end.

Sources

  1. College Algebra 2e, 4.1 Linear Functions OpenStax (Rice University) The slope formula m = (y₂ − y₁)/(x₂ − x₁); slope-intercept and point-slope forms; slope as the constant rate of change; a horizontal line has slope 0 and a vertical line’s slope is not defined, and a vertical line has no y-intercept unless it is x = 0; perpendicular slopes are negative reciprocals, which a horizontal and vertical pair doesn’t follow.
  2. College Algebra 2e, 2.1 The Rectangular Coordinate Systems and Graphs OpenStax (Rice University) The distance formula, derived from the Pythagorean theorem, and the midpoint formula M = ((x₁ + x₂)/2, (y₁ + y₂)/2).
  3. College Algebra 2e, 3.3 Rates of Change and Behavior of Graphs OpenStax (Rice University) The average rate of change between two points of a function is Δy/Δx = (y₂ − y₁)/(x₂ − x₁), and it need not be constant when the graph is not a line.
  4. Intermediate Algebra 2e, 3.2 Slope of a Line OpenStax (Rice University) Slope as rise over run; a vertical line’s slope is not defined because its run is 0 and division by zero is not defined; horizontal lines have slope 0.
  5. Intermediate Algebra 2e, 3.1 Graph Linear Equations in Two Variables OpenStax (Rice University) Standard form Ax + By = C, with the usual preference for whole-number A, B and C and A ≥ 0.
  6. Elementary Algebra 2e, 9.2 Simplify Square Roots OpenStax (Rice University) A square root is simplified when the number under it has no perfect-square factor; the product property √(ab) = √a · √b.
  7. Slope Wolfram MathWorld For a line making an angle θ with the x-axis, m = Δy/Δx = tan θ.
  8. Perpendicular Bisector Wolfram MathWorld The perpendicular bisector of a segment is perpendicular to it and passes through its midpoint.
  9. Guide to the ADA Accessibility Standards, Chapter 4: Ramps and Curb Ramps U.S. Access Board A ramp’s slope compares its rise with its horizontal run; the Standards write it as a ratio such as 1:12, and the guide also gives it as a percentage or in degrees, with 1:12 equal to 8.33%.