HomeMath › Slope Calculator

Slope Calculator

Computes the slope of the line through two points (rise over run), its y- and x-intercepts, the slope-intercept equation y = mx + b, the angle of inclination and the distance between the points.

When to use

You have two points and need the gradient or the equation of the line through them.

Do not use when: You need a best-fit line through many points (use linear-regression) or only the distance between two points (use distance-2d).

Formula

m = (y₂ − y₁) / (x₂ − x₁); b = y₁ − m·x₁; x_intercept = −b / m; angle = atan(m) × 180/π; distance = √(Δx² + Δy²)

Inputs

ParameterTypeUnitRequiredDescription
x1numberyesx-coordinate of the first point.
y1numberyesy-coordinate of the first point.
x2numberyesx-coordinate of the second point.
y2numberyesy-coordinate of the second point.

Outputs

OutputTypeUnitDescription
slopenumber(y₂ − y₁) / (x₂ − x₁); omitted for a vertical line.
slope_typestring'positive (rising)', 'negative (falling)', 'zero (horizontal line)' or 'undefined (vertical line)'.
y_interceptnumberValue of y where the line crosses the y-axis: y₁ − m·x₁.
x_interceptnumberValue of x where the line crosses the x-axis: −b / m (omitted for a horizontal line).
equationstringSlope-intercept form y = mx + b (or x = c for a vertical line).
angle_degreesnumber°atan(m) in degrees, between −90° and 90°.
delta_xnumberx₂ − x₁.
delta_ynumbery₂ − y₁.
distancenumber√(Δx² + Δy²).

Example

(1, 2) and (3, 6): {"x1":1,"y1":2,"x2":3,"y2":6}{"slope":2,"slope_type":"positive (rising)","y_intercept":0,"x_intercept":0,"equation":"y = 2x","angle_degrees":63.4349,"delta_x":2,"delta_y":4,"distance":4.472136}

(0, 3) and (4, 1): {"x1":0,"y1":3,"x2":4,"y2":1}{"slope":-0.5,"slope_type":"negative (falling)","y_intercept":3,"x_intercept":6,"equation":"y = -0.5x + 3","angle_degrees":-26.5651}

GET https://tttkmbb.com/api/v1/calculate/slope?x1=1&y1=2&x2=3&y2=6

Machine access

Sources

FAQ

What happens for a vertical line?

Δx = 0, so the slope is undefined and no y-intercept exists. The calculator returns the equation x = constant, an angle of 90° and no slope value.

Is slope the same as gradient or grade?

Slope and gradient are the same ratio. A road grade is the slope expressed in percent (slope × 100).

Related calculators