- Introduction
- The coordinate plane
- Distance between two points
- Midpoint and section formula
- Slope and the equation of a line
- Parallel and perpendicular lines
- Circles
- Areas and transformations
- Distance as a design choice
- AI and machine learning
- Common mistakes
- Practice problems
- 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.
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.
| Quadrant | Sign of x | Sign of y | Example |
|---|---|---|---|
| I | + | + | A (3, 2) |
| II | − | + | B (−4, 3) |
| III | − | − | C (−3, −4) |
| IV | + | − | D (5, −3) |
| on an axis | x = 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.
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.
| Points | Gaps (Δx, Δy) | Working | Distance |
|---|---|---|---|
| (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.
| Segment | Ratio | Result |
|---|---|---|
| (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.
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.
| Form | Equation | Best used when | Example (through (1, 2), (4, 6)) |
|---|---|---|---|
| slope-intercept | y = mx + b | you know the slope and intercept | y = (4/3)x + 2/3 |
| point-slope | y − y₁ = m(x − x₁) | you know a point and the slope | y − 2 = (4/3)(x − 1) |
| general | ax + by + c = 0 | comparing lines, distances | 4x − 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.
| Equation | Slope | y-intercept | x-intercept |
|---|---|---|---|
| y = 2x + 1 | 2 | 1 | −0.5 |
| y = −x + 3 | −1 | 3 | 3 |
| y = 0.5x − 2 | 0.5 | −2 | 4 |
| 3x + 4y − 12 = 0 | −3/4 | 3 | 4 |
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.
| Relationship | Condition | Example |
|---|---|---|
| parallel | m₁ = m₂ | y = 2x + 1 and y = 2x − 3 |
| perpendicular | m₁ · m₂ = −1 | 2 × (−1/2) = −1 |
| horizontal ⟂ vertical | special case | y = 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 | Line | Working | Distance |
|---|---|---|---|
| (3, 4) | 3x + 4y − 5 = 0 | |9 + 16 − 5| / 5 | 4 |
| (1, 3) | 2x − y − 3 = 0 | |2 − 3 − 3| / √5 | 1.79 |
| (3, 0) | x − y = 0 | |3| / √2 | 2.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².
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.
| Point | Left side | Compared with 9 | Position |
|---|---|---|---|
| (5, −1) | 9 + 0 = 9 | equal | on circle |
| (2, 2) | 0 + 9 = 9 | equal | on circle |
| (3, 0) | 1 + 1 = 2 | less | inside |
| (6, 2) | 16 + 9 = 25 | greater | outside |
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.
| Vertices | Working | Area |
|---|---|---|
| (0, 0), (4, 0), (0, 3) | ½ × 4 × 3 | 6 |
| (1, 1), (5, 2), (3, 6) | ½ |−4 + 25 − 3| | 9 |
| (1, 1), (3, 1), (1, 2) | ½ × 2 × 1 | 1 |
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.
| Transformation | Rule | New vertices | Area |
|---|---|---|---|
| original | none | (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.
| Name | Formula | Working | Value |
|---|---|---|---|
| Euclidean | √(Δx² + Δy²) | √(9 + 16) | 5 |
| Manhattan | |Δx| + |Δy| | 3 + 4 | 7 |
| Chebyshev | max(|Δx|, |Δy|) | max(3, 4) | 4 |
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.
| Rank | Point | Class | Distance |
|---|---|---|---|
| 1 | (5, 4) | blue | 1.00 |
| 2 | (5, 5) | blue | 1.41 |
| 3 | (4, 6) | blue | 2.00 |
| 4 | (2, 3) | red | 2.24 |
| 5 | (6.5, 3) | blue | 2.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.
| Point | Distance to (1, 1) | Distance to (9, 8) | Cluster |
|---|---|---|---|
| (1, 1) | 0.00 | 10.63 | 1 |
| (2, 2) | 1.41 | 9.22 | 1 |
| (1, 3) | 2.00 | 9.43 | 1 |
| (5, 4) | 5.00 | 5.66 | 1 |
| (6, 6) | 7.07 | 3.61 | 2 |
| (8, 7) | 9.22 | 1.41 | 2 |
| (9, 8) | 10.63 | 0.00 | 2 |
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.
| Vector u | Vector v | Cosine | Meaning |
|---|---|---|---|
| (1, 2) | (2, 4) | 1.00 | same direction |
| (3, 4) | (4, 3) | 0.96 | very similar |
| (1, 0) | (0, 1) | 0.00 | unrelated (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.
| Geometric idea | Machine learning use |
|---|---|
| distance between points | nearest neighbors, similarity search, clustering |
| midpoint / mean of points | k-means centers, averaging embeddings |
| line, plane, hyperplane | linear and logistic classifiers, SVMs |
| point-to-line distance | margin and confidence of a classifier |
| angle between vectors | cosine similarity for text and image embeddings |
| box overlap | object detection scoring (IoU) |
| transformations | image augmentation: rotate, scale, shift |
| walk along the slope | gradient descent |
11. Common mistakes
| Mistake | Wrong | Right |
|---|---|---|
| Swapping x and y | plotting (2, 3) as 3 across, 2 up | x first: 2 across, 3 up |
| Forgetting the square root | d = (3)² + (4)² = 25 | d = √(9 + 16) = 5 |
| Adding instead of averaging | midpoint (1, 2),(4, 6) = (5, 8) | (2.5, 4) |
| Slope upside down | m = Δx/Δy = 3/4 | m = Δy/Δx = 4/3 |
| Perpendicular slope sign | 2 → 1/2 | 2 → −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 = 9 | r² = 9, so r = 3 |
12. Practice problems
Try these before looking at the answers.
- Find the distance between (−1, 2) and (5, 10).
- Find the midpoint of (−3, 4) and (7, −2).
- Find the slope and equation of the line through (2, 1) and (6, 9).
- Write the equation of the line through (0, 5) that is perpendicular to y = 2x + 1.
- Write the equation of the circle with center (−1, 3) and radius 4.
- Is (2, 2) inside the circle x² + y² = 9?
- Find the area of the triangle (0, 0), (6, 0), (2, 5).
- A query point is (5, 5). Which is nearer by Euclidean distance: (2, 9) or (8, 1)?
Answers.
- √(6² + 8²) = 10.
- ((−3 + 7)/2, (4 − 2)/2) = (2, 1).
- m = (9 − 1)/(6 − 2) = 2; y − 1 = 2(x − 2), so y = 2x − 3.
- The slope is −1/2 and the intercept is 5, so y = −x/2 + 5.
- (x + 1)² + (y − 3)² = 16.
- 2² + 2² = 8 < 9, so yes, it is inside.
- ½ × 6 × 5 = 15 (base 6, height 5).
- 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.