Coordinate Geometry: Algebra on the Plane

A complete, plain-language guide with worked examples, diagrams, tables and links to AI and machine learning

In this article
  1. Introduction
  2. The coordinate plane
  3. Distance between two points
  4. Midpoint and section formula
  5. Slope and the equation of a line
  6. Parallel and perpendicular lines
  7. Circles
  8. Areas and transformations
  9. Distance as a design choice
  10. AI and machine learning
  11. Common mistakes
  12. Practice problems
  13. Conclusion

1. Introduction

Coordinate geometry joins two worlds that were once separate: algebra, which manipulates symbols, and geometry, which studies shapes. The bridge is a simple idea due to René Descartes. Give every point in a plane a pair of numbers, and every shape becomes an equation. A line is a linear equation. A circle is a quadratic one. Distances, angles and areas become arithmetic.

This matters far beyond the classroom. Maps and GPS use coordinates. Every pixel on a screen has a position. Computer graphics rotate and scale objects with coordinate formulas. And in machine learning, a data example is a point whose coordinates are its features, so questions such as "which examples are similar?" become questions about distance in space.

This article walks through the coordinate plane, distance, midpoints, slope and line equations, parallel and perpendicular lines, circles, areas and transformations, and the choice of distance measure. We close with how these ideas run through AI and machine learning, and with a look back at the whole series.

2. The coordinate plane

The coordinate plane is built from two number lines that cross at right angles. The horizontal one is the x-axis, the vertical one the y-axis, and they meet at the origin, written (0, 0). A point is described by an ordered pair (x, y): how far to move horizontally, then how far vertically. Order matters, since (3, 2) and (2, 3) are different places.

Coordinate plane with four quadrants and four labelled points
The plane has four quadrants; each point is read as (horizontal, vertical).

The axes divide the plane into four quadrants, numbered anticlockwise from the top right. The signs of the two coordinates tell you which quadrant a point is in.

The four quadrants
QuadrantSign of xSign of yExample
I++A (3, 2)
II−+B (−4, 3)
III−−C (−3, −4)
IV+−D (5, −3)
on an axisx = 0 or y = 0(0, 4) or (−2, 0)

Many computer images flip the vertical direction, putting the origin at the top left with y increasing downward. It is a useful reminder that a coordinate system is a convention, and you should always check which one a tool uses.

3. Distance between two points

How far apart are two points? Take P(1, 2) and Q(4, 6). Move across by 3 and up by 4, and you have the two short sides of a right triangle. The straight line between the points is the hypotenuse, so Pythagoras gives its length. This is the distance formula.

Right triangle between P and Q showing run 3 rise 4 and distance 5
The distance formula is Pythagoras applied to the horizontal and vertical gaps.

In symbols, the distance between (x₁, y₁) and (x₂, y₂) is d = √((x₂ − x₁)² + (y₂ − y₁)²). Squaring removes any sign, so the order of the points does not matter. For our example, d = √(9 + 16) = 5.

Distance examples
PointsGaps (Δx, Δy)WorkingDistance
(1, 2), (4, 6)3, 4√(9 + 16)5
(−2, 3), (4, −5)6, −8√(36 + 64)10
(0, 0), (5, 12)5, 12√(25 + 144)13
(2, 3), (2, 9)0, 6√36 (vertical line)6

If the points share an x or a y, the formula collapses to a simple subtraction. The last row is just 9 − 3. The same idea extends to three dimensions by adding a third squared gap under the root, and to any number of dimensions in machine learning.

4. Midpoint and section formula

The midpoint of a segment is the point halfway along it. Average the two x-values and average the two y-values: M = ((x₁ + x₂)/2, (y₁ + y₂)/2). For P(1, 2) and Q(4, 6), the midpoint is (2.5, 4), marked in the earlier figure.

A more general tool is the section formula. A point that divides the segment from P to Q in the ratio m : n has coordinates ((n·x₁ + m·x₂)/(m + n), (n·y₁ + m·y₂)/(m + n)). When m = n, it is the midpoint. For P(1, 2) and Q(7, 8) with ratio 2 : 1, the point is ((1·1 + 2·7)/3, (1·2 + 2·8)/3) = (5, 6), two thirds of the way along.

Midpoints and divisions
SegmentRatioResult
(1, 2) to (4, 6)1 : 1(2.5, 4)
(−2, 3) to (4, −5)1 : 1(1, −1)
(1, 2) to (7, 8)2 : 1(5, 6)
(1, 2) to (7, 8)1 : 2(3, 4)

