Thursday, April 24, 2008

Rotation

With vector vectoria Matt brings us from vectors to rotations, another vector quantity. Rotations play part in some of the deeper mysteries of physics. In OpenGL rotations determine the orientation of a graphical object. Here is a 3-D vector toy. The code is in the comments section. The patch has rotations going all over the place. Using a spherical coordinate system makes it possible to generate these rotations in q (theta) and f (phi). In the guts of the patch the orientation of the graphic arrow model is determined by using theta and phi as euler angles.

1 comment:

Tony said...

max v2;
#N vpatcher 235 44 654 345;
#P origin -19 31;
#P toggle 118 52 29 0;
#P window setfont "Sans Serif" 9.;
#P newex 118 90 29 196617 gate;
#P message 181 71 17 196617 1.;
#P newex 218 66 46 196617 / 1000.;
#N counter 0 6280;
#X flags 0 0;
#P newobj 218 44 80 196617 counter 0 6280;
#P newex 304 66 40 196617 / 100.;
#N counter 0 6280;
#X flags 0 0;
#P newobj 304 44 83 196617 counter 0 6280;
#P flonum 245 94 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N vpatcher 10 59 610 459;
#P outlet 291 128 15 0;
#P outlet 193 124 15 0;
#P outlet 55 119 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 193 84 96 196617 expr $f1*cos($f2);
#P newex 291 84 138 196617 expr $f1*sin($f2)*sin($f3);
#P newex 86 50 61 196617 pak 0. 0. 0.;
#P newex 50 83 140 196617 expr $f1*sin($f2)*cos($f3);
#P inlet 86 30 15 0;
#P inlet 114 30 15 0;
#P inlet 142 30 15 0;
#P connect 4 0 3 0;
#P connect 3 0 7 0;
#P connect 2 0 4 0;
#P connect 1 0 4 1;
#P connect 0 0 4 2;
#P connect 4 0 6 0;
#P connect 6 0 8 0;
#P connect 4 0 5 0;
#P connect 5 0 9 0;
#P pop;
#P newobj 186 120 129 196617 p sphere_to_cart;
#P flonum 304 94 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 186 94 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N vpatcher 10 59 702 495;
#P outlet 600 116 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 134 51 35 196617 sel 0.;
#P newex 89 50 35 196617 sel 0.;
#P message 413 121 37 196617 \$1 \$3;
#P newex 418 161 174 196617 expr atan($f2/$f1)+3.14*($f1 < 0);
#P newex 115 147 269 196617 expr atan(sqrt($f1*$f1+$f3*$f3)/$f2)+3.14*($f2 < 0);
#P newex 174 96 61 196617 pak 0. 0. 0.;
#P newex 50 122 190 196617 expr sqrt($f1*$f1+$f2*$f2+$f3*$f3);
#P inlet 134 31 15 0;
#P inlet 89 30 15 0;
#P inlet 224 76 15 0;
#P outlet 50 144 15 0;
#P outlet 115 169 15 0;
#P outlet 418 183 15 0;
#P connect 7 0 6 0;
#P connect 6 0 2 0;
#P connect 4 0 11 0;
#P connect 7 0 8 0;
#P connect 8 0 1 0;
#P connect 5 0 12 0;
#P connect 11 1 7 0;
#P connect 12 1 7 1;
#P connect 3 0 7 2;
#P connect 7 0 10 0;
#P connect 10 0 9 0;
#P connect 9 0 0 0;
#P connect 7 0 13 0;
#P pop;
#P newobj 186 183 128 196617 p cart_to_sphere;
#P flonum 304 160 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 245 160 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 186 160 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 264 221 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 225 221 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 186 221 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N vpatcher 477 276 1382 777;
#P origin 7 330;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P message 607 114 48 196617 2. 2. -2.;
#P newex 532 137 85 196617 vexpr $f1 * $f2;
#P message 529 210 227 196617 blend_enable 1 \, depth_enable 0 \, blend_mode 6 2;
#P window linecount 3;
#P message 504 160 310 196617 reset \, line_width 150 \, glcolor 0.7 0. 0. \, moveto 0. 0. 0. \, lineto \$1 0. 0. \, glcolor 0. 0.7 0. \, moveto 0. 0. 0. \, lineto 0. \$2 0. \, moveto 0. 0. 0. \, \, glcolor 0. 0. 0.7 \, moveto 0. 0. 0. \, lineto 0. 0. \$3;
#P window linecount 1;
#P newex 519 230 86 196617 jit.gl.sketch food;
#P inlet 491 123 15 0;
#P message 470 341 89 196617 lighting_enable 0;
#P newex 245 308 34 196617 * -1.;
#P newex 183 364 61 196617 pak 0. 0. 0.;
#P newex 418 221 34 196617 + 90.;
#P newex 376 223 33 196617 - 90.;
#P newex 425 170 41 196617 * 180.;
#P newex 425 146 40 196617 / 3.14;
#P newex 376 172 41 196617 * 180.;
#P newex 376 148 40 196617 / 3.14;
#P newex 231 239 66 196617 pack 0. 0. 0.;
#P newex 307 207 40 196617 + 0.25;
#P newex 280 180 29 196617 * 2.;
#P flonum 265 146 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 354 362 86 196617 jit.gl.sketch food;
#P window linecount 4;
#P message 382 283 318 196617 reset \, glenable cull_face \, glcullface back \, shapeslices 50 20 \, glcolor 0.4 0.4 0 \, moveto 0 0 \$1 \, cylinder 0.05 0.05 \$1 \, moveto 0 0 0 \, shapeorient 180 0 0 \, circle 0.1 \, glcolor 0 0 0 \, moveto 0 0 \$2 \, circle 0.2 \, moveto 0 0 \$3 \, shapeorient 0 0 0 \, cylinder 0 0.2 0.25;
#P flonum 414 197 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 377 197 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 344 254 109 196617 pak rotatexyz 0. 0. 0.;
#P hidden newex 1 58 48 196617 loadbang;
#P message 103 76 310 196617 blend_enable 0 \, depth_enable 1 \, blend_mode 6 1 \, lighting_enable 1;
#P window linecount 2;
#P message 86 44 399 196617 reset \, glcolor 0.5 0.5 0.5 \, shapeorient 0 90 0 \, cylinder 0.025 0.025 2.5 \, shapeorient 0 0 0 \, cylinder 0.025 0.025 2.5 \, shapeorient 90 0 0 \, cylinder 0.025 0.025 2.5;
#P window linecount 1;
#P newex 86 105 86 196617 jit.gl.sketch food;
#P inlet 425 122 15 0;
#P inlet 376 122 15 0;
#P inlet 265 124 15 0;
#P message 506 63 227 196617 blend_enable 1 \, depth_enable 1 \, blend_mode 6 1;
#P message 496 45 248 196617 reset \, glcolor 0.5 0.5 0.5 \, moveto 0 0 0 \, sphere 0.1;
#P newex 496 83 86 196617 jit.gl.sketch food;
#P hidden connect 9 0 7 0;
#P connect 8 0 6 0;
#P connect 7 0 6 0;
#P hidden connect 9 0 8 0;
#P connect 16 0 25 0;
#P connect 12 0 25 1;
#P fasten 15 0 18 0 270 217 236 217;
#P connect 26 0 25 2;
#P connect 23 0 26 0;
#P fasten 16 0 18 1 285 227 264 227;
#P connect 3 0 15 0;
#P fasten 15 0 16 0 270 171 285 171;
#P fasten 17 0 18 2 312 232 292 232;
#P fasten 16 0 17 0 285 200 312 200;
#P connect 10 0 14 0;
#P connect 13 0 14 0;
#P connect 27 0 14 0;
#P connect 4 0 19 0;
#P connect 19 0 20 0;
#P connect 11 0 23 0;
#P connect 20 0 11 0;
#P connect 23 0 10 1;
#P hidden connect 9 0 13 0;
#P connect 18 0 13 0;
#P connect 24 0 10 2;
#P connect 22 0 12 0;
#P connect 12 0 24 0;
#P connect 5 0 21 0;
#P connect 21 0 22 0;
#P hidden connect 9 0 1 0;
#P connect 1 0 0 0;
#P connect 2 0 0 0;
#P connect 9 0 30 0;
#P connect 32 0 30 0;
#P hidden connect 9 0 2 0;
#P connect 30 0 29 0;
#P connect 31 0 29 0;
#P connect 9 0 31 0;
#P connect 28 0 32 0;
#P connect 9 0 33 0;
#P connect 33 0 32 1;
#P pop;
#P newobj 186 241 129 196617 p sketch;
#P hidden message 112 182 70 196617 size 640 480;
#P hidden newex 39 164 50 196617 loadbang;
#P hidden message 114 150 70 196617 camera 2 4 4;
#P newex 15 213 152 196617 jit.window food @depthbuffer 1;
#P newex 15 87 43 196617 jit.qball;
#P number 60 38 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 15 38 15 0;
#P newex 15 64 57 196617 qmetro 20;
#P newex 15 118 50 196617 t b erase;
#P newex 15 193 87 196617 jit.gl.render food;
#P hidden connect 8 0 3 0;
#P connect 3 0 2 0;
#P connect 2 0 5 0;
#P connect 5 0 1 0;
#P hidden fasten 7 0 0 0 119 183 20 183;
#P connect 1 0 0 0;
#P fasten 1 1 0 0 38 142 20 142;
#P hidden connect 9 0 6 0;
#P connect 4 0 2 1;
#P hidden connect 8 0 9 0;
#P hidden connect 8 0 7 0;
#P hidden connect 8 0 28 0;
#P connect 28 0 27 0;
#P fasten 2 0 27 1 20 84 142 84;
#P hidden connect 8 0 26 0;
#P connect 26 0 18 0;
#P connect 18 0 20 0;
#P connect 20 0 14 0;
#P connect 14 0 17 0;
#P connect 17 0 11 0;
#P connect 11 0 10 0;
#P fasten 27 0 24 0 123 128 165 128 165 27 223 27;
#P connect 24 0 25 0;
#P connect 17 1 12 0;
#P connect 12 0 10 1;
#P connect 25 0 21 0;
#P connect 21 0 20 1;
#P connect 20 1 15 0;
#P connect 15 0 17 1;
#P connect 17 2 13 0;
#P connect 13 0 10 2;
#P connect 17 3 10 3;
#P fasten 27 0 22 0 123 128 165 128 165 27 309 27;
#P connect 22 0 23 0;
#P connect 23 0 19 0;
#P connect 19 0 20 2;
#P connect 20 2 16 0;
#P connect 16 0 17 2;
#P pop;