## Thursday, December 29, 2016

### Quaternions

A segue from Kenneth's atoms' rotations, patterns no doubt studied in Group Theory (not a physical science), would be to Quaternions, a mathematical device used to drive spatial transformations by iteration, much as rotation matrices get used.

A rotation matrix, recall, is an XY array of numbers set to "multiply" (__matmul__ in Python) with another matrix after it.  They don't necessarily commute (switched around, you get a different answer).  That "other matrix" may also be a target vector, where the rotation matrix is "pre-loaded" with just the right numbers to re-point it in a different direction.

A quaternion is a vector on steroids with more moving parts.  They'll multiply, much as complex numbers do in a plane (a flat surface), and thereby "spin" or "rotate" all the ways an avatar would need to, in a computer game.  They'll get the same work done as rotation matrices, but perhaps in a more elegant manner, using fewer lines of code?

These were the early days of the World Wide Web (1990s) and I'm chugging along reading about how game engines get built, and I find out some game-makers are using Quaternions to power their physics engines, and claiming to get faster frame rates, smoother performance, as a consequence.  "That's cool", I'm thinking, "as now I'll have running source code versions."

I like to "make math" not just read about it, and coding languages let me do that. Scott Gray, my future boss, had come to a similar conclusion using Mathematica (or Wolfram Language): some people learn better when they get to "make" or do "hands-on".

In this chapter, when the Web was young, the Java applet, embedded in your browser, run by the Java engine you'd have downloaded, was expected to be the king of the hill on the client side.  JavaScript, in contrast, was hardly taken seriously.  People would monkey around with it waiting for Java to assume its throne, but it never did.  JavaScript ended up taking a lot more responsibility.

The technology is still out there and serviceable though.  Java remains very important, even if the applet genre didn't take off.  Ahead of its time?  Remember a "headless browser" is just another thick client on your platform, and many of your smartphones are JVM devices, the ARM architecture having a native mode for its bytecodes.  I'm glad we have lots of talented coders ready to embrace those skills with open arms.  Python and Java are more synergetic than pitted against one another.

This other essay, which I'd tweeted about earlier, embeds the same Java applet, the quaternions cube, but is really more about the Python code I was then developing, to get on with my work in curriculum writing.  I ended up with a four-part series.

Now remember not to confuse "quaternions" with "quadrays" (same "qua" or "kwah" sound). The "quadays" are the four vectors from (0, 0, 0, 0) with the topology of a methane molecule (a central Carbon and four Hydrogens).  Linear combinations of these four vectors reach (span) all surrounding space with unique, canonical, non-negative four-tuple addresses. Rotation matrices apply. A variant addressing scheme balances negatives with positives in "sum to zero" format.