// Last edited on 2019-11-22 21:56:53 by jstolfi #macro parafuso(hrd,hdp,htx,hconic, srd,sdp,stx, trd,tdp,ttx, what) // {hrd,hdp} are radius and depth of screw head. // {hconic} is true if head is conical. // {srd,sdp} are radius and depth of screw shank (unthreaded part). // {trd,tdp} are radius and depth of screw thread. // {htx,stx,ttx} are textures to use in the holes for each part. // The screw axis is the X-axis, the top of the head is at X=0, // and the screw extends in the +X direction. The depths // {sdp} and {tdp} are measured from the top of the head. // {what=0} returns the nominal dimensions. // {what=1} returns the screw. // {what=2} returns the object to be subtracted to make the hole. #local eps = 0.001; // Perturbation to avoid coincident surfaces. #local eps3 = < eps, eps, eps >; #if (what = 0) #local dp = max(hdp,sdp,tdp); #local rd = max(hrd,srd,trd); #local screw_dim = < dp, rd, rd >; #local res = screw_dim; #elseif (what = 1) #local screw = difference{ // Basic screw: union{ // Head: #if (hconic > 0) cone{ < 0 + eps, 0, 0 >, hrd-eps, , srd-eps } #else cylinder{ < 0 + eps, 0, 0 >, , hrd-eps } #end // Shank: #if ((sdp > hdp) & (srd > 0.0)) cylinder{ < 0 + 2*eps, 0, 0 >, , srd-eps } #end // Thread: #if ((tdp > hdp) & (trd > 0.0)) cylinder{ < 0 + 3*eps, 0, 0 >, , trd-eps } #end } // Phillips slots: #local sl_rd = 0.80*hrd; // Radius of slots. #local sl_hth = 0.20*sl_rd; // half-thickness of slots. #local sl_hsd = 0.7071*sl_rd; // Side of slot box. #local sl_hdim = < sl_hsd, sl_hsd, sl_hth>; // Half-dim of slot box. #local slot = box{ - sl_hdim - eps3, + sl_hdim + eps3 rotate 45*z } union{ object{ slot } object{ slot rotate 90*x } } texture{ tx_screw } } #local res = object{ screw } #elseif (what = 2) #local screw_hole = union{ // Head: #local hdclear = 0.5; // Clearance around cylindrical heads. #local drill_dp = 10*max(hdp, hrd); // Depth of drill hole for recessed screws. cylinder{ < - drill_dp - eps, 0, 0 >, < 0 + eps, 0, 0 >, hrd + hdclear + eps texture{ htx } } #if (hconic > 0) cone{ < 0 - eps, 0, 0 >, hrd + eps, < hdp + eps, 0, 0 >, srd + eps texture{ htx } } #else cylinder{ < 0 - eps, 0, 0 >, < hdp + eps, 0, 0 >, hrd + hdclear + eps texture{ htx } } #end // Shank: #if ((sdp > hdp) & (srd > 0.0)) cylinder{ < 0, 0, 0 >, , srd + eps texture{ stx } } #end // Thread: #if ((tdp > hdp) & (trd > 0.0)) #local hdbite = 0.75; // Thread height. cylinder{ < 0 + eps, 0, 0 >, , trd + eps texture{ ttx } } #end } #local res = object{ screw_hole } #end res #end