Learning curves

Every so often I am struck by the huge gulf that can exist between “knowing what something does” and “knowing how to make something”. The tools that we rely on can be every simple to use, and yet extremely difficult to create and to understand under the hood.

For example, everybody gets what television does, but it takes specialized knowledge to understand how it really works, and even more specialized knowledge to build a working TV set. The same goes for automobiles, pianos, smartPhones, and all sorts of other modern tools that we take for granted.

This came home to me yesterday when I set out to do something for a computer graphics project that is very easy to describe: Given two curves, find out how much to move and scale one of the curves so that the two curves become superimposed on each other as close as possible.

To do that, you need to change the x,y and scale of one of the curves. All those possible x,y,scale values form a kind of parabolic dish, and the best answer is at the very bottom of the dish — the place where a marble would roll to if you dropped it into the dish.

But to turn that picture into math, and then into a computer program, took me several hours, and at the end of it I had a little piece of code that would make sense to very few people:

      var n = min(P.length, Q.length), a=0, b=0, c=0, d=0, e=0, f=0;
      for (var i = 0 ; i < n ; i++) {             var px = P[i][0], py = P[i][1], qx = Q[i][0], qy = Q[i][1];             a += px;             b += py;             c += qx;             d += qy;             e += px * px + py * py;             f += px * qx + py * qy;       }       return solve([ [n,0,a,c], [0,n,b,d], [a,b,e,f] ]);

Like most software, this relies on other software. For example, the last line calls a linear equation solver, which is a standard tool that I already had lying around.

Everything that is interesting — and maybe difficult to understand — about these dozen-odd lines of code is in how you convert a simple idea like “make two curves line up” into another simple idea like “find the bottom of a dish”, and then into mathematics. There isn’t anything interesting about the computer code itself.

Sometimes when I think that we should be teaching everyone to program, I look at code like this and I realize that the real power-up doesn’t come from learning programming, it comes from learning how to express ideas using math. And that’s a whole different thing.

Leave a Reply

Your email address will not be published. Required fields are marked *