This weighted average is the same idea as blending two colors or interpolating between two positions in an animation: a parameter slides the result from one end to the other.

5. Slope and the equation of a line

The slope of a line measures its steepness: the rise divided by the run, m = (y₂ − y₁)/(x₂ − x₁). For our points, m = (6 − 2)/(4 − 1) = 4/3. A positive slope climbs from left to right, a negative one falls, zero is flat, and a vertical line has no slope at all because the run is zero.

Six lines through the origin with different slopes
Larger slope means a steeper line; the sign gives the direction.

There are three standard ways to write a line's equation, each suited to different information. With the slope and the y-intercept b, use slope-intercept form, y = mx + b. With a slope and one point, use point-slope form, y − y₁ = m(x − x₁). And ax + by + c = 0 is the general form, which also handles vertical lines.

Three forms of a line equation
FormEquationBest used whenExample (through (1, 2), (4, 6))
slope-intercepty = mx + byou know the slope and intercepty = (4/3)x + 2/3
point-slopey − y₁ = m(x − x₁)you know a point and the slopey − 2 = (4/3)(x − 1)
generalax + by + c = 0comparing lines, distances4x − 3y + 2 = 0

To build the equation, find the slope, 4/3, use point-slope form with (1, 2), then simplify. Always check with the second point: at x = 4, y = (4/3)(4) + 2/3 = 6, which matches.

Reading a line from its equation
EquationSlopey-interceptx-intercept
y = 2x + 121−0.5
y = −x + 3−133
y = 0.5x − 20.5−24
3x + 4y − 12 = 0−3/434

6. Parallel and perpendicular lines

Two lines are parallel when they have the same slope, so they never meet. Two lines are perpendicular when their slopes multiply to −1, that is, when one slope is the negative reciprocal of the other. If one line has slope 2, a perpendicular line has slope −1/2.

Two parallel lines and a perpendicular line crossing both
Lines l₁ and l₂ are parallel; l₃ is perpendicular to both.
Slope relationships
RelationshipConditionExample
parallelm₁ = m₂y = 2x + 1 and y = 2x − 3
perpendicularm₁ · m₂ = −12 × (−1/2) = −1
horizontal ⟂ verticalspecial casey = 3 and x = 5

The distance from a point (x₀, y₀) to the line ax + by + c = 0 is |a·x₀ + b·y₀ + c| / √(a² + b²). For the point (3, 4) and the line 3x + 4y − 5 = 0, that is |9 + 16 − 5| / 5 = 4. The distance between parallel lines is the distance from any point of one to the other. The figure shows y = 2x + 1 and y = 2x − 3: writing the second as 2x − y − 3 = 0 and using the point (1, 3), we get |2 − 3 − 3| / √5 = 4/√5 ≈ 1.79.

Point-to-line distances
PointLineWorkingDistance
(3, 4)3x + 4y − 5 = 0|9 + 16 − 5| / 54
(1, 3)2x − y − 3 = 0|2 − 3 − 3| / √51.79
(3, 0)x − y = 0|3| / √22.12

7. Circles

A circle is the set of all points at a fixed distance r (the radius) from a fixed point (the center). The definition is the distance formula in disguise. If the center is (h, k), a point (x, y) is on the circle when its distance to the center is r, and squaring gives (x − h)² + (y − k)² = r².

Circle with centre (2, -1) and radius 3 with points inside, on and outside
Comparing the squared distance with r² tells you where a point lies.

The circle with center (2, −1) and radius 3 is (x − 2)² + (y + 1)² = 9. To test a point, compute the left side: if it equals 9 the point is on the circle, if less it is inside, and if more it is outside.

Testing points against (x − 2)² + (y + 1)² = 9
PointLeft sideCompared with 9Position
(5, −1)9 + 0 = 9equalon circle
(2, 2)0 + 9 = 9equalon circle
(3, 0)1 + 1 = 2lessinside
(6, 2)16 + 9 = 25greateroutside

Expanding gives the general form x² + y² − 4x + 2y − 4 = 0. To go the other way, complete the square. For x² + y² − 6x + 4y − 12 = 0, the center is (3, −2) and the radius is √(9 + 4 + 12) = 5. Circles are a quadratic relation, which links this topic to the earlier article on quadratic equations.

8. Areas and transformations

Coordinates make area a matter of arithmetic. For a polygon with vertices listed in order, the shoelace formula gives the area: multiply each x by the next y, subtract each y times the next x, sum, and halve the absolute value. For a triangle with vertices (1, 1), (5, 2), (3, 6), the area is ½ |1(2 − 6) + 5(6 − 1) + 3(1 − 2)| = ½ |−4 + 25 − 3| = 9.

