Slope Calculator with the Line Drawn to Scale

Slope Calculator

Slope from two points, or the missing piece when you already know the slope. Gives you the gradient, the equation of the line, the angle, the distance, the midpoint and the perpendicular slope, with the line drawn so you can see whether the answer looks right.

Two pointsPoint and slopeEquation of the lineAngle and gradePerpendicularDrawn to scale
The working
Four small coordinate grids showing the four kinds of slope. A positive line from (1,2) to (4,8) with rise 6 over run 3 giving m equals 2. A negative line from (0,5) to (5,0) giving m equals minus 1. A horizontal line from (0,3) to (5,3) giving m equals 0. A vertical line from (2,1) to (2,9) where the run is zero so the slope is undefined.
Three of these have a number and the fourth does not. Worth dwelling on the last panel, because a vertical line having no slope is different from a flat line having a slope of zero, and mixing those two up is the single most common error in the topic.

How to use this tool

Type two points and everything else follows. If you already know the slope and have one point on the line, switch to the second mode and the tool will build the equation from those instead. The drawing is not decoration: it is generated from the same numbers as the results, so if the line on screen does not look like what you expected, you have found a typo in your coordinates rather than a bug in the arithmetic.

The order of the points does not matter. Swapping them flips the sign of both the rise and the run, and those two sign changes cancel, so the slope comes out the same. The one input people get wrong is a minus sign on a coordinate, which flips the line from rising to falling and is instantly visible in the drawing.

What the calculation is doing

Slope is rise over run: how far the line climbs divided by how far it travels sideways over the same stretch. Write it as m equals y2 minus y1, all over x2 minus x1. It is a rate, not a distance, which is why it has no units of its own and why the same slope describes a line whether you measure it over one metre or a hundred.

Once you have m, the intercept comes free. Any point on the line satisfies y equals mx plus b, so rearranging gives b equals y1 minus m times x1. Substitute either of your two points and you get the same b, which is a quick way to check your own arithmetic on paper.

The angle is the arctangent of the slope, because the rise and run are the opposite and adjacent sides of a right triangle. That gives the neat facts worth memorising: a slope of 1 is exactly 45 degrees, a slope of 2 is 63.43 degrees, and a slope of 0.5 is 26.57. The percent grade used on road signs is simply the slope times 100, so a 6 percent hill has a slope of 0.06 and an angle of about 3.4 degrees. Grades sound steeper than they are.

The two cases that are not the same thing

A horizontal line has a slope of zero. The rise is nothing, the run is whatever you like, and zero divided by anything is zero. That is a real number and a perfectly ordinary answer.

A vertical line has no slope at all. The run is zero, so the fraction asks you to divide by nothing, and division by zero is not a large number or an infinite one, it is simply not defined. This is why the tool prints the word undefined rather than a symbol. A vertical line also has no y intercept unless it happens to be the y axis itself, and it cannot be written as y equals mx plus b in any form. Its equation is x equals a constant, which is why that is what appears in the equation bar when you enter two points with the same x.

The pairing is worth holding on to: horizontal and vertical are perpendicular to each other, so the perpendicular of a zero slope is an undefined one and the other way round. That is exactly what the perpendicular card shows, and it is the reason it sometimes reads undefined instead of giving you a number.

For every other pair, perpendicular slopes multiply to minus one. So a line of slope 2 meets a line of slope minus a half at a right angle. Parallel lines simply share the same slope and differ only in their intercept.

Slope here and slope distance elsewhere on this site

The word gets used for two different things and it is worth being clear which one you want. On this page slope means the gradient, a ratio with no units, the m in y equals mx plus b. In surveying and site work, slope distance means the length measured along the ground between two points at different heights, which is the hypotenuse rather than a ratio and is measured in metres or feet. That one belongs in the distance calculator linked below. If your problem gives you a tape reading along a hillside, you want slope distance. If it gives you two coordinates and asks how steep the line is, you are in the right place.

A worked check you can repeat on paper

The tool loads with (1,2) and (4,8). The rise is 8 minus 2, which is 6. The run is 4 minus 1, which is 3. So the slope is 6 over 3, or 2. In lowest terms that is 2 over 1, meaning the line climbs two units for every one it moves right.

For the intercept, take b equals y1 minus m times x1, which is 2 minus 2 times 1, so b is 0. Check it with the other point: 8 minus 2 times 4 is also 0. Both agree, so the line passes through the origin and the equation is y equals 2x.

The angle is arctan of 2, which is 63.435 degrees, and the grade is 200 percent. The distance is the square root of 3 squared plus 6 squared, so the root of 45, which is 6.7082. The midpoint is the average of each coordinate, giving (2.5, 5). The perpendicular slope is minus a half, and checking that, 2 times minus 0.5 is minus 1 as it should be.

Now change x2 to 1 so both points sit at x equals 1. The slope card switches to undefined, the equation becomes x equals 1, and the drawing shows a vertical line. That is the fourth panel of the diagram, live.

Mistakes that catch people out

  • Calling a vertical line a slope of zero. It is undefined. Flat lines are the zero ones. Getting these the wrong way round is worth full marks on a question and a wrong answer on a drawing.
  • Putting the run on top. Rise over run, not run over rise. The inverted answer is often plausible looking, which is what makes it dangerous, so sanity check against the angle: a slope under 1 must be under 45 degrees.
  • Subtracting the coordinates in a different order top and bottom. If you do y2 minus y1 on top you must do x2 minus x1 underneath. Mixing the order flips the sign and turns an uphill line into a downhill one.
  • Reading a percent grade as an angle. A 100 percent grade is 45 degrees, not 90. Grades and angles only agree near zero, and they diverge quickly after that.
  • Assuming perpendicular means the negative slope. It is the negative reciprocal. The perpendicular of 3 is minus a third, not minus 3.
  • Using the slope of a curve. Two points on a curve give you the average rate of change between them, not the slope at either one. For that you need the derivative, and no amount of care with the arithmetic here will get you it.

How this was checked

The engine was written twice and compared on the same inputs. All four cases from the diagram were checked by hand: the positive line returns 2 with an intercept of 0 and an angle of 63.4349 degrees, the negative one returns minus 1 at minus 45 degrees, the horizontal returns exactly 0 with an undefined perpendicular, and the vertical returns the undefined flag with an angle of 90. The distance formula was anchored on a 3, 4, 5 triangle returning exactly 5. The perpendicular was checked by multiplying it back against the original slope to confirm it lands on minus 1. The drawing is generated from the same solved values as the cards rather than from the raw inputs, so the picture cannot drift away from the numbers.

Related Calculators and Reference