// Last edited on 2010-05-16 00:03:33 by stolfilocal // SCREWS //////////////////////////////////////////////////////////////// #macro wood_screw_or_hole(len,rad,screw) // Either {wood_screw} if {screw=true}, // Either {wood_screw_hole} if {screw=false}, // Head: #local rhead = 3*rad; #local hhead = 2*rad; // Hole in head: #local hhole = 1.5*rad; #local rhole = 1.5*rad; // Unthreaded part of stem: #local rstem = rad; #local hstem = 0.40*(len - hhead); // Threaded part of stem: #local rthread = 1.15*rad; #local hthread = 0.60*(len - hhead); #local C = cos(pi/3); #local S = sin(pi/3); #if (screw) union{ union{ difference{ cone{ (0-eps)*z, rhead-eps, (-hhead-eps)*z, rstem-eps } prism{ linear_spline 0+eps, -hhole+eps, 7, <+1,00>, <+C,+S>, <-C,+S>, <-1,00>, <-C,-S>, <+C,-S>, <+1,00> rotate 90*x scale < rhole+eps, rhole+eps, 1 > } } cylinder{ (-hhead+eps)*z, (-hhead-hstem-eps)*z, rstem-eps } texture{ tx_screw_smooth } } union{ cylinder{ (-hhead-hstem+eps)*z, (-hhead-hstem-hthread/2-eps)*z, rthread } cone{ (-hhead-hstem-hthread/2+eps)*z, rthread, (-hhead-hstem-hthread+eps)*z, eps } texture{ tx_screw_thread } } } #else union{ cylinder{ (+hhead+eps)*z, (0-2*eps)*z, rhead+eps } cone{ (0-eps)*z, rhead+eps, (-hhead+eps)*z, rstem+eps } cylinder{ (0-2*eps)*z, (-hhead-hstem-eps)*z, rthread+eps } cylinder{ (-hhead-hstem+eps)*z, (-hhead-hstem-hthread/2-eps)*z, rstem+eps } cone{ (-hhead-hstem-hthread/2+eps)*z, rstem+eps, (-hhead-hstem-hthread-eps)*z, 0.5*rstem } } #end #end #macro wood_screw(len,rad) // A wood screw with hex-hole conical head. // The axis is the Z-axis. // The top is slightly below Z=0. wood_screw_or_hole(len,rad,true) #end #macro wood_screw_hole(len,rad) // A countersink drill-bit for {wood_screw} // The axis is the Z-axis. // The top of the screw will sit slightly below Z=0. // No texture; client must provide one. wood_screw_or_hole(len,rad,false) #end #macro slot_bolt(len,rad,bar_wdt) // A metal bolt with a head that fits inside the slots of an {extruded_bar}. // Given the bolt's radius {rad} and length {len} excluding the head, // and the extrude bar's width {wdt}. // The bolt stem and thread are centered on the Z axis and extends down from Z=0. // The head is above the Z=0 plane, oriented to fit in a slot // that runs along the X axis. // Head: #local head_len = 0.375*bar_wdt; // Lengh of head in slot direction. #local head_wdt1 = 0.200*bar_wdt; // Width of exposed part of head. #local head_hgt1 = 0.100*bar_wdt; // Height of exposed part of head. #local head_wdt2 = 0.300*bar_wdt; // Width of buried part of head. #local head_hgt2 = 0.150*bar_wdt; // Height of buried part of head. // Inset of head into slot: #local hins = 1.0; // Unthreaded part of stem: #local hstem = 0.50*head_wdt1; // Threaded part of stem: #local hthread = len - hstem; #local C = cos(pi/3); #local S = sin(pi/3); union{ box{ < -head_len/2+eps, -head_wdt1/2+eps, hins+eps >, < +head_len/2-eps, +head_wdt1/2-eps, head_hgt1+2*eps > texture{ tx_bolt_smooth } } box{ < -head_len/2+eps, -head_wdt2/2+eps, 0+eps >, < +head_len/2-eps, +head_wdt2/2-eps, head_hgt2-eps > translate head_hgt1*z texture{ tx_bolt_smooth } } cylinder{ (hins+2*eps)*z, (0-hstem-eps)*z, rad-2*eps texture{ tx_bolt_smooth } } cylinder{ (0-hstem+eps)*z, (-len+eps)*z, rad-eps texture{ tx_screw_thread } } } #end #macro hex_bolt(len,rad) // A metal bolt with a hex head. // Given the bolt radius {rad} and length {len} excluding the head. // The bolt stem and thread are centered on the Z axis and extends down from Z=0. // The head is above the Z=0 plane. // Head: #local rhead = 3*rad; #local hhead = 1.5*rad; // Unthreaded part of stem: #local hstem = 0.50*rhead; // Threaded part of stem: #local hthread = len - hstem; #local C = cos(pi/3); #local S = sin(pi/3); union{ prism{ linear_spline 0+eps, +hhead-eps, 7, <+1,00>, <+C,+S>, <-C,+S>, <-1,00>, <-C,-S>, <+C,-S>, <+1,00> rotate 90*x scale < rhead-eps, rhead-eps, 1 > texture{ tx_bolt_smooth } } cylinder{ (0+2*eps)*z, (0-hstem-eps)*z, rad-2*eps texture{ tx_bolt_smooth } } cylinder{ (0-hstem+eps)*z, (-len+eps)*z, rad-eps texture{ tx_screw_thread } } } #end #macro hex_nut(rad) // A metal hex nut. // Given the bolt radius {rad}. // The nut is centered on the Z axis and extends down from Z=0. // Outer nut profile: #local rnut = 3*rad; #local hnut = 1.5*rad; #local C = cos(pi/3); #local S = sin(pi/3); difference{ prism{ linear_spline 0-eps, -hnut+eps, 7, <+1,00>, <+C,+S>, <-C,+S>, <-1,00>, <-C,-S>, <+C,-S>, <+1,00> rotate 90*x scale < rnut-eps, rnut-eps, 1 > texture{ tx_bolt_smooth } } cylinder{ (0+eps)*z, (-hnut-eps)*z, rad+eps texture{ tx_screw_thread } } } #end #macro washer(irad,orad,thk) // A metal washer with inner radius {irad}, outer radius {orad}, thickness {thk}. // The wasehr centered on the Z axis and extends up from Z=0. difference{ cylinder{ (0+eps)*z, (thk-eps)*z, orad-eps texture{ tx_screw_smooth } } cylinder{ (0-eps)*z, (thk+eps)*z, irad+eps texture{ tx_screw_smooth } } } #end #macro slot_bolt_washer_and_nut(len,rad,bar_wdt,nut_dst,has_wsh,has_nut,explode) // A slot bolt with optional washer and nut, inserted into the +X slot of an // extruded bar with section {bar_wdt} by {bar_wdt}. // Assumes that the bar is centerd on the Z-axis. // The washer and nut are placed {nut_dst} away from the bar. // If {has_wsh} is false the washer is omitted. // If {has_nut} is false the nut is omitted. #local washer_irad = 1.1*rad; #local washer_orad = 4.0*rad; #local washer_thk = 0.33*rad; union{ // Bolt: object{ slot_bolt(len,rad,bar_wdt) rotate -90*y translate (bar_wdt/2)*x } #local dx = bar_wdt/2 + nut_dst; #if (has_wsh) object{ washer(washer_irad,washer_orad,washer_thk) rotate 90*y translate (dx + 25*explode)*x } #local dx = dx + washer_thk; #end #if (has_nut) object{ hex_nut(rad) rotate -90*y translate (dx + 30*explode)*x } #end } #end #debug "loaded pst_screws.inc\n"