Calculate Slope

Slope Calculator

Calculate the steepness, gradient, and line equation between two points.

Point 1 (x₁, y₁)

Point 2 (x₂, y₂)

Results

Slope (m):

Angle of Inclination: °

Percentage Grade: %

Equation:

ΔY (Rise):

ΔX (Run):

Understanding Slope Calculation

In mathematics, the slope (also called the gradient) of a line is a number that describes both the direction and the steepness of the line. It is frequently defined as the "rise over run."

The Slope Formula

To find the slope (m) between two points $(x_1, y_1)$ and $(x_2, y_2)$, use the following formula:

m = (y₂ – y₁) / (x₂ – x₁)

Key Terms Explained

  • Rise (ΔY): The vertical change between the two points.
  • Run (ΔX): The horizontal change between the two points.
  • Positive Slope: The line goes up from left to right.
  • Negative Slope: The line goes down from left to right.
  • Zero Slope: A perfectly horizontal line ($y$ values are the same).
  • Undefined Slope: A perfectly vertical line ($x$ values are the same).

Example Calculation

Suppose you have two points: Point A (1, 2) and Point B (4, 8).

  1. Identify coordinates: $x_1=1, y_1=2$ and $x_2=4, y_2=8$.
  2. Calculate Rise: $8 – 2 = 6$.
  3. Calculate Run: $4 – 1 = 3$.
  4. Calculate Slope: $6 / 3 = 2$.

The slope is 2, meaning for every 1 unit you move to the right, the line goes up by 2 units.

function calculateSlope() { var x1 = parseFloat(document.getElementById('x1').value); var y1 = parseFloat(document.getElementById('y1').value); var x2 = parseFloat(document.getElementById('x2').value); var y2 = parseFloat(document.getElementById('y2').value); var display = document.getElementById('slope-results'); if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) { alert("Please enter valid numbers for all coordinates."); return; } var rise = y2 – y1; var run = x2 – x1; var m, angle, percent, eq; if (run === 0) { m = "Undefined (Vertical)"; angle = 90; percent = "∞"; eq = "x = " + x1; } else { var slopeVal = rise / run; m = slopeVal.toFixed(4); // Clean up .0000 if (m.indexOf('.0000') > -1) m = parseInt(m); angle = (Math.atan(slopeVal) * (180 / Math.PI)).toFixed(2); percent = (slopeVal * 100).toFixed(2); var b = y1 – (slopeVal * x1); var bSign = b >= 0 ? "+ " : "- "; var bAbs = Math.abs(b).toFixed(2); if (bAbs.indexOf('.00') > -1) bAbs = parseInt(bAbs); if (slopeVal === 0) { eq = "y = " + y1; } else { eq = "y = " + (slopeVal === 1 ? "" : (slopeVal === -1 ? "-" : slopeVal.toFixed(2))) + "x " + (b === 0 ? "" : bSign + bAbs); } } document.getElementById('res-m').innerText = m; document.getElementById('res-angle').innerText = angle; document.getElementById('res-percent').innerText = percent; document.getElementById('res-eq').innerText = eq; document.getElementById('res-rise').innerText = rise.toFixed(2); document.getElementById('res-run').innerText = run.toFixed(2); display.style.display = 'block'; }

Leave a Comment