Xerobit

Slope Calculator: Slope, Distance and Line Equation

Enter the coordinates of two points to find the slope, the distance between them, the angle of inclination and the equation of the line. This slope calculator runs entirely in your browser, so nothing is uploaded to a server. It handles integers, decimals and negative values for any pair of points on a Cartesian plane.

Result

  • Slope (m)
    1.33333333333
  • Distance
    5
  • Angle
    53.1301023542°
  • Equation
    y = 1.33333333333x + 0.666666666667

How to use the slope calculator

  1. Enter the X and Y coordinates of your first point (X₁, Y₁).
  2. Enter the X and Y coordinates of your second point (X₂, Y₂).
  3. Read the slope (m), which is the rise divided by the run.
  4. Check the distance, angle and line equation that update automatically.

How the slope is calculated

The slope of a line measures its steepness and direction. It is defined as the change in the vertical axis (rise) divided by the change in the horizontal axis (run). The formula is:

m = (Y₂ - Y₁) / (X₂ - X₁)

For example, if your two points are (1, 2) and (4, 6), the calculation is (6 - 2) / (4 - 1) = 4 / 3, which gives a slope of approximately 1.333. A positive slope means the line rises from left to right, while a negative slope means it falls.

Finding the line equation

Once you have the slope, this slope calculator builds the equation of the line using the slope-intercept form: y = mx + b. The y-intercept (b) is found by rearranging the formula to b = Y₁ - m × X₁.

Using the same points (1, 2) and (4, 6) with a slope of 4/3: b = 2 - (4/3 × 1) = 2/3. So the full equation is y = 1.333x + 0.667. If the line is perfectly vertical, the slope is undefined and the equation takes the form x = c instead.

Distance and angle of inclination

The straight-line distance between two points uses the Pythagorean theorem: d = √((X₂ - X₁)² + (Y₂ - Y₁)²). For points (1, 2) and (4, 6), the differences are 3 and 4, so the distance is √(9 + 16) = √25 = 5.

The angle of inclination is the angle the line makes with the positive x-axis, measured counterclockwise. It is computed as θ = arctan(m) and converted from radians to degrees. A horizontal line has an angle of 0 degrees, and a line rising at a 45-degree angle has a slope of exactly 1.

Common slope values reference

This table shows how different slopes translate to angles and line behavior. Use it to quickly check your results from the slope calculator.

Slope (m)Angle (degrees)Line direction
00Horizontal
0.526.565Gentle rise
145Equal rise and run
263.435Steep rise
Undefined90Vertical
-1-45 (or 135)Equal fall

Practical uses for finding the slope

Calculating the gradient between two points is common in many fields. In construction and civil engineering, the slope determines drainage gradients, roof pitches and ramp accessibility. A wheelchair ramp, for instance, often requires a maximum slope of 1:12, meaning one unit of rise for every twelve units of run.

In finance and data analysis, the slope of a trend line represents the rate of change. If you plot revenue over time, the slope tells you how fast revenue is growing per period. In physics, the slope of a position-time graph gives velocity, and the slope of a velocity-time graph gives acceleration. For more complex linear algebra tasks, you might also use a linear equation solver or a matrix calculator.

Edge cases and common mistakes

The most frequent error when computing a slope manually is mixing up the order of subtraction. You must subtract the first point's coordinates from the second point's coordinates consistently in both the numerator and denominator. Swapping the order for only one axis will flip the sign of the result.

Another edge case is a vertical line where X₁ = X₂. Because the run is zero, dividing by zero makes the slope mathematically undefined. This slope calculator detects that condition and reports the line equation as x = X₁ rather than attempting an invalid division. Similarly, if both points are identical, there is no unique line, and the tool will flag the input as invalid.

Worked examples

Each result below was produced by the same code the tool runs, so you can check your own numbers against them.

ExampleInputResult
Simple positive slopeX₁ (first point): 0; Y₁ (first point): 0; X₂ (second point): 3; Y₂ (second point): 6Slope (m): 2; Distance: 6.7082039325; Angle: 63.4349488229°; Equation: y = 2x
Negative slopeX₁ (first point): -2; Y₁ (first point): 5; X₂ (second point): 3; Y₂ (second point): -5Slope (m): -2; Distance: 11.1803398875; Angle: -63.4349488229°; Equation: y = -2x + 1
Horizontal lineX₁ (first point): 1; Y₁ (first point): 4; X₂ (second point): 7; Y₂ (second point): 4Slope (m): 0; Distance: 6; Angle: 0°; Equation: y = 4
Decimal coordinatesX₁ (first point): 1.5; Y₁ (first point): 2.5; X₂ (second point): 3.5; Y₂ (second point): 7.5Slope (m): 2.5; Distance: 5.38516480713; Angle: 68.1985905136°; Equation: y = 2.5x - 1.25

FAQ

What is the formula for slope?

The formula is m = (Y₂ - Y₁) / (X₂ - X₁). You subtract the y-coordinates to find the rise, subtract the x-coordinates to find the run, and divide the rise by the run.

What does an undefined slope mean?

An undefined slope occurs when the two points share the same x-coordinate, creating a perfectly vertical line. Because the horizontal change is zero, the division is undefined.

Can the slope be negative?

Yes. A negative slope means the line descends from left to right. The y-values decrease as the x-values increase.

How do I find the y-intercept from two points?

First calculate the slope m. Then substitute one of your points into the equation b = Y₁ - m × X₁ to solve for the y-intercept b.

Does this slope calculator store my coordinates?

No. All calculations happen locally in your browser. Your coordinates are never sent to any server.

What is the difference between slope and gradient?

In basic two-dimensional geometry, slope and gradient refer to the same concept: the ratio of vertical change to horizontal change. In multivariable calculus, a gradient is a vector of partial derivatives.