NB. Dodecahedron and Icosahedron NB. OpGLN_Polyh.ijs NB. 1st v 2009/9/1 by T. Nishikawa NB. rev. 2009/9/14 NB. using revised polyhedron program 2009/11/7 NB. Soccer Ball - added 2009/12/20 NB. run 0 / run '' => Dodecahedron NB. run 1 => Icosahedron NB. run 2 => Soccer Ball / Semiregular Polyhedron [5,6,6] NB. run 3 => Another Soccer Ball / Semiregular Polyhedron [5,6,6] NB. polyhedron vertex imported from polyhedron.ijs ===================== NB. polyhedron.ijs NB. 正12面体と正20面体の頂点座標を求める NB. 2009/11/2 NB. 2009/11/9 一辺=2a に変更する load 'trig' polyh =: 3 : 0 : a =. x. % 2 NB. 正多面体を構成する正多角形の一辺 'p q' =. y. NB. シェフリのパラメータ K =. %: 1 - ( ((cos 1p1%p)^2) + (cos 1p1%q)^2 ) NB. R = 正多面体の外接球の半径 R =. a * (sin 1p1 % q) % (K) l =. a * (cos 1p1 % p) % (K) NB. r = 正多面体の内接球の半径 r =. a * (% tan 1p1 % p) * (cos 1p1 % q) % (K) NB. r5 = 正5角形の外接円の半径 r5 =. (a) % sin 1p1 % 5 h5 =. %: (R^2) - (r5^2) NB. h5=r: 正5角形の板の高さ=正5角形と重心との距離=正多面体の内接球の半径 R, r, r5 ) NB. 正12面体の頂点座標 dodec =: 3 : 0 a =. y. 'R r r5' =. a polyh 5 3 'p q' =. 5, 3 NB. R=正12面体の外接球の半径 NB. r=正12面体の内接球の半径=正5角形の板と重心との距離 NB. r5=正5角形の外接円の半径 TH =. (2p1 % p) * i.5 DA =. (r5 * (cos TH),. (sin TH)),"(1 0) r 'D0 D1 D2 D3 D4' =. DA D0 =. 0{DA 'D0X D0Y D0Z' =. D0 sin_alph =. (a%2) % R cos_alph =. %: 1 - sin_alph^2 sin_2alph =. 2 * sin_alph * cos_alph cos_2alph =. (cos_alph^2) - (sin_alph^2) D5X =. (D0X*cos_2alph) + (D0Z*sin_2alph) D5Z =. (-D0X*sin_2alph) + (D0Z*cos_2alph) D5Y =. D0Y D5 =. D5X, D5Y, D5Z DBX =. (D5X * cos TH) - (D5Y * sin TH) DBY =. (D5X * sin TH) + (D5Y * cos TH) DB =. (DBX,.DBY),"(1) D5Z 'D5 D6 D7 D8 D9' =. DB NB. 対蹠点を求めた後、順序を調整する 09/11/11 DC0 =. -|. DB DC1 =. 1 _1 1*"(1 1) DC0 DC =. 1 |. DC1 'D10 D11 D12 D13 D14' =. DC DDX =. -|. DA DDY =. 1 _1 1*"(1 1) DDX DD =. 1 |. DDY 'D15 D16 D17 D18 D19' =. DD DA, DB, DC, DD ) NB. 正20面体の頂点座標 icosa =: 3 : 0 a =. y. 'R r r5' =. a polyh 3 5 'p q' =. 3, 5 NB. R=正20面体の外接球の半径 C0 =. 0, 0, R 'C0X C0Y C0Z' =. C0 sin_beta =. (a%2) % R cos_beta =. %: 1 - sin_beta^2 sin_2beta =. 2 * sin_beta * cos_beta cos_2beta =. (cos_beta^2) - (sin_beta^2) C1X =. (C0X*cos_2beta) + (C0Z*sin_2beta) C1Z =. (-C0X*sin_2beta) + (C0Z*cos_2beta) C1Y =. C0Y C1 =. C1X, C1Y, C1Z TH =. (2p1 % 5) * i.5 CA =. (C1X * (cos TH),. (sin TH)),"(1 0) C1Z 'C1 C2 C3 C4 C5' =. CA CAXY =. 0 1{"(1) CA NB. 対蹠点を求めた後、順序を調整する 09/11/11 CB0 =. (_1* CAXY),"(1 0) (-C1Z) CB =. 2 |. CB0 'C6 C7 C8 C9 C10' =. CB C11 =. - C0 C0, CA, CB, C11 ) NB. Distance for Check NB. eg. D1 dist D6 => 5, D6 dist D12 => 5, D6 dist D13 => 5 dist =: 3 : 0 : 'ax ay az' =. x. 'bx by bz' =. y. %: (*: ax-bx) + (*: ay-by) + (*: az-bz) ) NB. OpenGL Graphics =============================================================== require 'gl3' A=: noun define pc a closeok; menupop "&Help"; menu help "&Help" "" "" ""; menupopz; xywh 0 0 220 200;cc g isigraph ws_clipchildren ws_clipsiblings rightmove bottommove; pas 0 0; rem form end; ) run =: a_run a_run=: verb define N =: y. NB. if. N = 0 NB. do. Vd =: dodec 1.5 NB. else. Vc =: icosa 2 NB. end. select. N case. 0 do. Vd =: dodec 1.5 case. 1 do. Vc =: icosa 2 case. 2 do. Vs =: icosa 2 MD =: 3 ME =: 1 case. 3 do. Vs =: icosa 2 MD =: 3 ME =: 1.5 end. wd A glaRC'' NB. enable gl3-OpenGL R =: 0 0 0 glaFont 'arial 30' glaUseFontBitmaps 0 32 26 32 wd 'pshow;ptop' ) a_g_char =: verb define R =: 360 | R + 3 * 'xyz' = 0 { sysdata NB. key_in 'x', rotate around x-axis R =: 360 | R - 3 * 'XYZ' = 0 { sysdata NB. key_in 'X', rotate around x-axis g glpaintx'' ) a_g_size=:verb define wh=.glqwh'' glViewport 0 0,wh glMatrixMode GL_PROJECTION glLoadIdentity'' NB. gluPerspective 30, (%/wh),5 15 NB. for Perspective Projection glOrtho _3 3 _3 3 _3 3 NB. for Ortho Projection ) a_g_paint =: verb define glClearColor 1 1 1 0 NB. back ground white glClear GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT glEnable GL_DEPTH_TEST glMatrixMode GL_MODELVIEW glLoadIdentity'' glTranslate 0 0 0 NB. for Ortho Projection NB.glTranslate 0 0 _10 NB. for Perspective Projection glRotate R ,. 3 3 $ 1 0 0 0 NB. glPolygonMode GL_FRONT_AND_BACK, GL_LINE NB. wire frame glPolygonMode GL_FRONT_AND_BACK, GL_FILL NB. if. N = 0 NB. do. draw_dodec '' NB. else. draw_icosa '' NB. end. select. N case. 0 do. draw_dodec '' case. 1 do. draw_icosa '' case. 2;3 do. draw_soccer5 '' draw_soccer6 '' end. drawtext '' glaSwapBuffers '' ) NB. Color Data COLA=: 1 0 0 COLB=: 0 1 0 COLC=: 0 0 1 COLD=: 1 1 0 COLE=: 0 0.5 1 COLF=: 1 0 1 COLG=: 1 0.5 0 COLH=: 0.5 1 0 COLI=: 1 0 0.5 COLJ=: 0.5 0 1 COLK=: 0 0.5 1 COLL=: 0.5 0.5 0.5 COLM=: 0.7 0 0 COLN=: 0.7 1 0 COLO=: 0.7 0 1 COLP=: 0.7 1 1 COLQ=: 0.3 0.3 0 COLR=: 0.3 0.3 1 COLS=: 0.3 1 0.3 COLT=: 0.3 1 1 drawtext =: verb define glMatrixMode GL_MODELVIEW glLoadIdentity '' glColor 0 0 0 0 glRasterPos _1.2 _2.5 0 glCallLists 5 ": R NB. indicate X, Y, Z rotated angles in deg ) a_help_button=: verb define wd'mb OpenGL *Press x y z to rotate.' wd 'setfocus g' ) polygon=: 4 : 0 glColor 4{.x.,1 glBegin GL_POLYGON glVertex y. glEnd '' ) NB. Dodecahedron Vertex draw_dodec=:verb define COLA polygon 0 1 2 3 4 {Vd NB. あか COLB polygon 0 5 11 6 1 {Vd NB. みどり COLC polygon 1 6 12 7 2 {Vd NB. あお COLD polygon 2 7 13 8 3 {Vd NB. き COLE polygon 3 8 14 9 4 {Vd NB. みずいろ COLF polygon 4 9 10 5 0 {Vd NB. むらさき COLG polygon 19 14 9 10 15 {Vd NB. ちゃいろ COLH polygon 18 13 8 14 19 {Vd NB. きみどり COLI polygon 17 12 7 13 18 {Vd NB. あかむらさき COLJ polygon 16 11 6 12 17 {Vd NB. こいあお COLK polygon 15 10 5 11 16 {Vd NB. そらいろ COLL polygon 15 19 18 17 16 {Vd NB. はいいろ ) NB. Icosahedron Vertex draw_icosa=:verb define COLA polygon 0 1 2 {Vc NB. あか COLB polygon 0 2 3 {Vc NB. みどり COLC polygon 0 3 4 {Vc NB. あお COLD polygon 0 4 5 {Vc NB. き COLE polygon 0 5 1 {Vc NB. みずいろ COLF polygon 1 2 7 {Vc NB. むらさき COLG polygon 2 3 8 {Vc NB. ちゃいろ COLH polygon 3 4 9 {Vc NB. きみどり COLI polygon 4 5 10 {Vc NB. あかむらさき COLJ polygon 5 1 6 {Vc NB. こいあお COLK polygon 1 6 7 {Vc NB. そらいろ COLL polygon 2 7 8 {Vc NB. はいいろ COLM polygon 3 8 9 {Vc NB. COLN polygon 4 9 10 {Vc NB. COLO polygon 5 10 6 {Vc NB. COLP polygon 6 7 11 {Vc NB. COLQ polygon 7 8 11 {Vc NB. COLR polygon 8 9 11 {Vc NB. COLS polygon 9 10 11 {Vc NB. COLT polygon 10 6 11 {Vc NB. ) NB. Soccer Ball = Truncated Semiregular Polyhedron [5,6,6] / 2009/12/22 ============= Vs =: icosa 2 NB. Soccer Ball - Pentagon ======================================== twovtx =: 3 : 0 y. { TWOVX ) TWOVX =: 0 1;0 2;0 3;0 4;0 5 TWOVX =: TWOVX,: (1 0;1 5;1 6;1 7;1 2) TWOVX =: TWOVX, (2 0;2 1;2 7;2 8;2 3) TWOVX =: TWOVX, (3 0;3 2;3 8;3 9;3 4) TWOVX =: TWOVX, (4 0;4 3;4 9;4 10;4 5) TWOVX =: TWOVX, (5 0;5 4;5 10;5 6;5 1) TWOVX =: TWOVX, (6 1;6 5;6 10;6 11;6 7) TWOVX =: TWOVX, (7 2;7 1;7 6;7 11;7 8) TWOVX =: TWOVX, (8 3;8 2;8 7;8 11;8 9) TWOVX =: TWOVX, (9 4;9 3;9 8;9 11;9 10) TWOVX =: TWOVX, (10 5;10 4;10 9;10 11;10 6) TWOVX =: TWOVX, (11 6;11 7;11 8;11 9;11 10) NB. MD =: 3 NB. ME =: 1 NB. ME =: 1.5 NB. if try, then another soccer ball !! midvtx =: 4 : 0 'VA VB' =. y. 'e d' =. x. VM =. VA + (e%d) * VB - VA ) NB. Pentagon Vertex of Succer Ball soc5 =: 3 : 0 (ME, MD) midvtx "1 <"1 > (twovtx y.) { L:0 Vs ) NB. Succer Ball - Hexagon ============================================ IND_ICO =: 0 1 2;0 2 3;0 3 4;0 4 5;0 5 1 IND_ICO =: IND_ICO, 1 7 2; 2 8 3;3 9 4;4 10 5;5 6 1 IND_ICO =: IND_ICO, 6 7 1; 7 8 2;8 9 3;9 10 4;10 6 5 IND_ICO =: IND_ICO, 6 7 11;7 8 11;8 9 11;9 10 11;10 6 11 pairvtx =: 3 : 0 t0 =: 0 1{L:0 y. t1 =: 1 2{L:0 y. t2 =: 2 0{L:0 y. t0, t1, t2 ) XYZ6 =: (pairvtx "(0) IND_ICO) {L:0 Vs midvtx2 =: 4 : 0 'VA VB' =. y. 'e d' =. x. VM =. VA + (e%d) * VB - VA VN =. VA + ((d-e)%d) * VB - VA VM,: VN ) NB. MXYZ6 =: (ME, MD) midvtx2 L:0 XYZ6 NB. Soccer Ball BLAK =: 0 0 0 draw_soccer5 =: verb define BLAK polygon soc5 0 BLAK polygon soc5 1 BLAK polygon soc5 2 BLAK polygon soc5 3 BLAK polygon soc5 4 BLAK polygon soc5 5 BLAK polygon soc5 6 BLAK polygon soc5 7 BLAK polygon soc5 8 BLAK polygon soc5 9 BLAK polygon soc5 10 BLAK polygon soc5 11 ) GRAY =: 0.7 0.7 0.7 GRAX =: 0.8 0.8 0.8 GRAZ =: 0.9 0.9 0.9 draw_soccer6 =: verb define MXYZ6 =. (ME, MD) midvtx2 L:0 XYZ6 GRAY polygon 6 3$,>0{MXYZ6 GRAX polygon 6 3$,>1{MXYZ6 GRAY polygon 6 3$,>2{MXYZ6 GRAX polygon 6 3$,>3{MXYZ6 GRAZ polygon 6 3$,>4{MXYZ6 GRAX polygon 6 3$,>5{MXYZ6 GRAY polygon 6 3$,>6{MXYZ6 GRAZ polygon 6 3$,>7{MXYZ6 GRAY polygon 6 3$,>8{MXYZ6 GRAZ polygon 6 3$,>9{MXYZ6 GRAY polygon 6 3$,>10{MXYZ6 GRAZ polygon 6 3$,>11{MXYZ6 GRAY polygon 6 3$,>12{MXYZ6 GRAZ polygon 6 3$,>13{MXYZ6 GRAY polygon 6 3$,>14{MXYZ6 GRAZ polygon 6 3$,>15{MXYZ6 GRAY polygon 6 3$,>16{MXYZ6 GRAZ polygon 6 3$,>17{MXYZ6 GRAY polygon 6 3$,>18{MXYZ6 GRAZ polygon 6 3$,>19{MXYZ6 ) NB. normal vector from VNR Dictionary p.367 NB. Example 3 NB. let a = 5 _3 1, b = _1 _1 2, then vector_product a and b = _5 _11 _8 NB. Usage: NB. norm_vec 5 _3 1;_1 _1 2 NB. _5 _11 _8 P0 =: 1 0 0 P1 =: 0 1 0 P2 =: 0 0 1 norm_vec =: 3 : 0 M =. > y. NX =. -/ . * (<0 1;1 2) { M NY =. - -/ . * (<0 1;0 2) { M NZ =. -/ . * (<0 1;0 1) { M NX, NY, NZ )