geometry25 min

Coordinate Geometry

The coordinate plane, distance formula, and midpoint -- connecting algebra to geometry

0/9Not Started

Why This Matters

Coordinate geometry is the bridge between algebra and geometry. By placing shapes on a grid with x and y axes, you turn geometric questions into algebraic calculations. Instead of drawing and measuring, you compute. This is how computers do geometry: every point on a screen has pixel coordinates, every GPS location has latitude and longitude, and every game character has an (x, y, z) position.

The distance formula tells you exactly how far apart two points are, and the midpoint formula tells you the point exactly halfway between them. These two formulas are the foundation of everything in coordinate geometry: from finding the length of a line segment to determining whether two circles overlap.

The distance formula is just the Pythagorean theorem applied to the coordinate plane. The horizontal difference is one leg, the vertical difference is the other, and the distance is the hypotenuse. This connection between geometry and algebra is one of the most powerful ideas in mathematics, and it is how every computer graphics system, navigation app, and physics simulation works under the hood.

Define Terms

Visual Model

Coordinate Planex-axis and y-axis
Point A (x1, y1)First location
Point B (x2, y2)Second location
Horizontal (dx)x2 - x1
Vertical (dy)y2 - y1
Distancesqrt(dx^2 + dy^2)
Midpoint((x1+x2)/2, (y1+y2)/2)
Slopedy / dx

The full process at a glance. Click Start tour to walk through each step.

Two points on the coordinate plane give rise to distance (via the Pythagorean theorem), midpoint (via averaging), and slope (via the ratio of differences).

Code Example

Code
// Distance between two points
function distance(x1, y1, x2, y2) {
  const dx = x2 - x1;
  const dy = y2 - y1;
  return Math.sqrt(dx ** 2 + dy ** 2);
}
console.log("Distance (1,2)-(4,6):", distance(1, 2, 4, 6)); // 5
console.log("Distance (0,0)-(3,4):", distance(0, 0, 3, 4)); // 5

// Midpoint between two points
function midpoint(x1, y1, x2, y2) {
  return [(x1 + x2) / 2, (y1 + y2) / 2];
}
console.log("Midpoint (1,2)-(5,8):", midpoint(1, 2, 5, 8)); // [3, 5]
console.log("Midpoint (0,0)-(10,10):", midpoint(0, 0, 10, 10)); // [5, 5]

// Slope between two points
function slope(x1, y1, x2, y2) {
  if (x2 - x1 === 0) return Infinity; // vertical line
  return (y2 - y1) / (x2 - x1);
}
console.log("Slope (0,0)-(3,6):", slope(0, 0, 3, 6));   // 2
console.log("Slope (0,0)-(4,0):", slope(0, 0, 4, 0));   // 0
console.log("Slope (2,0)-(2,5):", slope(2, 0, 2, 5));   // Infinity

// Check if three points are collinear
function areCollinear(x1, y1, x2, y2, x3, y3) {
  // Area of triangle is zero if points are collinear
  const area = Math.abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
  return area === 0;
}
console.log("Collinear (0,0),(1,1),(2,2):", areCollinear(0,0,1,1,2,2)); // true
console.log("Collinear (0,0),(1,1),(2,3):", areCollinear(0,0,1,1,2,3)); // false

Interactive Experiment

Try these exercises:

  • Find the distance between (3, 7) and (6, 11). Break it into dx and dy, then use the formula.
  • Compute the midpoint of (-4, 2) and (8, -6). Verify that the midpoint is equidistant from both endpoints.
  • What is the slope of a horizontal line? What about a vertical line? Test with coordinates.
  • Given three points (0, 0), (3, 4), and (6, 8), are they collinear? Compute the slopes between consecutive pairs to check.
  • Find a point that is exactly distance 10 from the origin. How many such points exist?

Quick Quiz

Coding Challenge

Distance and Midpoint Calculator

Write a function called `distanceAndMidpoint` that takes four numbers (x1, y1, x2, y2) and returns an object with two properties: `distance` (the distance between the two points, rounded to 2 decimal places) and `midpoint` (an array [mx, my] with the midpoint coordinates).

Loading editor...

Real-World Usage

Coordinate geometry powers countless applications:

  • GPS and mapping: Every location on Earth is represented by coordinates (latitude, longitude). Distance between locations uses a version of the distance formula adapted for a sphere.
  • Computer graphics: Every pixel, vertex, and sprite has coordinates. Distance and midpoint calculations drive rendering, animation, and interaction.
  • Robotics and motion planning: Robots navigate by computing distances to obstacles and waypoints in coordinate space.
  • Data science: Euclidean distance (the distance formula) is the basis of clustering algorithms like k-means and nearest-neighbor classifiers.
  • Physics simulations: Position, velocity, and acceleration are all vectors in coordinate space. The distance formula computes forces that depend on separation.

Connections