/* t_coil.inc 2010 Samuel T. Benge t_coil( ptA, ptB, rad1, rad2, nwnd ) t_coil_solid( ptA, ptB, rad1, rad2, nwnd ) * ptA = starting point * ptB = ending point * rad1 = major radius * rad2 = minor radius * nwnd = number of windings */ #include "shapes.inc" #declare t_coil_is_solid = false; // Rune's macro for aligning an object based on the z and y axes. // The z-axis will be given precedence over the y-axis. #macro tcoil_z_align( Normal_vector, Z_vector ) #local ObjectZ = vnormalize( Z_vector ); #local ObjectY = VPerp_Adjust( Normal_vector, Z_vector ); #local ObjectX = vcross( ObjectY, ObjectZ ); transform{ Shear_Trans( ObjectX, ObjectY, ObjectZ ) } #end #macro t_coil(ptA, ptB, rad1, rad2, nwnd) #local coil_length = vlength(ptB-ptA); #local p0 = <0, coil_length/nwnd*.125, 0>; #local p1 = <0, 0, rad1>; #local p2 = ; #local p3 = ; #local mn = vnormalize( vnormalize( p3 - p2 ) + vnormalize( p1 - p2 ) ); #local rad_ang = p3; #local rad_extend = p2; #local rad_extend_90 = rad_ang + VPerp_Adjust(mn,rad_ang-rad_extend); #local Plane = plane{ y,0 tcoil_z_align( VPerp_Adjust( p2-p1, p0-p1), p0-p2 ) translate p0 } #local intersect = trace( Plane, rad_ang, -rad_ang+rad_extend_90 ); #local this_radius = vlength( intersect - rad_ang ); #local this_angle = VAngleD( p2-intersect, rad_ang-intersect ); // objects #macro trans(V) transform{ rotate z*90 tcoil_z_align( p2-p3, -mn ) translate p0+intersect-y*coil_length/nwnd*.125 translate y*(coil_length/nwnd*V/4) rotate y*V*90 } #end #macro assemble_full_turn() #local V = 0; #while(V < 4) object{ arc trans(V) } #local V = V + 1; #end #end #macro assemble() #local V = 0; #while(V < nwnd) object{full_turn translate y*coil_length/nwnd*V} #local V = V + 1; #end #end #if(t_coil_is_solid) // solid #local arc = intersection{ torus{ this_radius, rad2 rotate -y*this_angle } object{Wedge( this_angle*2+.00001 ) rotate -y*this_angle} } merge{ #local full_turn = merge{ assemble_full_turn() } assemble() Point_At_Trans( ptB-ptA ) translate ptA } // ~solid #else // regular #local arc = torus{ this_radius, rad2 clipped_by{ Wedge( this_angle*2 ) } rotate -y*this_angle } #local end_cap = disc{ z*this_radius, x, rad2 } union{ #local full_turn = union{ assemble_full_turn() } assemble() object{end_cap rotate y*this_angle trans(0) } object{end_cap rotate -y*this_angle trans(nwnd*4-1) inverse} Point_At_Trans( ptB-ptA ) translate ptA } // ~regular #end #end #macro t_coil_solid(ptA, ptB, rad1, rad2, nwnd) #declare tcoil_solid = true; t_coil(ptA, ptB, rad1, rad2, nwnd) #declare tcoil_solid = false; #end