Home › Math › 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
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
x1 | number | yes | x-coordinate of the first point. | |
y1 | number | yes | y-coordinate of the first point. | |
x2 | number | yes | x-coordinate of the second point. | |
y2 | number | yes | y-coordinate of the second point. |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
slope | number | (y₂ − y₁) / (x₂ − x₁); omitted for a vertical line. | |
slope_type | string | 'positive (rising)', 'negative (falling)', 'zero (horizontal line)' or 'undefined (vertical line)'. | |
y_intercept | number | Value of y where the line crosses the y-axis: y₁ − m·x₁. | |
x_intercept | number | Value of x where the line crosses the x-axis: −b / m (omitted for a horizontal line). | |
equation | string | Slope-intercept form y = mx + b (or x = c for a vertical line). | |
angle_degrees | number | ° | atan(m) in degrees, between −90° and 90°. |
delta_x | number | x₂ − x₁. | |
delta_y | number | y₂ − y₁. | |
distance | number | √(Δ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
- API:
GET https://tttkmbb.com/api/v1/calculate/slope(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/slope · Markdown: https://tttkmbb.com/math/slope.md · JSON definition: https://tttkmbb.com/math/slope.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="slope" - OpenAPI operationId:
calculate_slope - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
- Wikipedia – Slope (reference)
- Wikipedia – Linear equation (reference)
- Wolfram MathWorld – Slope (reference)
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
- Distance Between Two Points Calculator — Distance and midpoint of the same two points.
- Linear Regression Calculator — Best-fit line through many points.
- Angle Converter — Convert the inclination angle between degrees, radians and grades.