TExcelTAD
Home › Calculus in Depth › Three-Dimensional Coordinate Systems

Three-Dimensional Coordinate Systems

Multivariable calculus lives in space, so it starts with a way to name every point of space by three numbers. This lesson sets up R3\mathbb{R}^3 precisely: the axes and their orientation, coordinate planes and octants, the distance formula, and the equation of a sphere. It is the ground floor for vectors, lines, planes and surfaces.

Axes, planes and octants

Pick an origin OO and three mutually perpendicular number lines through it, the xx-, yy- and zz-axes. A point PP is then the ordered triple (a,b,c)(a, b, c) of its signed distances along them. The set of all triples is

R3=R×R×R={(x,y,z):x,y,z∈R}\mathbb{R}^3 = \mathbb{R} \times \mathbb{R} \times \mathbb{R} = \{(x, y, z) : x, y, z \in \mathbb{R}\}

The axes are arranged by the right-hand rule: curl the fingers of your right hand from the positive xx-axis toward the positive yy-axis; your thumb points along the positive zz-axis. A left-handed system (zz flipped) is just as valid as geometry, but every formula that involves orientation, above all the cross product, changes sign.

Each pair of axes spans a coordinate plane:

Plane Equation Contains
xyxy-plane z=0z = 0 xx- and yy-axes
yzyz-plane x=0x = 0 yy- and zz-axes
xzxz-plane y=0y = 0 xx- and zz-axes

The three planes cut space into eight octants. The first octant is where x,y,z>0x, y, z > 0; the others have no standard numbering.

Note: An equation describes different sets in different dimensions. In R2\mathbb{R}^2, y=3y = 3 is a line. In R3\mathbb{R}^3, y=3y = 3 is the whole plane parallel to the xzxz-plane, because xx and zz are free. Always ask "which space am I in?"

Projections

The projection of P(a,b,c)P(a, b, c) onto the xyxy-plane is (a,b,0)(a, b, 0), onto the yzyz-plane (0,b,c)(0, b, c), and onto the xzxz-plane (a,0,c)(a, 0, c). Projection drops one coordinate. It is how 3D data becomes a 2D shadow, and how a top-down minimap is drawn from a 3D level.

The distance formula

Theorem. The distance between P1(x1,y1,z1)P_1(x_1, y_1, z_1) and P2(x2,y2,z2)P_2(x_2, y_2, z_2) is

∣P1P2∣=(x2−x1)2+(y2−y1)2+(z2−z1)2\lvert P_1P_2 \rvert = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}

Proof sketch. Build a box with P1P_1 and P2P_2 at opposite corners and edges parallel to the axes. Let AA be the corner that shares zz with P1P_1 but has the xx and yy of P2P_2. In the horizontal face, the Pythagorean theorem gives ∣P1A∣2=(x2−x1)2+(y2−y1)2\lvert P_1A \rvert^2 = (x_2 - x_1)^2 + (y_2 - y_1)^2. The segment AP2AP_2 is vertical with length ∣z2−z1∣\lvert z_2 - z_1 \rvert, and triangle P1AP2P_1AP_2 has a right angle at AA. Apply Pythagoras once more: ∣P1P2∣2=∣P1A∣2+∣AP2∣2\lvert P_1P_2 \rvert^2 = \lvert P_1A \rvert^2 + \lvert AP_2 \rvert^2. ∎

The midpoint of P1P2P_1P_2 is ((x1+x2)/2,(y1+y2)/2,(z1+z2)/2)((x_1 + x_2)/2, (y_1 + y_2)/2, (z_1 + z_2)/2), the coordinate-wise average.

python · try it yourself
import math

def dist(p, q):
    return math.sqrt(sum((b - a) ** 2 for a, b in zip(p, q)))

P1, P2 = (1, -2, 4), (7, 1, 2)
A = (P2[0], P2[1], P1[2])                    # box corner used in the proof
print("|P1A| =", dist(P1, A), "  |AP2| =", dist(A, P2))
print("Pythagoras:", math.hypot(dist(P1, A), dist(A, P2)))
print("direct    :", dist(P1, P2))
print("math.dist :", math.dist(P1, P2))
print("midpoint  :", tuple((a + b) / 2 for a, b in zip(P1, P2)))
|P1A| = 6.708203932499369   |AP2| = 2.0
Pythagoras: 7.0
direct    : 7.0
math.dist : 7.0
midpoint  : (4.0, -0.5, 3.0)

