TExcelTAD
Home › Algebra › Coordinate Systems

Coordinate Systems

A coordinate system gives every point a numeric address, so geometry turns into algebra: a point becomes a pair of numbers, a line or curve becomes an equation, and "where do they meet?" becomes "solve the system". This lesson reviews the Cartesian plane, extends it to three dimensions, and explains why computer screens put the origin in the top-left corner with yy pointing down.

The Cartesian plane

Two number lines cross at right angles at the origin OO. The horizontal one is the xx-axis, the vertical one the yy-axis. A point is written as an ordered pair (x,y)(x, y): first how far to walk right (negative: left), then how far up (negative: down). Order matters: (2,5)(2, 5) and (5,2)(5, 2) are different points.

The axes split the plane into four quadrants, numbered counter-clockwise starting 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 ++ −- (2,−2)(2, -2)

Points with x=0x = 0 lie on the yy-axis and points with y=0y = 0 lie on the xx-axis; they belong to no quadrant. The coordinate plane lesson in Basic Math has a gentler introduction.

python · try it yourself
import matplotlib.pyplot as plt

points = {"A": (3, 2), "B": (-4, 1), "C": (-2, -3), "D": (2, -2), "E": (0, 3)}

plt.figure(figsize=(5, 5))
plt.axhline(0, color="black", linewidth=1)
plt.axvline(0, color="black", linewidth=1)
for name, (x, y) in points.items():
    plt.plot(x, y, "o", color="tab:blue")
    plt.annotate(f"{name}({x}, {y})", (x, y), textcoords="offset points", xytext=(6, 6))
for label, pos in {"I": (4, 4), "II": (-4, 4), "III": (-4, -4), "IV": (4, -4)}.items():
    plt.text(*pos, label, fontsize=14, color="gray", ha="center")
plt.xlim(-5, 5); plt.ylim(-5, 5)
plt.grid(True, alpha=0.3)
plt.gca().set_aspect("equal")
plt.title("Points and quadrants")
plt.show()
print("plotted", len(points), "points")
plotted 5 points

Distance and midpoint

Two formulas turn geometric questions into arithmetic. Both come from the coordinates alone:

distance:d=(x2−x1)2+(y2−y1)2(the Pythagorean theorem)midpoint:M=(x1+x22,y1+y22)(the average of the coordinates)\begin{aligned} \text{distance:} &\quad d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} && \text{(the Pythagorean theorem)} \\ \text{midpoint:} &\quad M = \left(\frac{x_1 + x_2}{2}, \frac{y_1 + y_2}{2}\right) && \text{(the average of the coordinates)} \end{aligned}

For A(3,2)A(3, 2) and C(−2,−3)C(-2, -3): the gaps are 5 and 5, so d=50=52≈7.07d = \sqrt{50} = 5\sqrt{2} \approx 7.07, and M=(0.5,−0.5)M = (0.5, -0.5). The distance formula is the Pythagorean theorem applied to the horizontal and vertical gaps.

Three dimensions

Add a third axis, zz, at right angles to the other two, and every point in space gets an address (x,y,z)(x, y, z). The distance formula gains one more term: d=Δx2+Δy2+Δz2d = \sqrt{\Delta x^2 + \Delta y^2 + \Delta z^2}. In maths and in most 3D tools the axes are right-handed: point the right hand's fingers along xx, curl them toward yy, and the thumb points along zz. Some engines use left-handed axes instead; Handedness in the game-math course compares them.

Other coordinate systems describe the same plane differently. Polar coordinates give a point as a distance rr from the origin and an angle θ\theta; they suit circles and rotations and are covered in Pre-Calculus.

In software: screen coordinates

On a computer screen, a canvas or an image, the origin is the top-left corner, xx grows to the right and yy grows downward, measured in pixels. That is because screens are drawn row by row from the top, like reading text.

Maths coordinates Screen coordinates
origin centre (wherever you choose) top-left corner
yy direction up down
units any real number pixels (whole numbers)
a "counter-clockwise" turn positive angle looks clockwise on screen

To draw a maths graph on screen you map each point. Suppose the graph shows xx from −10 to 10 and yy from −5 to 5 on an 800 × 400 canvas:

px=x−xmin⁡xmax⁡−xmin⁡⋅width=x+1020⋅800py=ymax⁡−yymax⁡−ymin⁡⋅height=5−y10⋅400\begin{aligned} p_x &= \frac{x - x_{\min}}{x_{\max} - x_{\min}} \cdot \text{width} = \frac{x + 10}{20} \cdot 800 \\[1ex] p_y &= \frac{y_{\max} - y}{y_{\max} - y_{\min}} \cdot \text{height} = \frac{5 - y}{10} \cdot 400 \end{aligned}

The ymax⁡−yy_{\max} - y (instead of y−ymin⁡y - y_{\min}) is the flip: a large yy gives a small pyp_y, near the top.

