2020-02-26 19:43:02 +00:00
//
// NopSCADlib Copyright Chris Palmer 2020
// nop.head@gmail.com
// hydraraptor.blogspot.com
//
// This file is part of NopSCADlib.
//
// NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with NopSCADlib.
// If not, see <https://www.gnu.org/licenses/>.
//
//! Brackets for joining extrusions at a corner.
2020-02-29 17:52:36 +00:00
include < ../core.scad >
2021-09-03 09:23:24 +01:00
use < extrusion.scad >
2020-02-23 18:15:25 +00:00
2021-09-03 09:23:24 +01:00
function extrusion_inner_corner_bracket_size ( type ) = type [ 1 ] ; //! Size of inner bracket
function extrusion_inner_corner_bracket_tnut ( type ) = type [ 2 ] ; //! The sliding t-nut it is based on
function extrusion_inner_corner_bracket_extrusion ( type ) = type [ 3 ] ; //! Default extrusion this bracket is for
function extrusion_inner_corner_bracket_screw_offsets ( type ) = type [ 4 ] ; //! Screw offsets from the ends
2020-02-23 18:15:25 +00:00
2021-09-05 10:24:42 +01:00
module extrusion_inner_corner_bracket ( type , grub_screws = true , backwards = false , extrusion = undef ) { //! Inner corner bracket for extrusion
extrusion = is_undef ( extrusion ) ? extrusion_inner_corner_bracket_extrusion ( type ) : extrusion ;
2021-09-03 09:23:24 +01:00
vitamin ( str ( "extrusion_inner_corner_bracket(" , type [ 0 ] , "): Extrusion inner corner bracket for " , extrusion [ 0 ] ) ) ;
2020-02-23 18:15:25 +00:00
2020-02-26 19:43:02 +00:00
size = extrusion_inner_corner_bracket_size ( type ) ;
2021-09-03 09:23:24 +01:00
tnut = extrusion_inner_corner_bracket_tnut ( type ) ;
screw_offsets = extrusion_inner_corner_bracket_screw_offsets ( type ) ;
2020-02-23 18:15:25 +00:00
bottomTabOffset = 4 ;
topTabOffset = 10 ;
2021-09-03 09:23:24 +01:00
sizeBottom = [ size . y - bottomTabOffset , nut_square_width ( tnut ) , size . z ] ;
sizeTop = [ size . x - topTabOffset , nut_square_width ( tnut ) , size . z ] ;
tab = t_nut_tab ( tnut ) ;
tabSizeZ = nut_thickness ( tnut ) ;
screw = find_screw ( hs_grub , nut_size ( tnut ) ) ;
holeRadius = screw_pilot_hole ( screw ) ;
depth = ( extrusion_width ( extrusion ) - extrusion_center_square ( extrusion ) ) / 2 ;
offset = extrusion_tab_thickness ( extrusion ) + tabSizeZ ;
offset2 = extrusion_tab_thickness ( extrusion ) - nut_thickness ( tnut , true ) + nut_thickness ( tnut ) ;
translate ( [ backwards ? offset2 : - offset , - offset ] )
2020-02-23 18:15:25 +00:00
rotate ( [ - 90 , 0 , 0 ] ) {
color ( "silver" ) {
2021-09-03 09:23:24 +01:00
translate ( [ ( size . y + bottomTabOffset ) / 2 , 0 , tabSizeZ ] )
2020-02-23 18:15:25 +00:00
rotate ( [ 0 , 180 , 0 ] )
2021-09-03 09:23:24 +01:00
extrusionSlidingNut ( sizeBottom , tab [ 0 ] , tab [ 1 ] , tabSizeZ , holeRadius , ( bottomTabOffset - size . y ) / 2 + screw_offsets . y ) ;
translate ( [ tabSizeZ , 0 , ( size . x + topTabOffset ) / 2 ] )
2020-02-23 18:15:25 +00:00
rotate ( [ 0 , - 90 , 0 ] )
2021-09-03 09:23:24 +01:00
extrusionSlidingNut ( sizeTop , tab [ 0 ] , tab [ 0 ] , tabSizeZ , holeRadius , - ( topTabOffset - size . x ) / 2 - screw_offsets . x ) ;
translate ( [ 0 , - tab [ 1 ] / 2 ] ) {
cube ( [ bottomTabOffset , tab [ 1 ] , size . z ] ) ;
cube ( [ size . z , tab [ 1 ] , topTabOffset ] ) ;
2020-02-23 18:15:25 +00:00
}
}
2020-02-25 22:19:20 +00:00
if ( grub_screws )
2020-02-23 18:15:25 +00:00
not_on_bom ( ) no_explode ( ) {
2021-09-03 09:23:24 +01:00
screw_len = screw_shorter_than ( depth ) ;
gap = depth - screw_len ;
screw_z = offset - gap ;
rotate ( [ 0 , - 90 , 180 ] )
if ( backwards )
translate ( [ size . x - screw_offsets . x , 0 , - offset2 + gap ] )
vflip ( )
screw ( screw , screw_len ) ;
else
translate ( [ size . x - screw_offsets . x , 0 , screw_z ] )
screw ( screw , screw_len ) ;
translate ( [ size . y - screw_offsets . y , 0 , screw_z ] )
screw ( screw , screw_len ) ;
2020-02-23 18:15:25 +00:00
}
}
}
2020-02-25 22:19:20 +00:00
function extrusion_corner_bracket_size ( type ) = type [ 1 ] ; //! Size of bracket
function extrusion_corner_bracket_base_thickness ( type ) = type [ 2 ] ; //! Thickness of base of bracket
function extrusion_corner_bracket_side_thickness ( type ) = type [ 3 ] ; //! Thickness of side of bracket
function extrusion_corner_bracket_hole_offset ( type ) = type [ 4 ] ; //! Hole offset from corner
2021-09-03 09:23:24 +01:00
function extrusion_corner_bracket_tnut ( type ) = type [ 5 ] ; //! The sliding t-nut to use in the assembly
function extrusion_corner_bracket_extrusion ( type ) = type [ 6 ] ; //! Default extrusion this bracket is for
2020-02-23 18:15:25 +00:00
2020-02-25 22:19:20 +00:00
module extrusion_corner_bracket ( type ) { //! Corner bracket for extrusion
2021-09-03 09:23:24 +01:00
vitamin ( str ( "extrusion_corner_bracket(" , type [ 0 ] , "): Extrusion corner bracket " , type [ 1 ] . z , "mm for " , extrusion_corner_bracket_extrusion ( type ) [ 0 ] ) ) ;
2020-02-23 18:15:25 +00:00
2020-02-25 22:19:20 +00:00
eSize = extrusion_corner_bracket_size ( type ) . z ;
cbSize = extrusion_corner_bracket_size ( type ) . x ;
baseThickness = extrusion_corner_bracket_base_thickness ( type ) ;
2021-09-03 09:23:24 +01:00
hole_r = screw_clearance_radius ( find_screw ( hs_cap , nut_size ( extrusion_corner_bracket_tnut ( type ) ) ) ) ;
2020-02-23 18:15:25 +00:00
module base ( ) {
linear_extrude ( baseThickness )
difference ( ) {
2021-09-03 09:23:24 +01:00
translate ( [ 0 , - eSize / 2 ] )
2020-02-23 18:15:25 +00:00
square ( [ cbSize , eSize ] ) ;
2021-09-03 09:23:24 +01:00
2020-02-23 18:15:25 +00:00
hull ( ) {
2021-09-03 09:23:24 +01:00
translate ( [ extrusion_corner_bracket_hole_offset ( type ) + 1.5 , 0 ] )
circle ( hole_r ) ;
translate ( [ extrusion_corner_bracket_hole_offset ( type ) - 1.5 , 0 ] )
circle ( hole_r ) ;
2020-02-23 18:15:25 +00:00
}
}
}
color ( "silver" ) {
rotate ( [ 90 , 0 , 90 ] )
base ( ) ;
2021-09-03 09:23:24 +01:00
translate ( [ 0 , baseThickness ] )
2020-02-23 18:15:25 +00:00
rotate ( [ 90 , 0 , 0 ] )
base ( ) ;
2021-09-03 09:23:24 +01:00
2020-02-25 22:19:20 +00:00
sideThickness = extrusion_corner_bracket_side_thickness ( type ) ;
2020-02-23 18:15:25 +00:00
for ( z = [ - eSize / 2 , eSize / 2 - sideThickness ] ) {
translate_z ( z ) {
right_triangle ( cbSize , cbSize , sideThickness , center = false ) ;
cube ( [ 5 , cbSize , sideThickness ] ) ;
cube ( [ cbSize , 5 , sideThickness ] ) ;
}
}
}
}
2020-02-25 22:19:20 +00:00
module extrusion_corner_bracket_hole_positions ( type ) { //! Place children at hole positions
2020-02-23 18:15:25 +00:00
for ( angle = [ [ 0 , 90 , 0 ] , [ - 90 , - 90 , 0 ] ] )
rotate ( angle )
2020-02-25 22:19:20 +00:00
translate ( [ 0 , extrusion_corner_bracket_hole_offset ( type ) , extrusion_corner_bracket_base_thickness ( type ) ] )
2020-02-23 18:15:25 +00:00
children ( ) ;
}
2021-09-05 10:24:42 +01:00
module extrusion_corner_bracket_assembly ( type , part_thickness = undef , screw_type = undef , nut_type = undef , max_screw_depth = undef , extrusion = undef ) { //! Assembly with fasteners in place
2020-02-25 22:19:20 +00:00
extrusion_corner_bracket ( type ) ;
2021-09-05 10:24:42 +01:00
extrusion = is_undef ( extrusion ) ? extrusion_corner_bracket_extrusion ( type ) : extrusion ;
2021-09-03 09:23:24 +01:00
nut = is_undef ( nut_type ) ? extrusion_corner_bracket_tnut ( type ) : nut_type ;
screw = is_undef ( screw_type ) ? find_screw ( hs_cap , nut_size ( nut ) ) : screw_type ;
thickness = is_undef ( part_thickness ) ? extrusion_tab_thickness ( extrusion ) : part_thickness ;
depth = is_undef ( max_screw_depth ) ? ( extrusion_width ( extrusion ) - extrusion_center_square ( extrusion ) ) / 2 - eps : max_screw_depth ;
2020-02-23 18:15:25 +00:00
2021-09-03 09:23:24 +01:00
screw_washer_thickness = washer_thickness ( screw_washer ( screw ) ) ;
nut_washer_type = nut_washer ( nut ) ;
2020-02-23 18:15:25 +00:00
nut_washer_thickness = nut_washer_type ? washer_thickness ( nut_washer_type ) : 0 ;
2021-09-03 09:23:24 +01:00
nut_offset = extrusion_corner_bracket_base_thickness ( type ) + thickness ;
screw_length = depth ? screw_shorter_than ( extrusion_corner_bracket_base_thickness ( type ) + screw_washer_thickness + depth )
: screw_longer_than ( nut_offset + screw_washer_thickness + nut_washer_thickness + nut_thickness ( nut ) ) ;
2020-02-23 18:15:25 +00:00
2020-02-25 22:19:20 +00:00
extrusion_corner_bracket_hole_positions ( type ) {
2021-09-03 09:23:24 +01:00
screw_and_washer ( screw , screw_length ) ;
2020-02-23 18:15:25 +00:00
translate_z ( - nut_offset )
vflip ( )
if ( nut_washer_type )
2021-09-03 09:23:24 +01:00
nut_and_washer ( nut ) ;
2020-02-23 18:15:25 +00:00
else
rotate ( 90 )
2021-09-03 09:23:24 +01:00
sliding_t_nut ( nut ) ;
2020-02-23 18:15:25 +00:00
}
}