The differences (6,3,−2)(6, 3, -2) satisfy 36+9+4=4936 + 9 + 4 = 49, so the distance is exactly 7.

Spheres

A sphere is the set of points at fixed distance rr from a centre C(h,k,l)C(h, k, l). Squaring the distance formula gives its equation:

(x−h)2+(y−k)2+(z−l)2=r2(x - h)^2 + (y - k)^2 + (z - l)^2 = r^2

Given an expanded equation such as x2+y2+z2+Dx+Ey+Fz+G=0x^2 + y^2 + z^2 + Dx + Ey + Fz + G = 0, complete the square in each variable. The result is a sphere when the right-hand side is positive, a single point when it is zero, and the empty set when it is negative.

python · try it yourself
import sympy as sp

x, y, z = sp.symbols("x y z", real=True)
expr = x**2 + y**2 + z**2 - 6*x + 2*y - 10*z + 19

# complete the square: x² + Dx = (x + D/2)² − D²/4
D, E, F = -6, 2, -10
h, k, l = sp.Rational(-D, 2), sp.Rational(-E, 2), sp.Rational(-F, 2)
r2 = h**2 + k**2 + l**2 - 19
print("centre:", (h, k, l), " r^2 =", r2, " r =", sp.sqrt(r2))
check = (x - h)**2 + (y - k)**2 + (z - l)**2 - r2
print("same polynomial:", sp.expand(check - expr) == 0)
centre: (3, -1, 5)  r^2 = 16  r = 4
same polynomial: True

Inequalities describe solids: (x−3)2+(y+1)2+(z−5)2≤16(x - 3)^2 + (y + 1)^2 + (z - 5)^2 \le 16 is the solid ball, and 1≤x2+y2+z2≤41 \le x^2 + y^2 + z^2 \le 4 is a spherical shell between radii 1 and 2.

In software

  • Handedness. OpenGL, Three.js and most maths texts use right-handed coordinates; Unity and DirectX's traditional conventions are left-handed, and Unreal and Blender put zz up. Importing a model between tools often needs one axis negated. See Handedness and engine conventions.
  • Distance checks. Games compare squared distances (no square root) for "is the enemy within 10 m?": d2≤100d^2 \le 100. Bounding spheres, a centre plus a radius, are the cheapest broad-phase collision test (Circles and Spheres).
  • Spatial data. Point clouds from LIDAR, molecular coordinates and k-nearest-neighbour search all start from the 3D (or n-D) distance formula.

For a gentler first look at coordinates and vectors, see Vectors.

Exercises

Exercise 1: Which set is it?

Describe in words the set of points in R3\mathbb{R}^3 satisfying (a) x=−2x = -2, (b) y=0y = 0 and z=0z = 0, (c) x2+z2=9x^2 + z^2 = 9.

Answer

(a) A plane parallel to the yzyz-plane, 2 units behind it. (b) The xx-axis. (c) A circular cylinder of radius 3 around the yy-axis.

Solution

(a) Only xx is fixed; yy and zz are free, so it is a plane perpendicular to the xx-axis through (−2,0,0)(-2, 0, 0). (b) Two conditions fix yy and zz; only xx varies, which gives the xx-axis. (c) In every plane y=constanty = \text{constant}, the points satisfy x2+z2=9x^2 + z^2 = 9, a circle of radius 3 centred on the yy-axis. Stacking these circles for all yy gives a cylinder.

Exercise 2: Is the triangle right-angled?

Show that A(2,0,1)A(2, 0, 1), B(4,3,1)B(4, 3, 1), C(5,−2,5)C(5, -2, 5) form a right triangle, and find the vertex with the right angle.

Answer

∣AB∣2=13\lvert AB \rvert^2 = 13, ∣AC∣2=29\lvert AC \rvert^2 = 29, ∣BC∣2=42=13+29\lvert BC \rvert^2 = 42 = 13 + 29, so the right angle is at AA.

