2024-03-15 23:10:34 -07:00
export const bracket = ` // Shelf Bracket
2024-09-13 08:24:31 -07:00
// This is a bracket that holds a shelf. It is made of aluminum and is designed to hold a force of 300 lbs. The bracket is 6 inches wide and the force is applied at the end of the shelf, 12 inches from the wall. The bracket has a factor of safety of 1.2. The legs of the bracket are 5 inches and 2 inches long. The thickness of the bracket is calculated from the constraints provided.
2023-09-15 22:37:40 -04:00
2024-09-23 22:42:51 +10:00
2024-09-13 08:24:31 -07:00
// Define constants
2024-12-06 16:04:17 -05:00
sigmaAllow = 35000 // psi (6061-T6 aluminum)
width = 6 // inch
p = 300 // Force on shelf - lbs
factorOfSafety = 1.2 // FOS of 1.2
shelfMountL = 5 // inches
wallMountL = 2 // inches
shelfDepth = 12 // Shelf is 12 inches in depth from the wall
moment = shelfDepth * p // assume the force is applied at the end of the shelf to be conservative (lb-in)
2024-03-15 16:05:26 -07:00
2024-09-23 22:42:51 +10:00
2024-12-06 16:04:17 -05:00
filletRadius = . 375 // inches
extFilletRadius = . 25 // inches
mountingHoleDiameter = 0.5 // inches
2024-03-15 23:10:34 -07:00
2024-09-23 22:42:51 +10:00
2024-09-13 08:24:31 -07:00
// Calculate required thickness of bracket
2024-12-06 16:04:17 -05:00
thickness = sqrt ( moment * factorOfSafety * 6 / ( sigmaAllow * width ) ) // this is the calculation of two brackets holding up the shelf (inches)
2024-03-15 23:10:34 -07:00
2024-09-23 22:42:51 +10:00
2024-09-13 08:24:31 -07:00
// Sketch the bracket body and fillet the inner and outer edges of the bend
2024-12-06 16:04:17 -05:00
bracketLeg1Sketch = startSketchOn ( 'XY' )
2024-03-15 23:10:34 -07:00
| > startProfileAt ( [ 0 , 0 ] , % )
2024-09-23 22:42:51 +10:00
| > line ( [ shelfMountL - filletRadius , 0 ] , % , $fillet1 )
2024-09-13 08:24:31 -07:00
| > line ( [ 0 , width ] , % , $fillet2 )
| > line ( [ - shelfMountL + filletRadius , 0 ] , % )
2024-03-15 23:10:34 -07:00
| > close ( % )
2024-09-23 22:42:51 +10:00
| > hole ( circle ( {
2024-12-06 13:57:31 +13:00
center = [ 1 , 1 ] ,
radius = mountingHoleDiameter / 2
2024-09-23 22:42:51 +10:00
} , % ) , % )
| > hole ( circle ( {
2024-12-06 13:57:31 +13:00
center = [ shelfMountL - 1.5 , width - 1 ] ,
radius = mountingHoleDiameter / 2
2024-09-23 22:42:51 +10:00
} , % ) , % )
| > hole ( circle ( {
2024-12-06 13:57:31 +13:00
center = [ 1 , width - 1 ] ,
radius = mountingHoleDiameter / 2
2024-09-23 22:42:51 +10:00
} , % ) , % )
| > hole ( circle ( {
2024-12-06 13:57:31 +13:00
center = [ shelfMountL - 1.5 , 1 ] ,
radius = mountingHoleDiameter / 2
2024-09-23 22:42:51 +10:00
} , % ) , % )
2024-09-13 08:24:31 -07:00
// Extrude the leg 2 bracket sketch
2024-12-06 16:04:17 -05:00
bracketLeg1Extrude = extrude ( thickness , bracketLeg1Sketch )
2024-03-15 16:05:26 -07:00
| > fillet ( {
2024-12-06 13:57:31 +13:00
radius = extFilletRadius ,
tags = [
2024-09-23 22:42:51 +10:00
getNextAdjacentEdge ( fillet1 ) ,
getNextAdjacentEdge ( fillet2 )
]
} , % )
2024-09-13 08:24:31 -07:00
// Sketch the fillet arc
2024-12-06 16:04:17 -05:00
filletSketch = startSketchOn ( 'XZ' )
2024-09-13 08:24:31 -07:00
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , thickness ] , % )
| > arc ( {
2024-12-06 13:57:31 +13:00
angleEnd = 180 ,
angleStart = 90 ,
radius = filletRadius + thickness
2024-09-23 22:42:51 +10:00
} , % )
2024-09-13 08:24:31 -07:00
| > line ( [ thickness , 0 ] , % )
| > arc ( {
2024-12-06 13:57:31 +13:00
angleEnd = 90 ,
angleStart = 180 ,
radius = filletRadius
2024-09-23 22:42:51 +10:00
} , % )
2024-09-13 08:24:31 -07:00
// Sketch the bend
2024-12-06 16:04:17 -05:00
filletExtrude = extrude ( - width , filletSketch )
2024-09-13 08:24:31 -07:00
// Create a custom plane for the leg that sits on the wall
2024-12-06 16:04:17 -05:00
customPlane = {
2024-12-06 13:57:31 +13:00
plane = {
origin = { x = - filletRadius , y = 0 , z = 0 } ,
xAxis = { x = 0 , y = 1 , z = 0 } ,
yAxis = { x = 0 , y = 0 , z = 1 } ,
zAxis = { x = 1 , y = 0 , z = 0 }
2024-09-13 08:24:31 -07:00
}
}
// Create a sketch for the second leg
2024-12-06 16:04:17 -05:00
bracketLeg2Sketch = startSketchOn ( customPlane )
2024-09-13 08:24:31 -07:00
| > startProfileAt ( [ 0 , - filletRadius ] , % )
| > line ( [ width , 0 ] , % )
| > line ( [ 0 , - wallMountL ] , % , $fillet3 )
| > line ( [ - width , 0 ] , % , $fillet4 )
| > close ( % )
2024-09-23 22:42:51 +10:00
| > hole ( circle ( {
2024-12-06 13:57:31 +13:00
center = [ 1 , - 1.5 ] ,
radius = mountingHoleDiameter / 2
2024-09-23 22:42:51 +10:00
} , % ) , % )
| > hole ( circle ( {
2024-12-06 13:57:31 +13:00
center = [ 5 , - 1.5 ] ,
radius = mountingHoleDiameter / 2
2024-09-23 22:42:51 +10:00
} , % ) , % )
2024-09-13 08:24:31 -07:00
// Extrude the second leg
2024-12-06 16:04:17 -05:00
bracketLeg2Extrude = extrude ( - thickness , bracketLeg2Sketch )
2024-03-15 23:10:34 -07:00
| > fillet ( {
2024-12-06 13:57:31 +13:00
radius = extFilletRadius ,
tags = [
2024-09-23 22:42:51 +10:00
getNextAdjacentEdge ( fillet3 ) ,
getNextAdjacentEdge ( fillet4 )
]
} , % )
`
2024-03-29 12:56:32 -04:00
2024-08-19 15:36:18 -04:00
/ * *
* @throws Error if the search text is not found in the example code .
* /
2024-03-29 12:56:32 -04:00
function findLineInExampleCode ( {
searchText ,
example = bracket ,
} : {
searchText : string
example? : string
} ) {
const lines = example . split ( '\n' )
const lineNumber = lines . findIndex ( ( l ) = > l . includes ( searchText ) ) + 1
if ( lineNumber === 0 ) {
2024-08-19 15:36:18 -04:00
// We are exporting a constant, so we don't want to return an Error.
// eslint-disable-next-line suggest-no-throw/suggest-no-throw
2024-03-29 12:56:32 -04:00
throw new Error (
` Could not find the line with search text " ${ searchText } " in the example code. Was it removed? `
)
}
return lineNumber
}
export const bracketWidthConstantLine = findLineInExampleCode ( {
2024-12-06 16:04:17 -05:00
searchText : 'width =' ,
2024-03-29 12:56:32 -04:00
} )
export const bracketThicknessCalculationLine = findLineInExampleCode ( {
2024-12-06 16:04:17 -05:00
searchText : 'thickness =' ,
2024-03-29 12:56:32 -04:00
} )