Triangle areas by coordinates
VerticesWorkingArea
(0, 0), (4, 0), (0, 3)½ × 4 × 36
(1, 1), (5, 2), (3, 6)½ |−4 + 25 − 3|9
(1, 1), (3, 1), (1, 2)½ × 2 × 11

A transformation moves every point by a rule. A translation adds a fixed amount to each coordinate. A scaling by a factor s multiplies every coordinate, so lengths grow by s and areas by s². A rotation by 90° anticlockwise about the origin sends (x, y) to (−y, x). Rotations and translations keep lengths and areas the same; scaling does not.

A triangle with scaled, rotated and shifted copies
One triangle and three transformed copies.
Transforming the triangle (1,1), (3,1), (1,2)
TransformationRuleNew verticesArea
originalnone(1, 1), (3, 1), (1, 2)1
scale ×2(x, y) → (2x, 2y)(2, 2), (6, 2), (2, 4)4
rotate 90°(x, y) → (−y, x)(−1, 1), (−1, 3), (−2, 1)1
translate(x, y) → (x + 3, y − 4)(4, −3), (6, −3), (4, −2)1

Every movement of an object on a screen, from a game character to a photo being rotated, is a chain of such rules. They are applied together by using matrices, which bring us back to the algebra of functions and linear equations.

9. Distance as a design choice

The standard distance, the straight-line one, is called Euclidean distance. It is not the only reasonable choice. A taxi in a city grid cannot cut across blocks, so the distance it travels is the sum of the horizontal and vertical gaps. This is Manhattan distance. A third, Chebyshev distance, takes the larger of the two gaps, as a chess king moves.

Three distances between (1, 2) and (4, 6)
NameFormulaWorkingValue
Euclidean√(Δx² + Δy²)√(9 + 16)5
Manhattan|Δx| + |Δy|3 + 47
Chebyshevmax(|Δx|, |Δy|)max(3, 4)4
Unit circles under three different distance measures: round, diamond and square
Each measure defines its own "circle" of points at distance 1 from the origin.

A circle is just all points at a fixed distance, so changing the distance changes the circle's shape: round for Euclidean, a diamond for Manhattan, a square for Chebyshev. The choice affects which examples count as nearest neighbors, so it is a modelling decision, not a detail.

10. AI and machine learning

In machine learning, every example is a point. A house described by its size and its age is the point (size, age); a photo with a million pixels is a point in a million-dimensional space. The geometry of this space then drives the algorithms. Similar examples are close together, so distance becomes a measure of similarity.

The k-nearest-neighbors method uses this directly. To classify a new example, find the k closest training points and let them vote. Take a query (4, 4) among four red points and five blue ones. The distances to the three closest are 1, 1.41 and 2, and all three belong to the blue class, so the prediction is blue.

Scatter of red and blue points with a query point and a dashed circle around its nearest neighbours
k-nearest neighbors is a distance calculation followed by a vote.
Nearest neighbors of the query (4, 4)
RankPointClassDistance
1(5, 4)blue1.00
2(5, 5)blue1.41
3(4, 6)blue2.00
4(2, 3)red2.24
5(6.5, 3)blue2.69

With k = 3 the vote is 3 blue to 0 red. With k = 5 it is 4 blue to 1 red. Both give blue, but with a harder example the answer can change with k, which is why k is tuned.

Clustering uses the same geometry without labels. The k-means algorithm alternates two steps: assign each point to the nearest center, then move each center to the mean (the average coordinates) of its points. Take seven points and starting centers (1, 1) and (9, 8). The first four points join the first center and the last three the second. The new centers are (2.25, 2.5) and (7.67, 7), and another pass changes no assignments, so the algorithm stops.

Two panels showing k-means assignment and the movement of the centres
k-means alternates assigning points and moving centres.
k-means on seven points
PointDistance to (1, 1)Distance to (9, 8)Cluster
(1, 1)0.0010.631
(2, 2)1.419.221
(1, 3)2.009.431
(5, 4)5.005.661
(6, 6)7.073.612
(8, 7)9.221.412
(9, 8)10.630.002

Linear classifiers are lines and planes. The decision boundary w · x + b = 0 is a line in two dimensions, a plane in three and a hyperplane beyond. The distance from a point to this boundary, using the formula from section 6, is a measure of confidence: for the boundary 2x − y − 1 = 0, the point (3, 2) is |6 − 2 − 1| / √5 = 3/√5 ≈ 1.34 away. Support vector machines choose the boundary that keeps the points as far away as possible.

