// Last edited on 2023-12-23 09:14:02 by stolfi background{ color rgb < 1, 1, 1 > } #declare steel_1 = // aço texture{ pigment{ color rgb < 0.70, 0.70, 0.70 > } finish{ diffuse 0.5 ambient 0.1 brilliance 1 reflection 0.1 specular 0.2 roughness 0.5} } #declare tx_plastico = texture{ pigment{ color rgb < 0.10, 0.80, 1.00 > } finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 } } #declare tx_2 = texture{ pigment{ color rgb < 0.30, 0.30, 0.30 > } finish{ diffuse 0.5 ambient 0.1 brilliance 1 reflection 0.15 specular 0.2 roughness 0.5} } #declare tx_xadrez = texture{ pigment{ checker color rgb < 0.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > } finish{ diffuse 0.9 ambient 0.1 } scale 2.0 } #declare tx_4 = texture{ pigment{ color rgb < 0.25, 0.59, 0.04 > } finish{ diffuse 0.3 ambient 0.1 specular 0.5 roughness 1 } } #macro tanque_4 (posX, posY, posZ) //4 tocos #local principal = cylinder { , , 1.5 // center of one end, center of other end, radius open // remove end caps } #local cabeca = sphere { , 1.5 // , radius } #local toco1 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } #local toco2 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } #local toco3 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } #local toco4 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } union { object {principal texture{steel_1}} object {cabeca texture{tx_2}} object {toco1 texture {tx_plastico}} object {toco2 texture {tx_plastico}} object {toco3 texture {tx_plastico}} object {toco4 texture {tx_plastico}} } #end #macro tanque_1 (posX, posY, posZ) //2 tocos #local principal = sphere { , 1.5 // , radius } #local toco1 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } union { object {principal texture{steel_1}} object {toco1 texture {tx_plastico}} } #end #macro tanque_2 (posX, posY, posZ) //2 tocos #local principal = sphere { , 1.5 // , radius } #local apoio1 = cone { , 1.5 // , center & radius of one end , 0 // , center & radius of the other end } #local toco1 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } #local toco2 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } union { object {principal texture{steel_1}} object {apoio1 texture{tx_2}} object {toco1 texture {tx_plastico}} object {toco2 texture {tx_plastico}} } #end #macro tanque_3 (posX, posY, posZ) // 3 tocos #local principal = box { , // near lower left corner, far upper right corner } #local cabeca = sphere { , 1.5 // , radius } #local toco1 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } #local toco2 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } #local toco3 = cylinder { , , 0.1 // center of one end, center of other end, radius open // remove end caps } union { object {principal texture{steel_1}} object {cabeca texture{tx_2}} object {toco1 texture {tx_plastico}} object {toco2 texture {tx_plastico}} object {toco3 texture {tx_plastico}} } #end #declare roleta = seed(0); #declare nmax = 3000; #declare tocos = array[nmax]; #declare contador = 0; #declare altura = 7; #macro remover (indice) #declare tocos[indice] = tocos[contador-1]; #declare contador = contador - 1; #end #macro interpola1(tt, t0, v0, t1, v1) #local ss = (tt- t0)/(t1-t0); #local vv = (1-ss)*v0 + ss*v1; vv #end #macro interpola3(tt, ta, tb, v0, v1, v2, v3) #local v01 = interpola1(tt, ta, v0, tb, v1); #local v12 = interpola1(tt, ta, v1, tb, v2); #local v23 = interpola1(tt, ta, v2, tb, v3); #local v012 = interpola1(tt, ta, v01, tb, v12); #local v123 = interpola1(tt, ta, v12, tb, v23); #local v0123 = interpola1(tt, ta, v012, tb, v123); v0123 #end #macro testa_interpola(p0, p1, n, raio) union { #local i = n; #while (i > 0) #local centro = interpola1(i, 0, p0, n, p1); #local bola = sphere { centro, raio // , radius } object{bola texture{tx_plastico}} #local i = i - 1; #end } #end #macro testa_interpola3(p0, va, vb, p1, n, raio) union { #local i = n; #while (i > 0) #local centro = interpola3(i, 0, n, p0, va, vb, p1); #local bola = sphere { centro, raio // , radius } object{bola texture{tx_plastico}} #local i = i - 1; #end } #end #macro interpola3_multi(tt, pini, n, p1, p2, pfim) #local k = int(tt); #local q1 = p1[k]; #local q2 = p2[k]; #if (k = 0) #local q0 = pini; #if (n = 1) #local q3 = pfim; #else #local q3 = (q2 + p1[k+1])/2; #end #else #local q0 = (q1 + p2[k-1])/2; #if (k = n-1) #local q3 = pfim; #else #local q3 = (q2 + p1[k+1])/2; #end #end #local pt = interpola3(tt, k, k+1, q0, q1, q2, q3); pt #end #macro rodar() #local Pini = <0,0,0>; #local n = 2; #local p1 = array[n]; #local p1[0] = <3, 0, 0>; #local p1[1] = <6, 0, 3>; #local p2 = array[n]; #local p2[0] = <3, 0, 3>; #local p2[1] = <6, 0, 6>; #local Pfim = <10, 10, 10>; #local tt = 0; #local res = 100; union { #while(tt < res*n) #local pt = interpola3_multi(tt/res, Pini, n, p1, p2, Pfim); sphere { pt, 0.1 // , radius texture { tx_plastico } } #local tt = tt + 1; #end } #end #macro liga(x0,y0,z0, x1,y1,z1) #local ini = ; #local fim = ; tanque_cubo(x0,y0,z0) #local toco_ini = ini + <0, 0, -1>; #local dire_ini = <0, 0, -1>; tanque_bola(x1,y1,z1) #local toco_fim = fim + <2, 0, 2>; #local dire_fim = <-1, 0, 0>; testa_interpola3(toco_ini, toco_ini+ dire_ini*10, toco_fim - dire_fim*10, toco_fim, 300, 0.1) #end #declare multiplicador = 10; #macro grau1_base() //offset em relação aos centro #local ponto = <2,0,0>; ponto #end #macro grau1_ponta() //offset em relação aos centro #local ponto = <2,0,0>; ponto*multiplicador #end #macro grau2_base(j) //offset em relação aos centro #local ponto = ; ponto #end #macro grau2_ponta(j) //offset em relação aos centro #local ponto = ; ponto*multiplicador #end #macro grau3_base(j) //offset em relação aos centro #local ponto = <0,0,0>; #switch (j) #case(0) #local ponto = <2,0,2>; #break #case(1) #local ponto = <-2,0,2>; #break #case(2) #local ponto = <0,0,-1>; #break #end ponto #end #macro grau3_ponta(j) //offset em relação aos centro #local ponto = <0,0,0>; #switch (j) #case(0) #local ponto = <2,0,2>; #break #case(1) #local ponto = <-2,0,2>; #break #case(2) #local ponto = <0,0,-1>; #break #end ponto*multiplicador #end #macro grau4_base(j) //offset em relação aos centro #local ponto = <0,0,0>; #switch (j) #case(0) #local ponto = <2,0,2>; #break #case(1) #local ponto = <-2,0,2>; #break #case(2) #local ponto = <0,2,2>; #break #case(3) #local ponto = <0,-2,2>; #break #end ponto #end #macro grau4_ponta(j) //offset em relação aos centro #local ponto = <0,0,0>; #switch (j) #case(0) #local ponto = <2,0,2>; #break #case(1) #local ponto = <-2,0,2>; #break #case(2) #local ponto = <0,2,2>; #break #case(3) #local ponto = <0,-2,2>; #break #end ponto*multiplicador #end #macro conetor(na, nb, pini, tini, pfim, tfim, D) #local P1 = array[na]; #local P2 = array[na]; #local i = 0; #while (i < na) #local posX = int(D*rand(roleta)); #local posY = int(D*rand(roleta)); #local posZ = int(D*rand(roleta)); #local P1[i] = ; #local posX = int(D*rand(roleta)); #local posY = int(D*rand(roleta)); #local posZ = int(D*rand(roleta)); #local P2[i] = ; #local i = i+1; #end #local P1[0] = tini; #local P2[na-1] = tfim; #local tt = 0; union { #while(tt < nb*na) #local pt = interpola3_multi(tt/nb, pini, na, P1, P2, pfim); sphere { pt, 0.1 // , radius texture { tx_plastico } } #local tt = tt + 1; #end } #end #macro gera_grafo(nv, ne, org, dst, D, na, nb) #local graus_v = array[nv]; #local usados = array[nv]; #local cvertices = array[nv]; #local i = 0; #while (i < nv) #local graus_v[i] = 0; #local usados[i] = 0; #local i = i + 1; #end #local ie = 0; #while (ie < ne) #local graus_v[org[ie]] = graus_v[org[ie]] + 1; #local graus_v[dst[ie]] = graus_v[dst[ie]] + 1; #local ie = ie + 1; #end #local i = 0; union { #while (i < nv) #local posX = int(D*rand(roleta)); #local posY = int(D*rand(roleta)); #local posZ = int(D*rand(roleta)); #local cvertices[i] = ; #switch (graus_v[i]) #case (1) tanque_1(posX, posY, posZ) #break #case (2) tanque_2(posX, posY, posZ) #break #case (3) tanque_3(posX, posY, posZ) #break #case (4) tanque_4(posX, posY, posZ) #break #end #local i = i+1; #end #local ie = 0; #while (ie < ne) #local pini = <0,0,0>; #local tini = <0,0,0>; #local pfim = <0,0,0>; #local tfim = <0,0,0>; #switch (graus_v[org[ie]]) #case (1) #local pini = cvertices[org[ie]] + grau1_base(); #local tini = cvertices[org[ie]] + grau1_ponta(); #local usados[org[ie]] = usados[org[ie]] + 1; #break #case (2) #local pini = cvertices[org[ie]] + grau2_base(usados[org[ie]]); #local tini = cvertices[org[ie]] + grau2_ponta(usados[org[ie]]); #local usados[org[ie]] = usados[org[ie]] + 1; #break #case (3) #local pini = cvertices[org[ie]] + grau3_base(usados[org[ie]]); #local tini = cvertices[org[ie]] + grau3_ponta(usados[org[ie]]); #local usados[org[ie]] = usados[org[ie]] + 1; #break #case (4) #local pini = cvertices[org[ie]] + grau4_base(usados[org[ie]]); #local tini = cvertices[org[ie]] + grau4_ponta(usados[org[ie]]); #local usados[org[ie]] = usados[org[ie]] + 1; #break #end #switch (graus_v[dst[ie]]) #case (1) #local pfim = cvertices[dst[ie]] + grau1_base(); #local tfim = cvertices[dst[ie]] + grau1_ponta(); #local usados[dst[ie]] = usados[dst[ie]] + 1; #break #case (2) #local pfim = cvertices[dst[ie]] + grau2_base(usados[dst[ie]]); #local tfim = cvertices[dst[ie]] + grau2_ponta(usados[dst[ie]]); #local usados[dst[ie]] = usados[dst[ie]] + 1; #break #case (3) #local pfim = cvertices[dst[ie]] + grau3_base(usados[dst[ie]]); #local tfim = cvertices[dst[ie]] + grau3_ponta(usados[dst[ie]]); #local usados[dst[ie]] = usados[dst[ie]] + 1; #break #case (4) #local pfim = cvertices[dst[ie]] + grau4_base(usados[dst[ie]]); #local tfim = cvertices[dst[ie]] + grau4_ponta(usados[dst[ie]]); #local usados[dst[ie]] = usados[dst[ie]] + 1; #break #end #local ie = ie + 1; conetor(na, nb, pini, tini, pfim, tfim, D) #end } #end #declare D = 30; #declare ne_grafo = 6; #declare nv_grafo = 4; #declare org = array[6] {0, 2, 2, 3, 1, 3} #declare dst = array[6] {2, 0, 1, 0, 3, 3} gera_grafo(nv_grafo, ne_grafo, org, dst, D, 2, 400) #declare cmin = < 0, 0, 0 >; #declare cmax = < D, D, D >; #include "gaiola.inc" // object{ gaiola(cmin,cmax) } #declare centro_cena = (cmin + cmax)/2; #declare raio_cena = 0.55*vlength(cmax-cmin); // #declare centro_cena = D * < 0.5, 0.7, 0.5 >; // #declare raio_cena = 0.25*vlength(cmax-cmin); #declare dist_camera = 7*raio_cena; #include "camlight.inc" #declare dir_camera = < 7, 5, 3 >; #declare intens_luz = 1.20; camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)