TExcelTAD
Home › Basic Math & Pre-Algebra › The Coordinate Plane

The Coordinate Plane

The coordinate plane puts two number lines at right angles, so that every point on a flat surface gets an address made of two numbers. It is how we draw equations as pictures, and it is also how every screen, map and game world places things. This lesson covers plotting points, quadrants, distance, midpoints and a first look at straight lines.

Axes and ordered pairs

The horizontal number line is the x-axis and the vertical one is the y-axis. They cross at the origin (0,0)(0, 0). A point is written as an ordered pair (x,y)(x, y): first go xx steps right (or left if negative), then yy steps up (or down if negative).

Order matters: (2,5)(2, 5) and (5,2)(5, 2) are different points.

The axes cut the plane into four quadrants, numbered counter-clockwise from the top right:

Quadrant Sign of xx Sign of yy Example
I ++ ++ (3,2)(3, 2)
II −- ++ (−4,1)(-4, 1)
III −- −- (−2,−3)(-2, -3)
IV ++ −- (5,−1)(5, -1)

A point with a zero coordinate, such as (0,4)(0, 4) or (−3,0)(-3, 0), lies on an axis and belongs to no quadrant.

Plotting points and a line

Matplotlib draws the plane for us. Here are a few points and the line y=2x−1y = 2x - 1, built from a table of values (the same idea as evaluating an expression in Variables and Expressions):

python · try it yourself
import matplotlib.pyplot as plt

xs = [-2, -1, 0, 1, 2, 3]
ys = [2 * x - 1 for x in xs]
print(list(zip(xs, ys)))

plt.figure(figsize=(6, 4))
plt.axhline(0, color="gray", lw=1)
plt.axvline(0, color="gray", lw=1)
plt.plot(xs, ys, "o-", label="y = 2x − 1")
for (px, py), name in [((3, 2), "A"), ((-4, 1), "B"), ((-2, -3), "C"), ((5, -1), "D")]:
    plt.plot(px, py, "s", color="tab:red")
    plt.annotate(f"{name}({px}, {py})", (px, py), textcoords="offset points", xytext=(5, 5))
plt.grid(True, alpha=0.3)
plt.legend()
plt.title("Points and a line on the coordinate plane")
[(-2, -5), (-1, -3), (0, -1), (1, 1), (2, 3), (3, 5)]

Slope and intercept

Each step of 1 to the right on the line above raises yy by 2. That rate is the slope mm. Between any two points:

m=riserun=y2−y1x2−x1m = \frac{\text{rise}}{\text{run}} = \frac{y_2 - y_1}{x_2 - x_1}

A line can be written as y=mx+by = mx + b, where bb is the y-intercept, the yy value where the line crosses the y-axis (x=0x = 0). For y=2x−1y = 2x - 1, m=2m = 2 and b=−1b = -1. A positive slope rises to the right, a negative slope falls, and slope 0 is a flat line. A vertical line has no slope, because its run is 0.

Distance and midpoint

The horizontal and vertical gaps between two points form the legs of a right triangle, so the Pythagorean theorem gives the straight-line distance:

d=(x2−x1)2+(y2−y1)2midpoint=(x1+x22,y1+y22)\begin{aligned} d &= \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} \\ \text{midpoint} &= \left(\frac{x_1 + x_2}{2}, \frac{y_1 + y_2}{2}\right) \end{aligned}

From A(1,2)A(1, 2) to B(7,10)B(7, 10): the gaps are 6 and 8, so d=36+64=100=10d = \sqrt{36 + 64} = \sqrt{100} = 10, and the midpoint is (4,6)(4, 6).

python · try it yourself
import math

def distance(p, q):
    return math.hypot(q[0] - p[0], q[1] - p[1])

def midpoint(p, q):
    return ((p[0] + q[0]) / 2, (p[1] + q[1]) / 2)

def slope(p, q):
    return (q[1] - p[1]) / (q[0] - p[0])

A, B = (1, 2), (7, 10)
print("distance:", distance(A, B))
print("midpoint:", midpoint(A, B))
print("slope:", round(slope(A, B), 4))
distance: 10.0
midpoint: (4.0, 6.0)
slope: 1.3333

In software

  • Screens are coordinate planes with y flipped. In HTML canvas, CSS, SVG and most 2D game frameworks, (0,0)(0, 0) is the top-left corner and yy grows downward. Converting a math point to a screen pixel means screen_y=height−y\text{screen\_y} = \text{height} - y (or a full mapping, see Screen Space).
  • Game worlds and maps store positions as (x,y)(x, y) pairs or vectors (see Vectors). Distance checks such as "is the enemy within 5 units?" use the formula above.
  • Charts in dashboards, Matplotlib and spreadsheets map data values to plane coordinates.
  • In machine learning, each data row is a point. With two features it is a point in the plane, and a classifier draws a line between groups.