python · try it yourself
def to_screen(x, y, xmin=-10, xmax=10, ymin=-5, ymax=5, width=800, height=400):
    px = (x - xmin) / (xmax - xmin) * width
    py = (ymax - y) / (ymax - ymin) * height      # flip: y up -> py down
    return round(px), round(py)

def to_math(px, py, xmin=-10, xmax=10, ymin=-5, ymax=5, width=800, height=400):
    x = xmin + px / width * (xmax - xmin)
    y = ymax - py / height * (ymax - ymin)
    return x, y

for p in [(0, 0), (10, 5), (-10, -5), (3, 2)]:
    print(p, "->", to_screen(*p))
print("mouse click at (600, 100) is", to_math(600, 100))
(0, 0) -> (400, 200)
(10, 5) -> (800, 0)
(-10, -5) -> (0, 400)
(3, 2) -> (520, 120)
mouse click at (600, 100) is (5.0, 2.5)

to_math is the inverse map, used when the user clicks: it turns a pixel back into graph coordinates. Charting libraries, map widgets and game cameras all contain these two functions. In 3D graphics the same idea appears as the last stage of the pipeline, from normalised device coordinates to pixels (Clip Space, NDC and Screen).

Tip: When a sprite moves "up" but your code adds to yy, it moves down the screen. Decide once which system a variable lives in, and convert only at the drawing step.

Exercises

Exercise 1: Quadrants

Name the quadrant or axis of (−6,2)(-6, 2), (5,−1)(5, -1), (0,4)(0, 4) and (−3,−3)(-3, -3).

Answer

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

Solution
(−6,2):x −, y +→II(5,−1):x +, y −→IV(0,4):x=0→on the positive y-axis(−3,−3):x −, y −→III\begin{aligned} (-6, 2)&: \quad x\ {-},\ y\ {+} && \to \text{II} \\ (5, -1)&: \quad x\ {+},\ y\ {-} && \to \text{IV} \\ (0, 4)&: \quad x = 0 && \to \text{on the positive } y\text{-axis} \\ (-3, -3)&: \quad x\ {-},\ y\ {-} && \to \text{III} \end{aligned}

Exercise 2: Distance and midpoint

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

Answer

d=10d = 10, M=(2,6)M = (2, 6).

Solution
gaps: 5−(−1)=6, 10−2=8d=36+64=100=10M=(−1+52,2+102)=(2,6)\begin{aligned} &\text{gaps: } 5 - (-1) = 6,\ 10 - 2 = 8 \\ &d = \sqrt{36 + 64} = \sqrt{100} = 10 \\ &M = \left(\frac{-1 + 5}{2}, \frac{2 + 10}{2}\right) = (2, 6) \end{aligned}
python · try it yourself
import math
print(math.dist((-1, 2), (5, 10)), ((-1 + 5) / 2, (2 + 10) / 2))
10.0 (2.0, 6.0)

Exercise 3: A 3D distance

How far apart are (1,2,3)(1, 2, 3) and (3,5,9)(3, 5, 9)?

Answer
Solution
Δx=2, Δy=3, Δz=6d=4+9+36=49=7\begin{aligned} &\Delta x = 2,\ \Delta y = 3,\ \Delta z = 6 \\ &d = \sqrt{4 + 9 + 36} = \sqrt{49} = 7 \end{aligned}

Exercise 4: Map to a screen

A chart shows xx from 0 to 100 and yy from 0 to 50 on a 500 × 250 pixel canvas (yy down). Where is the data point (40,30)(40, 30) drawn? Which data point is at pixel (250,250)(250, 250)?

Answer

(40,30)(40, 30) is drawn at pixel (200,100)(200, 100); pixel (250,250)(250, 250) is the data point (50,0)(50, 0).

Solution
px=40−0100⋅500=200py=50−3050⋅250=100inverse:x=0+250500⋅100=50,y=50−250250⋅50=0\begin{aligned} p_x &= \frac{40 - 0}{100} \cdot 500 = 200 \\[1ex] p_y &= \frac{50 - 30}{50} \cdot 250 = 100 \\[1ex] \text{inverse:} &\quad x = 0 + \frac{250}{500} \cdot 100 = 50,\quad y = 50 - \frac{250}{250} \cdot 50 = 0 \end{aligned}
python · try it yourself
def to_screen(x, y):
    return x / 100 * 500, (50 - y) / 50 * 250
def to_data(px, py):
    return px / 500 * 100, 50 - py / 250 * 50
print(to_screen(40, 30), to_data(250, 250))
(200.0, 100.0) (50.0, 0.0)

Test yourself

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

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

On a 600 px tall canvas that shows yy from 0 (bottom) to 10 (top), at which pixel row is y=10y = 10 drawn?

  1. 600
  2. 60
  3. 0
  4. 300

What is the distance between (0,0)(0, 0) and (6,8)(6, 8)?

  1. 14
  2. 10
  3. 48
  4. 14\sqrt{14}