Direction can matter more than distance, especially for text and image embeddings. Cosine similarity compares the angle between two vectors: cos θ = (u · v)/(|u| |v|). It is 1 when the vectors point the same way, 0 when they are perpendicular, and the size does not matter.

Cosine similarity examples
Vector uVector vCosineMeaning
(1, 2)(2, 4)1.00same direction
(3, 4)(4, 3)0.96very similar
(1, 0)(0, 1)0.00unrelated (perpendicular)

In computer vision, an object detector draws a bounding box with corner coordinates. Its quality is scored by intersection over union: the overlap area divided by the combined area. For boxes (0, 0)–(4, 4) and (2, 2)–(6, 6), the overlap is a 2 × 2 square of area 4, the union is 16 + 16 − 4 = 28, and the score is 4/28 ≈ 0.14, a poor match.

Finally, gradient descent is a walk through coordinates. For the loss f(x, y) = x² + y² at (3, 4), the gradient is (6, 8). With a step size of 0.1, the new point is (3, 4) − 0.1 × (6, 8) = (2.4, 3.2), which is closer to the minimum at the origin: its distance falls from 5 to 4, a 20% drop each step.

Coordinate geometry in machine learning
Geometric ideaMachine learning use
distance between pointsnearest neighbors, similarity search, clustering
midpoint / mean of pointsk-means centers, averaging embeddings
line, plane, hyperplanelinear and logistic classifiers, SVMs
point-to-line distancemargin and confidence of a classifier
angle between vectorscosine similarity for text and image embeddings
box overlapobject detection scoring (IoU)
transformationsimage augmentation: rotate, scale, shift
walk along the slopegradient descent

11. Common mistakes

Frequent mistakes and corrections
MistakeWrongRight
Swapping x and yplotting (2, 3) as 3 across, 2 upx first: 2 across, 3 up
Forgetting the square rootd = (3)² + (4)² = 25d = √(9 + 16) = 5
Adding instead of averagingmidpoint (1, 2),(4, 6) = (5, 8)(2.5, 4)
Slope upside downm = Δx/Δy = 3/4m = Δy/Δx = 4/3
Perpendicular slope sign2 → 1/22 → −1/2
Wrong center sign(x − 2)² + (y + 1)² = 9 → center (−2, 1)center (2, −1)
Radius versus r²(x − 2)² + (y + 1)² = 9 → r = 9r² = 9, so r = 3

12. Practice problems

Try these before looking at the answers.

  1. Find the distance between (−1, 2) and (5, 10).
  2. Find the midpoint of (−3, 4) and (7, −2).
  3. Find the slope and equation of the line through (2, 1) and (6, 9).
  4. Write the equation of the line through (0, 5) that is perpendicular to y = 2x + 1.
  5. Write the equation of the circle with center (−1, 3) and radius 4.
  6. Is (2, 2) inside the circle x² + y² = 9?
  7. Find the area of the triangle (0, 0), (6, 0), (2, 5).
  8. A query point is (5, 5). Which is nearer by Euclidean distance: (2, 9) or (8, 1)?

Answers.

  1. √(6² + 8²) = 10.
  2. ((−3 + 7)/2, (4 − 2)/2) = (2, 1).
  3. m = (9 − 1)/(6 − 2) = 2; y − 1 = 2(x − 2), so y = 2x − 3.
  4. The slope is −1/2 and the intercept is 5, so y = −x/2 + 5.
  5. (x + 1)² + (y − 3)² = 16.
  6. 2² + 2² = 8 < 9, so yes, it is inside.
  7. ½ × 6 × 5 = 15 (base 6, height 5).
  8. Both are exactly 5 away: √(9 + 16) and √(9 + 16). It is a tie, which shows why real systems need a tie-breaking rule.

13. Conclusion

Coordinate geometry turns shapes into equations. Distance comes from Pythagoras, midpoints from averaging, lines from slope, circles from a fixed distance, and areas from the shoelace formula. Parallel lines share a slope, perpendicular lines have slopes whose product is −1, and the choice of distance measure changes what "near" means.

In machine learning, this is the working language: data points are coordinates, similarity is distance or angle, classifiers are lines and hyperplanes, and learning is a walk through coordinate space. This is the last article in the series, and it brings the threads together. Variables and expressions give the symbols; linear and quadratic equations give the basic shapes; functions and composition describe how things transform; exponentials and logarithms capture growth; sequences and series describe repetition and sums; inequalities set the limits; and coordinate geometry puts all of it on a map you can see and measure.