2024-02-26 10:56:50 +00:00
use < mirrorcopy.scad >
2021-10-17 19:21:17 +00:00
capSizeMSizeMultiplier = 1.66 * 1.01 ;
printingKerfMM = 0.6 ;
circleFacets = 60 ;
boltColour = "LightSkyBlue" ;
boltClearanceColour = "LightSteelBlue" ;
2024-02-26 10:56:50 +00:00
boltClearanceTransparency = 0.3 ;
2021-10-17 19:21:17 +00:00
2024-02-26 10:56:50 +00:00
module metricBoltHex ( mSize , structural = false , recessNut = 0 , recessNutIsCircleMM = false , chamfer = false ) {
2021-09-09 09:27:59 +00:00
// Hex diameter = mSize * 1.8, (or 2.0 if structural
// We add 1% to make the hex slip in better
2021-10-17 19:21:17 +00:00
hexDiameter = ( mSize * ( structural ? 2.0 : 1.8 ) * 1.01 ) + printingKerfMM ;
2021-09-09 09:27:59 +00:00
2021-10-17 19:21:17 +00:00
color ( boltColour )
2021-08-18 23:45:53 +00:00
translate ( [ 0 , 0 , ( mSize * 0.7 ) / 2 ] )
cylinder ( d = hexDiameter , h = mSize * 0.7 , $fn = 6 , center = true ) ;
if ( recessNut > 0 ) {
2024-02-26 10:56:50 +00:00
if ( recessNutIsCircleMM = = false ) {
color ( boltClearanceColour , boltClearanceTransparency )
translate ( [ 0 , 0 , ( recessNut / 2 ) * - 1 + 0.1 ] )
cylinder ( d = hexDiameter , h = recessNut + 0.1 , $fn = 6 , center = true ) ;
} else {
color ( boltClearanceColour , boltClearanceTransparency )
translate ( [ 0 , 0 , ( recessNut / 2 ) * - 1 + 0.1 ] )
cylinder ( d = recessNutIsCircleMM > hexDiameter ? recessNutIsCircleMM : hexDiameter , h = recessNut + 0.1 , $fn = circleFacets , center = true ) ;
}
2021-08-18 23:45:53 +00:00
}
if ( chamfer ) {
chamferHeight = mSize * 1.5 * 0.595 ;
2024-02-26 10:56:50 +00:00
color ( boltClearanceColour , boltClearanceTransparency )
translate ( [ 0 , 0 , ( mSize * 0.7 ) + ( chamferHeight / 2 ) ] )
cylinder ( d1 = hexDiameter , d2 = 0 , h = chamferHeight , center = true , $fn = 6 ) ;
2021-08-18 23:45:53 +00:00
}
}
2024-02-26 10:56:50 +00:00
module metricSocketCap ( mSize , length , structural = false , recessCap = 0 , chamfer = false , overrideCapSize = 0 ) {
2021-09-09 09:27:59 +00:00
//cap size = M number * 1.5.
// We add 1% to make the cap head spin nicely in the hole.
2024-02-26 10:56:50 +00:00
capSize = overrideCapSize > 0 ? overrideCapSize : ( mSize * capSizeMSizeMultiplier ) + printingKerfMM ;
2021-10-17 19:21:17 +00:00
color ( boltColour )
translate ( [ 0 , 0 , ( length + ( ( mSize * 1.25 ) / 2 ) ) ] )
cylinder ( d = capSize , h = mSize * 1.25 , center = true , $fn = circleFacets ) ;
2024-02-26 10:56:50 +00:00
//echo (str("cap size is ", capSize));
2021-08-18 23:45:53 +00:00
if ( recessCap > 0 ) {
2024-02-26 10:56:50 +00:00
color ( boltClearanceColour , boltClearanceTransparency )
2021-08-18 23:45:53 +00:00
translate ( [ 0 , 0 , ( length + ( ( recessCap / 2 ) + ( mSize * 1.25 ) ) ) ] )
2024-02-26 10:56:50 +00:00
cylinder ( d = capSize , h = recessCap + 0.01 , center = true , $fn = circleFacets ) ;
2021-08-18 23:45:53 +00:00
}
if ( chamfer ) {
2024-02-26 10:56:50 +00:00
color ( boltClearanceColour , boltClearanceTransparency )
2021-08-18 23:45:53 +00:00
translate ( [ 0 , 0 , ( length - ( ( mSize * 1.5 * 0.595 ) / 2 ) ) ] )
2021-10-17 19:21:17 +00:00
cylinder ( d2 = capSize , d1 = 0 , h = mSize * 1.5 * 0.595 , center = true , $fn = circleFacets ) ;
2021-08-18 23:45:53 +00:00
}
}
module metricShaft ( mSize , length , structural = false ) {
2021-10-17 19:21:17 +00:00
color ( boltColour )
translate ( [ 0 , 0 , ( length / 2 ) ] )
cylinder ( d = mSize + printingKerfMM , h = length + 0.01 , center = true , $fn = circleFacets ) ;
2021-08-18 23:45:53 +00:00
}
2024-02-26 10:56:50 +00:00
module metricSocketScrew ( mSize , length , structural = false , recessCap = 0 , chamfer = false , overrideCapSize = 0 ) {
metricSocketCap ( mSize , length , structural = structural , recessCap = recessCap , chamfer = chamfer , overrideCapSize = overrideCapSize ) ;
2021-08-18 23:45:53 +00:00
metricShaft ( mSize , length , structural = structural ) ;
}
2024-02-26 10:56:50 +00:00
module metricSocketScrewSlot ( mSize , length , width , structural = false , recessCap = 0 , chamfer = false , overrideCapSize = 0 ) {
hull ( ) mirrorCopy ( )
translate ( [ width / 2 , 0 , 0 ] )
metricSocketCap ( mSize , length , structural = structural , recessCap = recessCap , chamfer = chamfer , overrideCapSize = overrideCapSize ) ;
hull ( ) mirrorCopy ( )
translate ( [ width / 2 , 0 , 0 ] )
metricShaft ( mSize , length , structural = structural ) ;
}
2021-08-18 23:45:53 +00:00
2024-02-26 10:56:50 +00:00
module metricCapheadAndBolt ( mSize , length = 40 , structural = false , recessCap = 0 , recessNut = 0 , recessNutIsCircleMM = false , chamfer = false , overrideCapSize = 0 ) {
capSize = overrideCapSize > 0 ? overrideCapSize : ( mSize * capSizeMSizeMultiplier ) + printingKerfMM ;
2021-10-17 19:21:17 +00:00
2024-02-26 10:56:50 +00:00
/*echo (str("Creating a M",mSize, " size, ", length, "mm long bolt with a ", capSize, "mm wide caphead and bolt ", chamfer?"with":"without", " chamfering."));
2021-08-18 23:45:53 +00:00
if ( recessCap ) {
echo ( str ( "It has a " , recessCap , "mm recessed cap" ) ) ;
}
if ( recessNut ) {
echo ( str ( "It has a " , recessCap , "mm recessed nut" ) ) ;
2024-02-26 10:56:50 +00:00
} /**/
translate ( [ 0 , 0 , ( ( length / 2 ) + ( ( mSize * 1.25 ) / 2 ) ) * - 1 ] )
union ( ) {
translate ( [ 0 , 0 , 0 ] )
metricSocketScrew ( mSize , length , structural = structural , recessCap = recessCap , chamfer = chamfer , overrideCapSize = overrideCapSize ) ;
metricBoltHex ( mSize , structural , recessNut = recessNut , recessNutIsCircleMM = recessNutIsCircleMM , chamfer = chamfer ) ;
2021-08-18 23:45:53 +00:00
}
2024-02-26 10:56:50 +00:00
}
module metricCapheadAndNutsert ( mSize , length = 40 , nutsertLength = 13 , mSizeRatio = 1.35 , structural = false , recessCap = 0 , chamfer = false , overrideCapSize = 0 ) {
capSize = overrideCapSize > 0 ? overrideCapSize : ( mSize * capSizeMSizeMultiplier ) + printingKerfMM ;
2021-10-17 19:21:17 +00:00
translate ( [ 0 , 0 , ( ( length / 2 ) + ( ( mSize * 1.25 ) / 2 ) ) * - 1 ] )
union ( ) {
translate ( [ 0 , 0 , 0 ] )
2024-02-26 10:56:50 +00:00
metricSocketScrew ( mSize , length , structural = structural , recessCap = recessCap , chamfer = chamfer , overrideCapSize = overrideCapSize ) ;
metricThreadedNutsert ( mSize , length = nutsertLength , mSizeRatio = mSizeRatio ) ;
2021-10-17 19:21:17 +00:00
}
2021-08-18 23:45:53 +00:00
}
2024-02-26 10:56:50 +00:00
module metricThreadedNutsert ( mSize , length = 13 , mSizeRatio = 1.35 ) {
width = mSize * mSizeRatio ;
translate ( [ 0 , 0 , - 1 ] ) {
translate ( [ 0 , 0 , length / 2 ] )
cylinder ( h = length , d = width , center = true ) ;
translate ( [ 0 , 0 , length / 8 / 2 ] )
cylinder ( h = length / 8 , d2 = width , d1 = width * 1.1 , center = true ) ;
}
}
2021-10-17 19:21:17 +00:00
/**/
translate ( [ 0 , 10 , 0 ] )
metricCapheadAndBolt ( 6 , 40 ) ;
2021-08-18 23:45:53 +00:00
2024-02-26 10:56:50 +00:00
translate ( [ 0 , 10 , 0 ] )
metricCapheadAndBolt ( 6 , 40 , recessNut = 20 , recessNutIsCircleMM = 20 ) ;
2021-10-17 19:21:17 +00:00
translate ( [ 20 , 10 , 0 ] )
metricCapheadAndBolt ( 6 , 40 , recessNut = 1 , recessCap = 1 , chamfer = true ) ;
2024-02-26 10:56:50 +00:00
translate ( [ 40 , 10 , 0 ] ) {
metricCapheadAndNutsert ( 6 , 40 , 13 , recessCap = 1 , chamfer = true ) ;
}
translate ( [ 60 , 10 , 0 ] ) {
metricSocketScrewSlot ( 6 , 40 , 10 ) ;
}
2021-10-17 19:21:17 +00:00
/**/
2021-09-09 09:27:59 +00:00
/*
2021-08-18 23:45:53 +00:00
translate ( [ 0 , 10 , 0 ] )
metricCapheadAndBolt ( 6 , 20 , recessNut = 10 , recessCap = 10 ) ;
2021-09-09 09:27:59 +00:00
/*
2021-08-18 23:45:53 +00:00
translate ( [ 0 , 20 , 0 ] )
metricCapheadAndBolt ( 6 , 20 , chamfer = true ) ;
translate ( [ 20 , 0 , 0 ] )
metricCapheadAndBolt ( 10 , 40 ) ;
translate ( [ 20 , 20 , 0 ] )
metricCapheadAndBolt ( 10 , 40 , recessNut = 10 , recessCap = 10 ) ;
translate ( [ 20 , 40 , 0 ] )
metricCapheadAndBolt ( 10 , 40 , chamfer = true ) ;
* /