/* File SOMBRERO.C: Sombrero - HGC/EGA version */ #include #include //-+-±×·¡ÇÈ ÇÔ¼ö¿Í ¼öÇÐ ÇÔ¼öÀ2Ç ¼±¾ðÀÌ µé¾îÀÖÀ½ #include //-+ // +-----ºÒ¸°ÇüÀ» Á¤ÀÇ typedef enum {false, true} boolean; void graph(double y, double z, int *plotted); //-+ void rotate3d(double xr, double yr, double zr, // | ÇÔ¼ö ¼±¾ð double *px, double *py, double *pz);//-+ /* |z */// ÀÌ ¿¹Á¦¿¡¼­ #define SIZE 2. /* | */// ¾²ÀÎ 3Â÷¿ø ÁÂÇ¥°è #define ZROTATE 11. /* | */// 2 ±×·¡ÇÈ È­¸éÀº #define YROTATE 40. /* +------ y */// yzÆò¸é¿¡ ÇØ´çÇÔ #define XROTATE 0. /* / */ /* / */ /* x */ double function(double x, double y)// ¸ß½ÃÄÚ ¸ðÀÚ¸¦ ³ªÅ¸³»´Â { // 3Â÷¿ø Æò¸éÀÇ ½Ä double f; f = hypot(x, y) / 35.; if (fabs(f) < 1.e-5) return (40. * M_PI); else return (40. * sin(f * M_PI) / f); } void main(void) { // ÀÚµ¿º¯¼ö¸¦ ¼±¾ð(Á¤ÀÇ) int graphdrive = DETECT, graphmode; int plotted = false; //---- °î¼±ÀÇ ½ÃÀÛÁ¡ÀÎÁöÀÇ ¿©ºÎ¸¦ °¡¸² double x, y, z, x2, y2, z2; //---- 3Â÷¿ø ÁÂÇ¥ double zr, yr, xr; //---- °¢°¢ zÃà, yÃà, xÃàÀ» Áß½ÉÀ¸·Î Çϴ ȸÀü°¢ initgraph(&graphdrive, &graphmode, ""); zr = ZROTATE * M_PI / 180.; //-+ yr = YROTATE * M_PI / 180.; // | ¶óµð¾È °ªÀ¸·Î ȯ»ê xr = XROTATE * M_PI / 180.; //-+ for (x = -115.2; x <= 115.; x += 5.) { for (y = -115.; y <= 115.; y += 5.) { z = function(x, y); x2 = x * SIZE; //-+-- ÁÂÇ¥¸¦ SIZE¹è¸¸Å­ È®´ë y2 = y * SIZE; // | zÃà, yÃà, xÃàÀ» Áß½ÉÀ¸·Î °¢°¢ z2 = z * SIZE; //-+ | ȸÀü rotate3d(xr, yr, zr, &x2, &y2, &z2);//-+ graph(y2, z2, &plotted); //---+ } // 3Â÷¿ø °î¼±À» plotted = false; // yzÆò¸é¿¡ Åõ¿µÇÑ Á¤»ç¿µÀ» È­¸é¿¡2 ±×¸² } // | // +-»õ·Î¿î °î¼±À» ±×¸² getch(); closegraph(); //---- ±×·¡ÇÈ ½Ã½ºÅÛÀ» Á¾·á } /* Rotation order : z axis -> y axis -> x axis */ void rotate3d(double xr, double yr, double zr, double *px, double *py, double *pz) { double x = *px, y = *py, z = *pz; double x1, y1, z1, x2, y2, z2, x3, y3, z3; x1 = x * cos(zr) - y * sin(zr); // -+ y1 = x * sin(zr) + y * cos(zr); // | zÃàÀ» Áß½ÉÀ¸·Î zr¸¸Å­ ȸÀü z1 = z; // -+ x2 = x1 * cos(yr) - z1 * sin(yr); //-+ y2 = y1; // | yÃàÀ» Áß½ÉÀ¸·Î yr¸¸Å­ ȸÀü z2 = x1 * sin(yr) + z1 * cos(yr); //-+ x3 = x2; //-+ y3 = y2 * cos(xr) - z2 * sin(xr); // | xÃàÀ» Áß½ÉÀ¸·Î xr¸¸Å­ ȸÀü z3 = y2 * sin(xr) + z2 * cos(xr); //-+ *px = x3; //-+ *py = y3; // | ½Ç¸Å°³º¯¼ö x2, y2, z2¿¡ °ªÀ» ´ëÀÔ *pz = z3; //-+ (actual parameter) } void graph(double y, double z, int *plotted) { int xx, yy, xasp, yasp; getaspectratio(&xasp, &yasp); //---- È­¸éÀÇ Á¾È¾ºñ¸¦ ±¸ÇÔ xx = getmaxx() / 2 + (int)y; yy = getmaxy() / 2 - (int)(z * xasp / yasp); if (*plotted == false) moveto(xx, yy); //--- CP¸¸ À̵¿ else lineto(xx, yy); //---- °î¼±ÀÇ ½ÃÀÛÀÌ ¾Æ´Ï¸é ¼±À» ±×¸² *plotted = true; }