From the handbook: Differentiation and Integration of Functions of Several Variables, §419–450, pages 626–662
Slope on a surface has a direction, and two numbers describe it.
Picture a map with a grid on it, like a street map. Any spot on the map can be named by two numbers: x, how far east it is, and y, how far north it is. These are the same two coordinates as on any graph.
Now give every spot a height. Call the height z. If you know where you are standing (x and y), the landscape tells you how high you are (z). Two numbers go in, one number comes out.
The thing that turns the two numbers into the height is called a function. Think of it as a rule, or a machine: feed it a position and it hands back a height. Mathematicians give the rule a short name, usually f, and write
z = f(x, y)
Read it aloud as “z is f of x and y”, meaning “the height is what the rule gives you for this position”. The letter f doesn't stand for a number. It stands for the rule itself.
A very simple example of a rule is f(x, y) = x + 2y. Standing at x = 3, y = 1, the height is 3 + 2 × 1 = 5. That rule makes a tilted flat ramp. The hills in this demo use more complicated rules, but the idea is the same. A real terrain file (a DEM in TopoToImage) is this kind of rule written out as a table: a grid of positions, each with its height.
Here the landscape is built the way a computer stores terrain: a grid of heights joined into flat triangles.
On a hillside, “how steep is it?” depends on which way you walk. Walking along the side of the hill may be level, while walking straight up it is steep. So one number isn't enough to describe slope on a surface. It takes two.
The east slope. Stand still, then take a small step due east. Your x changes, your y stays the same, and your height changes a little. Divide the change in height by the length of the step and you have the slope going east, the same rise over run as on a roof or a road sign. Mathematicians write it as
∂z / ∂x
Read it as “the change in z for a small change in x”. The curly ∂ is a rounded letter d, short for “a tiny difference in”. So ∂z/∂x is a tiny change in height divided by a tiny step east. It is called a partial derivative: “derivative” because it is a rate of change, “partial” because only one of the two inputs is allowed to change while the other is held fixed.
The north slope. Do the same thing walking due north: y changes, x stays the same. That slope is written ∂z/∂y.
Back to the ramp z = x + 2y. A step of 1 east raises you by 1, so its east slope is 1. A step of 1 north raises you by 2, so its north slope is 2. Climbing this ramp is twice as hard walking north as walking east.
A positive slope means uphill in that direction, a negative one means downhill, and zero means level. The blue and pink panels below the map show exactly these two walks through the orange point, with the slope of each.
Draw an arrow that goes as far east as the east slope and as far north as the north slope. For the ramp that is 1 east and 2 north. That arrow points in the steepest uphill direction, and its length tells you how steep it is there. On the map it is the orange arrow (scaled to fit), drawn from its blue east leg and its pink north leg. Its length comes from Pythagoras: for the ramp, √(1² + 2²) ≈ 2.24.
Turn it around and it points the way water runs: straight downhill. That is what the white arrows on every triangle show. On a flat triangle the slope is the same everywhere, so each triangle has one pair of slopes and one arrow.
Vygodsky, Mathematical Handbook: Higher Mathematics, chapter “Differentiation and Integration of Functions of Several Variables”.
The shading on the map is another big idea at work: each triangle's brightness is the dot product of its normal with the light direction (idea 2).