Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 37 ยท Coordinate Geometry and Proof

Distance, Midpoint and Slope

Use the distance, midpoint and slope formulas on the coordinate plane, test for parallel and perpendicular lines, and classify polygons with code.

Coordinates turn geometry into arithmetic. Once every point has an address (x, y), you can calculate lengths, find centers and compare directions with formulas instead of rulers. This idea, from Renรฉ Descartes in the 1600s, is called coordinate geometry or analytic geometry. In this lesson you learn the three basic tools.

Distance between two points

Take points A = (x1, y1) and B = (x2, y2). Draw a horizontal and a vertical segment to make a right triangle with AB as hypotenuse. The legs have lengths |x2 - x1| and |y2 - y1|. Pythagoras gives:

Text
AB = โˆš( (x2 - x1)ยฒ + (y2 - y1)ยฒ )

Example: A = (1, 2) and B = (7, 10). Differences are 6 and 8, so AB = โˆš(36 + 64) = 10. The order of the points does not matter because the differences are squared.

Midpoint

The midpoint M of a segment is halfway between the endpoints, so its coordinates are the averages:

Text
M = ( (x1 + x2)/2 , (y1 + y2)/2 )

For A = (1, 2) and B = (7, 10): M = (4, 6). You can also work backward. If M = (4, 6) is the midpoint and one end is (1, 2), the other end is (2 ร— 4 - 1, 2 ร— 6 - 2) = (7, 10).

Slope

The slope m of a line measures steepness: rise divided by run.

Text
m = (y2 - y1) / (x2 - x1)

From (1, 2) to (7, 10): m = 8/6 = 4/3.

  • Positive slope: the line rises to the right.
  • Negative slope: it falls to the right.
  • Zero slope: a horizontal line.
  • A vertical line has an undefined slope (the run is zero, and you cannot divide by zero).

Parallel and perpendicular lines

  • Parallel lines have equal slopes: m1 = m2.
  • Perpendicular lines have slopes whose product is -1: m1 ร— m2 = -1. The slope of a perpendicular is the negative reciprocal. If m = 4/3, a perpendicular line has slope -3/4.

Check with a clear example: a line with slope 1 climbs at 45ยฐ, and the line with slope -1 descends at 45ยฐ. They meet at a right angle, and 1 ร— (-1) = -1.

flowchart TD
    A["Two points"] --> B["Distance: Pythagoras"]
    A --> C["Midpoint: averages"]
    A --> D["Slope: rise รท run"]
    D --> E["Equal slopes: parallel"]
    D --> F["Product -1: perpendicular"]

From two points you can get length, center and direction.

Worked example: what kind of quadrilateral?

Take the points A(0, 0), B(4, 1), C(5, 5), D(1, 4).

  • Sides: AB = โˆš17, BC = โˆš17, CD = โˆš17, DA = โˆš17. All four sides are equal.
  • Slopes: AB = 1/4, DC = (5 - 4)/(5 - 1) = 1/4, so AB โˆฅ DC. Also BC = 4, AD = 4, so BC โˆฅ AD.
  • Slopes 1/4 and 4 multiply to 1, not -1, so the angles are not right angles.

Four equal sides, so it is a rhombus that is not a square. The diagonals AC and BD have slopes 1 and -1, and 1 ร— (-1) = -1: they are perpendicular, as expected in a rhombus.

To prove that a shape is a square, you need four equal sides and a right angle (or equal diagonals). To prove a parallelogram, parallel opposite sides are enough.

A coordinate toolkit

The program below implements the three formulas with a careful treatment of vertical lines, and then uses them to classify the quadrilateral above.

Python Distance, midpoint and slope helpers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Classify a quadrilateral from coordinates

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The classifier uses math.isclose to compare decimals, because decimal arithmetic can leave tiny rounding errors that make == fail.

Common mistakes

  • Subtracting in different orders for x and y: use the same direction (B - A) for both.
  • Forgetting the square root in the distance formula.
  • Writing the perpendicular slope as -m instead of -1/m.
  • Dividing by zero for vertical lines.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the distance between (0, 0) and (5, 12)?

    โˆš(5ยฒ + 12ยฒ) = โˆš169 = 13.
  2. 2. What is the midpoint of (-2, 8) and (6, 0)?

    ((-2 + 6)/2, (8 + 0)/2) = (2, 4).
  3. 3. A line has slope 2/5. What is the slope of a line perpendicular to it?

    The perpendicular slope is the negative reciprocal: -5/2, since (2/5) ร— (-5/2) = -1.
  4. 4. Which pair of lines is parallel?

    Parallel lines have equal slopes.

Summary

  • Distance: โˆš((x2 - x1)ยฒ + (y2 - y1)ยฒ).
  • Midpoint: average the coordinates.
  • Slope: (y2 - y1)/(x2 - x1); parallel lines share a slope, perpendicular slopes multiply to -1.
  • Use these formulas to classify shapes and test claims from coordinates.

Next: Equations of Lines and Circles