# 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.

- Calculator id: `slope` · Category: Math (`math`) · Tool name: `calculate_slope`
- Canonical page: https://tttkmbb.com/math/slope · This document: https://tttkmbb.com/math/slope.md · JSON definition: https://tttkmbb.com/math/slope.json

## Purpose

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.

**Use when:** 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).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `x1` | number |  | required | x-coordinate of the first point. |
| `y1` | number |  | required | y-coordinate of the first point. |
| `x2` | number |  | required | x-coordinate of the second point. |
| `y2` | number |  | required | y-coordinate of the second point. |

## Output

| Field | 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²). |

## Formula

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

## Data Sources

- Wikipedia – Slope — https://en.wikipedia.org/wiki/Slope (reference, retrieved 2026-09-23)
- Wikipedia – Linear equation — https://en.wikipedia.org/wiki/Linear_equation (reference, retrieved 2026-09-23)
- Wolfram MathWorld – Slope — https://mathworld.wolfram.com/Slope.html (reference, retrieved 2026-09-23)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/slope?x1=…&y1=…&x2=…&y2=…`
- `POST https://tttkmbb.com/api/v1/calculate/slope` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/slope · OpenAPI operationId `calculate_slope` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "slope", "inputs": {…}}`

## Example

- (1, 2) and (3, 6): inputs `{"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): inputs `{"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
```

## Limitations

You need a best-fit line through many points (use linear-regression) or only the distance between two points (use distance-2d). All values are computed from the formula above; no measurement or live data is involved.

## 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

- [Distance Between Two Points Calculator](https://tttkmbb.com/math/distance-2d.md) — Distance and midpoint of the same two points.
- [Linear Regression Calculator](https://tttkmbb.com/statistics/linear-regression.md) — Best-fit line through many points.
- [Angle Converter](https://tttkmbb.com/conversion/angle.md) — Convert the inclination angle between degrees, radians and grades.