Solution

By the converse of Pythagoras, the triangle is right-angled exactly when the largest squared side equals the sum of the other two.

python · try it yourself
A, B, C = (2, 0, 1), (4, 3, 1), (5, -2, 5)
d2 = lambda p, q: sum((b - a) ** 2 for a, b in zip(p, q))
ab, bc, ac = d2(A, B), d2(B, C), d2(A, C)
print("AB^2 =", ab, " BC^2 =", bc, " AC^2 =", ac)
print("right angle at A:", ab + ac == bc)
print("right angle at B:", ab + bc == ac)
print("right angle at C:", bc + ac == ab)
AB^2 = 13  BC^2 = 42  AC^2 = 29
right angle at A: True
right angle at B: False
right angle at C: False

Exercise 3: Sphere from a diameter

Find the equation of the sphere that has the segment from (−1,2,5)(-1, 2, 5) to (3,6,−1)(3, 6, -1) as a diameter.

Answer

(x−1)2+(y−4)2+(z−2)2=17(x - 1)^2 + (y - 4)^2 + (z - 2)^2 = 17

Solution
centre=midpoint=(−1+32,2+62,5−12)=(1,4,2)diameter2=42+42+(−6)2=68r2=68/4=17\begin{aligned} \text{centre} &= \text{midpoint} = \left(\frac{-1+3}{2}, \frac{2+6}{2}, \frac{5-1}{2}\right) = (1, 4, 2) \\ \text{diameter}^2 &= 4^2 + 4^2 + (-6)^2 = 68 \\ r^2 &= 68/4 = 17 \end{aligned}

Exercise 4: Point, sphere or nothing? (code)

Write a function that takes D,E,F,GD, E, F, G from x2+y2+z2+Dx+Ey+Fz+G=0x^2 + y^2 + z^2 + Dx + Ey + Fz + G = 0 and reports "sphere", "point" or "empty" along with the centre. Test it on (2,−4,6,14)(2, -4, 6, 14), (2,−4,6,20)(2, -4, 6, 20) and (0,0,8,−9)(0, 0, 8, -9).

Answer

(2,−4,6,14)(2, -4, 6, 14): point at (−1,2,−3)(-1, 2, -3). (2,−4,6,20)(2, -4, 6, 20): empty. (0,0,8,−9)(0, 0, 8, -9): sphere centre (0,0,−4)(0, 0, -4), radius 5.

Solution

Completing the square gives r2=(D2+E2+F2)/4−Gr^2 = (D^2 + E^2 + F^2)/4 - G.

python · try it yourself
from fractions import Fraction as Fr

def classify(D, E, F, G):
    c = (Fr(-D, 2), Fr(-E, 2), Fr(-F, 2))
    r2 = Fr(D * D + E * E + F * F, 4) - G
    kind = "sphere" if r2 > 0 else "point" if r2 == 0 else "empty"
    return kind, tuple(str(v) for v in c), str(r2)

for coeffs in [(2, -4, 6, 14), (2, -4, 6, 20), (0, 0, 8, -9)]:
    print(coeffs, "->", classify(*coeffs))
(2, -4, 6, 14) -> ('point', ('-1', '2', '-3'), '0')
(2, -4, 6, 20) -> ('empty', ('-1', '2', '-3'), '-6')
(0, 0, 8, -9) -> ('sphere', ('0', '0', '-4'), '25')

Test yourself

In R3\mathbb{R}^3, what is the set z=4z = 4?

  1. A line parallel to the zz-axis
  2. A point
  3. A plane parallel to the xyxy-plane
  4. A sphere of radius 4

What is the distance from (1,2,3)(1, 2, 3) to (3,5,9)(3, 5, 9)?

  1. 7
  2. 13\sqrt{13}
  3. 11
  4. 49

x2+y2+z2−4z=0x^2 + y^2 + z^2 - 4z = 0 describes…

  1. the empty set
  2. a sphere centred at the origin
  3. a single point
  4. a sphere of radius 2 centred at (0,0,2)(0, 0, 2)