python · try it yourself
W, H = 800, 600

def to_screen(x, y, scale=50):
    # math origin in the centre of the canvas, y up -> pixels with y down
    return (W / 2 + x * scale, H / 2 - y * scale)

for p in [(0, 0), (2, 3), (-4, -1)]:
    print(p, "->", to_screen(*p))
(0, 0) -> (400.0, 300.0)
(2, 3) -> (500.0, 150.0)
(-4, -1) -> (200.0, 350.0)

Exercises

Exercise 1: Which quadrant?

Name the quadrant (or axis) of each point: (−7,3)(-7, 3), (4,−4)(4, -4), (0,−2)(0, -2), (−1,−9)(-1, -9).

Answer

II, IV, on the y-axis, III.

Solution

Look only at the signs:

text
(−7, 3)   x −, y +   → II
(4, −4)   x +, y −   → IV
(0, −2)   x = 0      → on the y-axis (no quadrant)
(−1, −9)  x −, y −   → III

Exercise 2: Distance and midpoint

Find the distance and the midpoint between P(−2,1)P(-2, 1) and Q(10,6)Q(10, 6).

Answer

Distance 13, midpoint (4,3.5)(4, 3.5).

Solution
gaps: 10−(−2)=12,6−1=5d=122+52=144+25=169=13midpoint=(−2+102,1+62)=(4,3.5)\begin{aligned} \text{gaps: } & 10 - (-2) = 12,\quad 6 - 1 = 5 \\ d &= \sqrt{12^2 + 5^2} = \sqrt{144 + 25} = \sqrt{169} = 13 \\ \text{midpoint} &= \left(\frac{-2 + 10}{2}, \frac{1 + 6}{2}\right) = (4, 3.5) \end{aligned}
python · try it yourself
import math
print(math.hypot(10 - (-2), 6 - 1), ((-2 + 10) / 2, (1 + 6) / 2))
13.0 (4.0, 3.5)

Exercise 3: Line through two points

Find the equation y=mx+by = mx + b of the line through (1,4)(1, 4) and (3,10)(3, 10). Where does it cross the x-axis?

Answer

y=3x+1y = 3x + 1; it crosses the x-axis at (−13,0)\left(-\frac{1}{3}, 0\right).

Solution
m=10−43−1=62=3use (1,4):4=3⋅1+b ⇒ b=1y=3x+1x-axis means y=0:0=3x+1 ⇒ x=−13\begin{aligned} &m = \frac{10 - 4}{3 - 1} = \frac{6}{2} = 3 \\ &\text{use } (1, 4){:}\quad 4 = 3 \cdot 1 + b \ \Rightarrow\ b = 1 \\ &y = 3x + 1 \\ &\text{x-axis means } y = 0{:}\quad 0 = 3x + 1 \ \Rightarrow\ x = -\tfrac{1}{3} \end{aligned}

Exercise 4: Flip to the screen

A 400×300400 \times 300 canvas puts the math origin at its bottom-left corner, with 1 unit=1 pixel1\ \text{unit} = 1\ \text{pixel}. Write to_screen(x, y) returning pixel coordinates (yy down from the top) and convert (0,0)(0, 0), (400,300)(400, 300) and (100,50)(100, 50).

Answer

(0,300)(0, 300), (400,0)(400, 0), (100,250)(100, 250).

Solution

xx is unchanged. The math yy counts up from the bottom while the pixel yy counts down from the top, so screen_y=300−y\text{screen\_y} = 300 - y.

python · try it yourself
def to_screen(x, y, h=300):
    return (x, h - y)

print(to_screen(0, 0), to_screen(400, 300), to_screen(100, 50))
(0, 300) (400, 0) (100, 250)

Test yourself

In which quadrant is the point (−3,−8)(-3, -8)?

  1. I
  2. II
  3. III
  4. IV

What is the slope of the line through (2,7)(2, 7) and (6,−1)(6, -1)?

  1. 2
  2. −2
  3. −12-\frac{1}{2}
  4. 84\frac{8}{4}

On an HTML canvas, what happens to a point's pixel yy when the object moves up the screen?

  1. It increases
  2. It decreases
  3. It stays the same
  4. It becomes negative