OOP Meets Algebra,
|
Three quaternions, paired with their inverses, apply to each of the cube's 8 corners, causing a 1 degree/cycle rotation around each of the three orthogonal axes (x,y and z). Then the code projects these points to a flat surface (the screen) and paints the 12 connecting edges. Check boxes control which of the 3 quaternion "rotors" get applied. |
Here's some of the Java: public class Cubist extends Artist { // I'm a Cubist. I live inside a Studio object as an Artist, // and I know something about Quaternions (at least I hope I do) double cube [ ][ ]; Quaternion qx, qy, qz, qxinv, qyinv, qzinv; boolean xrotor, yrotor, zrotor; Cubist(){ // my Constructor -- I set out these tools as soon as you // create me as an object noPoints = 8; s1 = new int[noPoints][2]; // screen coordinates for cube cube = new double[noPoints][3]; // array for cube points refcube(); // initialize the cube qx = new Quaternion("X",1); // rotate 1 degree around X qy = new Quaternion("Y",1); // rotate 1 degree around Y qz = new Quaternion("Z",1); // rotate 1 degree around Z // I need the inverse of each of the above -- Quaternions // know how to return their own inverses qxinv = qx.inv(); qyinv = qy.inv(); qzinv = qz.inv(); xrotor = true; yrotor = true; zrotor = true; } public void rotateCube() { for ( int i=0; i<8; i++ ) { // I'm getting the vector part after rotating each // cube corner i.e. c = (q c q^-1).vector if (xrotor) cube[i] = qx.mult(cube[i]).mult(qxinv).vector; if (yrotor) cube[i] = qy.mult(cube[i]).mult(qyinv).vector; if (zrotor) cube[i] = qz.mult(cube[i]).mult(qzinv).vector; } } The process cycles at high speed within a Flipbook, thanks to the quick work of a Studio-resident quanternion-savvy Cubist (a subclass of Artist) -- more Java objects which I dreamed up for this paper (and plan to reuse in other projects). In sum, the OOP model has the effect of "stuffing more operational intelligence into the objects themselves" (in this case quaternions), by defining the methods internally, in contrast to having us conceptualize operations as "outside" or "independent of" the entities in question. Again, the OOP paradigm is potentially imparting a "new spin" to our pre-OOP algebraic concepts. These effects may be subtle, but I suspect are quite real and, over the long haul, will probably make quite a difference, both in our pedagogical approach to the material, and in the shape of innovations to come. For further reading:
Return to Topics for Exploration
|