Slope Calculator from Points

Slope Calculator from Points

Calculate gradient, distance, and line equations instantly

Point 1 (x₁, y₁)

Point 2 (x₂, y₂)

Results:

Slope (m):

Distance:

Angle (θ): °

y-intercept (b):

Equation:


Understanding the Slope Formula

In analytical geometry, the slope (also called the gradient) of a line represents the "steepness" and direction of the line. It is defined as the ratio of the vertical change (the "rise") to the horizontal change (the "run") between two distinct points on the line.

The Slope Formula

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

How to Calculate Slope from Two Points

  1. Identify Coordinates: Label your first point as (x₁, y₁) and your second point as (x₂, y₂).
  2. Subtract y-values: Calculate the difference between the y-coordinates (y₂ – y₁). This is your "Rise".
  3. Subtract x-values: Calculate the difference between the x-coordinates (x₂ – x₁). This is your "Run".
  4. Divide: Divide the rise by the run. The resulting value m is your slope.

Practical Example

Suppose you have two points on a graph: Point A (2, 3) and Point B (6, 11).

  • Rise: 11 – 3 = 8
  • Run: 6 – 2 = 4
  • Slope: 8 / 4 = 2

This means for every 1 unit you move to the right, the line moves 2 units upward.

Special Cases

  • Horizontal Lines: If y₁ = y₂, the slope is 0.
  • Vertical Lines: If x₁ = x₂, the slope is undefined (division by zero). This calculator will notify you if your points form a vertical line.
  • Positive vs. Negative: A positive slope leans to the right (upward), while a negative slope leans to the left (downward).
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 resultsArea = document.getElementById('results-area'); var resSlope = document.getElementById('res-slope'); var resDistance = document.getElementById('res-distance'); var resAngle = document.getElementById('res-angle'); var resIntercept = document.getElementById('res-intercept'); var resEquation = document.getElementById('res-equation'); if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) { alert("Please enter valid numbers for all coordinates."); return; } resultsArea.style.display = 'block'; var dx = x2 – x1; var dy = y2 – y1; // Distance calculation var distance = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); resDistance.innerHTML = distance.toFixed(4); if (dx === 0) { // Vertical line resSlope.innerHTML = "Undefined (Vertical)"; resAngle.innerHTML = "90"; resIntercept.innerHTML = "None"; resEquation.innerHTML = "x = " + x1; } else { var m = dy / dx; var b = y1 – (m * x1); var angleRad = Math.atan(m); var angleDeg = angleRad * (180 / Math.PI); resSlope.innerHTML = m.toFixed(4); resAngle.innerHTML = angleDeg.toFixed(2); resIntercept.innerHTML = b.toFixed(4); // Build equation string var mStr = m === 1 ? "" : (m === -1 ? "-" : m.toFixed(2)); var bSign = b >= 0 ? " + " : " – "; var bStr = Math.abs(b).toFixed(2); if (m === 0) { resEquation.innerHTML = "y = " + b.toFixed(2); } else { resEquation.innerHTML = "y = " + mStr + "x" + (b === 0 ? "" : bSign + bStr); } } }

Leave a Comment