Tuesday, April 22, 2008

Cylindrical Coordinates

Cylindrical coordinates specify a point in 3-D with a mix of polar coordinates and cartesian. Polar coordinates use a distance and angle measure to locate points in 2-D. Cylindrical coordinates use an additional distance measure to locate points in 3-D. For this example r and f are two polar coordinates and y is the third. We can translate from cylindrical to 3-D cartesian coordinates using r and f to determine x and z and using y as it is given.
Here is a patch that lets you play with 3-D cylindrical coordinates. The code is in the comments section. Since it uses cartesian coordinates we translate from cylindrical to cartesian as we send messages to OpenGL.

1 comment:

Tony said...

max v2;
#N vpatcher 25 489 351 727;
#P origin -19 51;
#P window setfont "Sans Serif" 9.;
#P flonum 167 59 35 9 -2.5 2.5 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 18.;
#P comment 167 32 34 196626 y;
#P window setfont Symbol 20.;
#P comment 125 34 34 1507348 f;
#P window setfont "Sans Serif" 9.;
#P newex 124 78 29 196617 t b f;
#P newex 109 101 52 196617 poltocar;
#P flonum 124 58 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 85 58 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont Symbol 20.;
#P comment 86 35 34 1507348 r;
#P window setfont "Sans Serif" 9.;
#P flonum 206 149 35 9 -2.5 2.5 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 167 149 35 9 -2.5 2.5 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 128 149 35 9 -2.5 2.5 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 18.;
#P comment 212 118 34 196626 z;
#P comment 177 119 34 196626 y;
#P comment 140 119 34 196626 x;
#P window setfont "Sans Serif" 9.;
#N vpatcher 447 237 1148 769;
#P origin 7 326;
#P window setfont "Sans Serif" 9.;
#P message 54 313 69 196617 line_width \$1;
#P flonum 52 279 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 114 381 227 196617 blend_enable 1 \, depth_enable 1 \, blend_mode 6 1;
#P window linecount 2;
#P message 102 344 228 196617 reset \, glcolor 0. 0. 0.7 \, moveto 0. 0. 0. \, lineto 0. \$2 0. \, glcolor 0.7 0. 0. \, lineto \$1 \$2 \$3;
#P window linecount 1;
#P newex 104 401 86 196617 jit.gl.sketch food;
#P newex 563 242 40 196617 * 180.;
#P newex 563 221 63 196617 / 3.141593;
#P window linecount 0;
#P newex 535 300 32 196617 print;
#P window linecount 1;
#P newex 510 187 29 196617 t b f;
#P flonum 554 360 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 464 233 66 196617 pack 0. 0. 0.;
#P newex 470 160 29 196617 t b f;
#P newex 455 183 47 196617 cartopol;
#P message 389 422 227 196617 blend_enable 1 \, depth_enable 1 \, blend_mode 6 1;
#P message 379 404 366 196617 reset \, glcolor 0. 0.3 0. \, moveto 0. \$3 0. \, shapeorient 90 0 0 \, circle \$1 0. \$2;
#P newex 379 442 86 196617 jit.gl.sketch food;
#P window linecount 0;
#P hidden newex 1 62 48 196617 loadbang;
#P message 275 272 227 196617 blend_enable 1 \, depth_enable 1 \, blend_mode 6 1;
#P message 103 80 310 196617 blend_enable 0 \, depth_enable 1 \, blend_mode 6 1 \, lighting_enable 1;
#P window linecount 1;
#P newex 265 220 66 196617 pak 0. 0. 0.;
#P message 265 254 266 196617 reset \, glcolor 0.5 0.5 0.5 \, moveto \$1 \$2 \$3 \, sphere 0.1;
#P newex 265 292 86 196617 jit.gl.sketch food;
#P window linecount 2;
#P message 86 48 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 109 86 196617 jit.gl.sketch food;
#P inlet 321 189 15 0;
#P inlet 293 188 15 0;
#P inlet 265 188 15 0;
#P connect 25 0 26 0;
#P hidden connect 10 0 4 0;
#P connect 4 0 3 0;
#P connect 8 0 3 0;
#P connect 10 0 23 0;
#P connect 7 0 23 0;
#P hidden connect 10 0 8 0;
#P connect 26 0 22 0;
#P connect 23 0 22 0;
#P connect 24 0 22 0;
#P connect 10 0 24 0;
#P hidden connect 10 0 7 0;
#P connect 0 0 7 0;
#P hidden connect 10 0 6 0;
#P connect 7 0 6 0;
#P connect 6 0 5 0;
#P connect 9 0 5 0;
#P hidden connect 10 0 9 0;
#P connect 1 0 7 1;
#P connect 2 0 7 2;
#P connect 10 0 12 0;
#P connect 16 0 12 0;
#P connect 13 0 11 0;
#P connect 12 0 11 0;
#P connect 10 0 13 0;
#P connect 0 0 14 0;
#P fasten 15 0 14 0 475 180 460 180;
#P connect 18 0 16 0;
#P connect 14 0 16 0;
#P connect 2 0 15 0;
#P fasten 15 1 14 1 494 180 497 180;
#P connect 21 0 16 1;
#P connect 1 0 18 0;
#P connect 18 1 16 2;
#P connect 14 1 20 0;
#P connect 20 0 21 0;
#P pop;
#P newobj 128 169 88 196617 p sketch;
#P hidden message 4 86 70 196617 size 320 240;
#P hidden newex 17 32 50 196617 loadbang;
#P hidden message 6 54 70 196617 camera 2 4 4;
#P newex 18 204 152 196617 jit.window food @depthbuffer 1;
#P newex 18 146 50 196617 t b erase;
#P newex 18 184 87 196617 jit.gl.render food;
#P hidden connect 4 0 5 0;
#P hidden connect 4 0 3 0;
#P hidden fasten 20 0 1 0 172 108 23 108;
#P fasten 16 0 1 0 114 126 23 126;
#P fasten 1 1 0 0 41 173 23 173;
#P connect 1 0 0 0;
#P hidden fasten 3 0 0 0 11 161 23 161;
#P hidden connect 5 0 2 0;
#P fasten 14 0 16 0 90 90 114 90;
#P fasten 17 0 16 0 129 98 114 98;
#P connect 15 0 17 0;
#P fasten 16 0 10 0 114 135 133 135;
#P connect 10 0 6 0;
#P fasten 17 1 16 1 148 98 156 98;
#P fasten 20 0 11 0 172 143 172 143;
#P connect 11 0 6 1;
#P fasten 16 1 12 0 156 121 211 121;
#P connect 12 0 6 2;
#P pop;