#macro CreateRing( WD, ID, n, m, d ) /* This macro can create an open or closed ring. A closed ring would have a helix distance (d) of zero. An open ring would probably have a helix distance of 2.25 to 2.5 times the wire diameter (WD). WD = wire diameter ID = ring I.D. n = Number of cross-section segments m = Number of loft segments d = Helix distance Created by: Zlosk (mailler@zlosk.com) December 21, 2004 */ union { #declare WR = WD / 2.0; #declare IR = ID / 2.0; #declare xCtr = WR + IR; #declare yCtr = 0; #declare zCtr = 0; // Build the cross-section vertex list #declare i = 0; #declare xBase = array[n]; #declare yBase = array[n]; #declare zBase = array[n]; #while (i < n) #declare xBase[i] = xCtr + WR * cos(2*pi*i/n); #declare yBase[i] = yCtr; #declare zBase[i] = zCtr + WR * sin(2*pi*i/n); #declare i = i + 1; #end #declare dz = d / m; mesh2 { vertex_vectors { n * (m + 1), #declare LoftCt = 0; #while (LoftCt <= m) #declare VtxCt = 0; #while (VtxCt < n) < cos( LoftCt * 2*pi/m ) * (xCtr+WR*cos((VtxCt-n*LoftCt)* 2*pi/n)), sin( LoftCt * 2*pi/m ) * xBase[VtxCt], zCtr+WR*sin(2*pi * VtxCt/n) + LoftCt*d/m >, #declare VtxCt = VtxCt + 1; #end #declare LoftCt = LoftCt + 1; #end } normal_vectors { n * (m + 1), #declare LoftCt = 0; #while (LoftCt <= m) #declare VtxCt = 0; #while (VtxCt < n) #declare dx = cos( 2*pi * LoftCt/m ) * cos( 2*pi * (VtxCt/n - LoftCt) ); #declare dy = sin( 2*pi * LoftCt/m ) * cos( 2*pi * (VtxCt/n - LoftCt) ); #declare dz = sin( 2*pi * VtxCt/n); < dx, dy, dz >, #declare VtxCt = VtxCt + 1; #end #declare LoftCt = LoftCt + 1; #end } face_indices { 2 * n * m, #declare LoftCt = 0; #while (LoftCt < m) #declare VtxCt = 0; #while (VtxCt < n) #declare p1 = LoftCt*n + VtxCt; #declare p2 = (LoftCt+1)*n + VtxCt; #declare p3 = (LoftCt+1)*n + VtxCt + 1; #declare p4 = LoftCt*n + VtxCt + 1; #if (VtxCt = (n-1)) #declare p3 = p3 - n; #declare p4 = p4 - n; #end < p1, p2, p3>, < p1, p3, p4>, #declare VtxCt = VtxCt + 1; #end #declare LoftCt = LoftCt + 1; #if (LoftCt < m) #end #end } } // end mesh2 mesh2 { vertex_vectors { 2*n + 2, #declare VtxCt = 0; #while (VtxCt < n) < xBase[VtxCt], yBase[VtxCt], zBase[VtxCt] >, #declare VtxCt = VtxCt + 1; #end #declare VtxCt = 0; #while (VtxCt < n) < xBase[VtxCt], yBase[VtxCt], zBase[VtxCt] + d >, #declare VtxCt = VtxCt + 1; #end < xCtr, yCtr, 0 >, < xCtr, yCtr, d > } // end vertex_vectors face_indices { 2*n, #declare VtxCt = 0; #declare p0 = 2*n; #while (VtxCt < n) #declare p1 = VtxCt + 1; #if ((VtxCt+1) = n) #declare p1 = p1 - n; #end < p0, VtxCt, p1 >, < p0 + 1, VtxCt + n, p1 + n>, #declare VtxCt = VtxCt + 1; #end } // end face_indices } // end mesh2 } // end union #end