// Last edited on 2023-12-23 02:39:51 by stolfi background{ color rgb < 0.8, 0.8, 0.9 > } // ====================================================================== // CORES E TEXTURAS #declare tx_plastico_azul = texture { pigment { color rgb < 0.05, 0.40, 0.50 > } finish { diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 } } #declare tx_plastico_branco = texture { pigment { color rgb < 1, 1, 1 > } finish { diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 } } #declare tx_plastico_vermelho = texture { pigment { color rgb < 0.9, 0.1, 0.1 > } finish { diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 } } #declare tx_plastico_verde = texture { pigment { color rgb < 0.1, 0.9, 0.1 > } finish { diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 } } // ====================================================================== // DESCRIÇÃO DOS VÉRTICES #declare ver_2 = union { union { sphere { < 0, 0, 0>, 2 } cylinder { <3, 0, 0>, <-3, 0, 0>, 1 } texture { tx_plastico_azul } } union { sphere { <3, 0, 0>, 0.25 } sphere { <-3, 0, 0>, 0.25 } texture { tx_plastico_branco } } } #declare ver_3 = union { union { cylinder { <0, 0, -0.75>, <0, 0, 0.75>, 2 } cone { <0, 0, 0.75>, 2.0 <0, 0, 1.75>, 0 } texture { tx_plastico_azul } } union { sphere { <2, 0, 0>, 0.25 } sphere { <2, 0, 0>, 0.25 rotate <0, 0, 120> } sphere { <2, 0, 0>, 0.25 rotate <0, 0, 240> } texture { tx_plastico_branco } } } #declare ver_4 = union { union { box { <-1, -1, -1>, <1, 1, 1> } box { <-0.5, -0.5, 1>, <0.5, 0.5, 2> rotate <0, 0, 45> } texture { tx_plastico_azul } } union { sphere { <1, 0, 0>, 0.25 } sphere { <0, 1, 0>, 0.25 } sphere { <-1, 0, 0>, 0.25 } sphere { <0, -1, 0>, 0.25 } texture { tx_plastico_branco } } } // ====================================================================== // AJUDA PARA ENCONTRAR AS SAIDAS DOS VERTICES #macro s_ver_1 (N) #local S = <3, 0, 0>; S #end #macro s_ver_2 (N) #local S = <3 + (-6 * N), 0, 0>; S #end #macro s_ver_3 (N) #local inv_x = 0; #local inv_y = 0; #if (N > 0) #local inv_x = 1; #local inv_y = 1; #end #if (N > 1) #local inv_y = -1; #end #local S = <2 + (-3) * inv_x, -2 * 0.866025404 * inv_y, 0>; S #end #macro s_ver_4 (N) #if (N = 0) #local S = <1, 0, 0>; #end #if (N = 1) #local S = <0, 1, 0>; #end #if (N = 2) #local S = <-1, 0, 0>; #end #if (N = 3) #local S = <0, -1, 0>; #end S #end // ====================================================================== // INTERPOLAÇÃO #macro interpola1 (T, T0, V0, T1, V1) #local ss = (T - T0) / (T1 - T0); #local vv = (1 - ss) * V0 + ss * V1; vv #end #macro interpola3 (T, T0, T1, V0, V1, V2, V3) #local v01 = interpola1(T, T0, V0, T1, V1); #local v12 = interpola1(T, T0, V1, T1, V2); #local v23 = interpola1(T, T0, V2, T1, V3); #local v012 = interpola1(T, T0, v01, T1, v12); #local v123 = interpola1(T, T0, v12, T1, v23); #local v0123 = interpola1(T, T0, v012, T1, v123); v0123 #end #macro interpola3_multi (T, Pi, N, P1s, P2s, Pf) #local k = int(T); #local Q0 = Pi; #local Q3 = Pf; #local Q1 = P1s[k]; #local Q2 = P2s[k]; #if (k > 0) #local Q0 = (P2s[k - 1] + P1s[k]) / 2; #end #if (k < (N-1)) #local Q3 = (P1s[k + 1] + P2s[k]) / 2; #end #local Pt = interpola3(T, k, k+1, Q0, Q1, Q2, Q3); Pt #end #macro interpola1_teste (P0, P1, N, R) union { #local i = 0; #while (i < N) #local centro = interpola1 (i, 0, P0, N, P1); sphere { centro, R } #local i = i + 1; #end } #end #macro interpola3_teste (P0, P1, P2, P3, N, R) union { #local i = 0; #while (i < N) #local centro = interpola3 (i, 0, N, P0, P1, P2, P3); sphere { centro, R } #local i = i + 1; #end } #end #macro interpola3_multi_draw (Pi, Pf, N_curvas, P1s, P2s, N_pontos, P_raio) union { #local i = 0; #while (i < N_pontos) #local T = (i / N_pontos) * N_curvas; #local centro = interpola3_multi(T, Pi, N_curvas, P1s, P2s, Pf); sphere { centro, P_raio } #local i = i + 1; #end } #end #macro gera_grafo(nv, ne, org, dst, D, na, nb) #local GV = array[nv]; #local deg = array[nv]; #local t_usados = array[nv]; #local S = seed(0); union { // Gera vertices #for (i, 0, nv - 1) // Gera vertice i #local pos = * D - (D / 2); #local GV[i] = pos; #local t_usados[i] = 0; // Conta grau do vertice i #local deg[i] = 0; #for (j, 0, ne - 1) #if (org[j] = i) #local deg[i] = deg[i] + 1; #end #if (dst[j] = i) #local deg[i] = deg[i] + 1; #end #end // Desenha o vertice i #if (deg[i] < 2) sphere{pos, 1.5 texture {tx_plastico_azul}} #end #if (deg[i] = 2) object {ver_2 translate pos} #end #if (deg[i] = 3) object {ver_3 translate pos} #end #if (deg[i] = 4) object {ver_4 translate pos} #end #end // Gera arestas #for (i, 0, ne - 1) // Pontos da origem #local vorigem = org[i]; #if (deg[vorigem] = 1) #local t_org_base = s_ver_1(t_usados[vorigem]); #local t_org_ponta = t_org_base * 3; #end #if (deg[vorigem] = 2) #local t_org_base = s_ver_2(t_usados[vorigem]); #local t_org_ponta = t_org_base * 3; #end #if (deg[vorigem] = 3) #local t_org_base = s_ver_3(t_usados[vorigem]); #local t_org_ponta = t_org_base * 3; #end #if (deg[vorigem] = 4) #local t_org_base = s_ver_4(t_usados[vorigem]); #local t_org_ponta = t_org_base * 3; #end #local t_org_base = t_org_base + GV[vorigem]; #local t_org_ponta = t_org_ponta + GV[vorigem]; #local t_usados[vorigem] = t_usados[vorigem] + 1; // Pontos do destino #local vdestino = dst[i]; #if (deg[vdestino] = 1) #local t_dst_base = s_ver_1(t_usados[vdestino]); #local t_dst_ponta = t_dst_base * 3; #end #if (deg[vdestino] = 2) #local t_dst_base = s_ver_2(t_usados[vdestino]); #local t_dst_ponta = t_dst_base * 3; #end #if (deg[vdestino] = 3) #local t_dst_base = s_ver_3(t_usados[vdestino]); #local t_dst_ponta = t_dst_base * 3; #end #if (deg[vdestino] = 4) #local t_dst_base = s_ver_4(t_usados[vdestino]); #local t_dst_ponta = t_dst_base * 3; #end #local t_dst_base = t_dst_base + GV[vdestino]; #local t_dst_ponta = t_dst_ponta + GV[vdestino]; #local t_usados[vdestino] = t_usados[vdestino] + 1; #if (0 = 0) #debug concat("!!", str(vorigem,0,0), " ", str(vdestino,0,0), "\n") conector(na, nb, t_org_base, t_org_ponta, t_dst_base, t_dst_ponta, D) #end #end } #end #macro conector(na, nb, pini, tini, pfin, tfin, D) #local P1 = array[na]; #local P2 = array[na]; // preenche os pontos #local P1[0] = tini; #local P2[na-1] = tfin; #local S = seed(1); #for (i, 0, na - 2) // sendo o -2 para P1[0] e P2[na-1] #local P1[i+1] = * D - (D / 2); #local P2[i] = * D - (D / 2); #end union{ #local i = 0; #while (i < nb) #local T = (i / nb) * na; #local centro = interpola3_multi(T, pini, na, P1, P2, pfin); sphere { centro, 0.1 texture {tx_plastico_vermelho} } #local i = i + 1; #end } #end // ====================================================================== // CONSTRUINDO (FINAL) #local nv = 4; #local ne = 6; #local org = array[ne] {0, 2, 2, 2, 1, 3}; #local dst = array[ne] {2, 0, 1, 0, 3, 3}; #local D = 30; #local na = 5; #local nb = 2000; // object {conector(5, 2000, <-10, 0, 0>, <-9, 0, 1>, <9, 0, -1>, <10, 0, 0>, 10)} object {gera_grafo(nv, ne, org, dst, D, na, nb)} #declare cmin = < -D/2, -D/2, -D/2 >; #declare cmax = < +D/2, +D/2, +D/2 >; #include "gaiola.inc" // object{ gaiola(cmin,cmax) } #declare centro_cena = (cmin + cmax)/2; #declare raio_cena = 0.65*vlength(cmax-cmin); #declare dist_camera = 7*raio_cena; #include "camlight.inc" #declare dir_camera = < -5, 4, 3 >; #declare intens_luz = 1.2; camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)