2025-03-06 18:01:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// Shelf Bracket
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// 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.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Set units
							 
						 
					
						
							
								
									
										
										
										
											2025-05-06 08:44:03 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								@settings(defaultLengthUnit = in, kclVersion = 1.0)
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Define parameters
							 
						 
					
						
							
								
									
										
										
										
											2025-03-06 18:01:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								sigmaAllow = 35000 // psi (6061-T6 aluminum)
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								width = 5.0
							 
						 
					
						
							
								
									
										
										
										
											2025-03-06 18:01:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								p = 300 // Force on shelf - lbs
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								fos = 1.2 // Factor of safety of 1.2
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								shelfMountLength = 5.0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								wallMountLength = 2.25
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								shelfDepth = 12 // Shelf is 12 inches deep from the wall
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								shelfMountingHoleDiameter = .50
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								wallMountingHoleDiameter = .625
							 
						 
					
						
							
								
									
										
										
										
											2025-03-06 18:01:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Calculated parameters
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								moment = shelfDepth * p // assume the force is applied at the end of the shelf
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								thickness = sqrt(moment * fos * 6 / (sigmaAllow * width)) // required thickness for two brackets to hold up the shelf
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bendRadius = 0.25
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								extBendRadius = bendRadius + thickness
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								filletRadius = .5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								shelfMountingHolePlacementOffset = shelfMountingHoleDiameter * 1.5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								wallMountingHolePlacementOffset = wallMountingHoleDiameter * 1.5
							 
						 
					
						
							
								
									
										
										
										
											2025-03-26 08:53:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Add checks to ensure bracket is possible. These make sure that there is adequate distance between holes and edges.
							 
						 
					
						
							
								
									
										
										
										
											2025-04-22 12:44:52 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								assert(wallMountLength, isGreaterThanOrEqual = wallMountingHoleDiameter * 3, error = "Holes not possible. Either decrease hole diameter or increase wallMountLength")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								assert(shelfMountLength, isGreaterThanOrEqual = shelfMountingHoleDiameter * 5.5, error = "wallMountLength must be longer for hole sizes to work. Either decrease mounting hole diameters or increase shelfMountLength")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								assert(width, isGreaterThanOrEqual = shelfMountingHoleDiameter * 5.5, error = "Holes not possible. Either decrease hole diameter or increase width")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								assert(width, isGreaterThanOrEqual = wallMountingHoleDiameter * 5.5, error = "Holes not possible. Either decrease hole diameter or increase width")
							 
						 
					
						
							
								
									
										
										
										
											2025-03-06 18:01:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Create the body of the bracket
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bracketBody = startSketchOn(XZ)
							 
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> startProfile(at = [0, 0])
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> xLine(length = shelfMountLength - thickness, tag = $seg01)
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 23:38:51 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> yLine(length = thickness, tag = $seg02)
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> xLine(length = -shelfMountLength, tag = $seg03)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  |> yLine(length = -wallMountLength, tag = $seg04)
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 23:38:51 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> xLine(length = thickness, tag = $seg05)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  |> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg06)
							 
						 
					
						
							
								
									
										
										
										
											2025-03-06 18:01:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								  |> close()
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 23:38:51 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> extrude(%, length = width)
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Add mounting holes to mount to the shelf
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								shelfMountingHoles = startSketchOn(bracketBody, face = seg03)
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> circle(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       center = [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         -(bendRadius + shelfMountingHolePlacementOffset),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         shelfMountingHolePlacementOffset
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       radius = shelfMountingHoleDiameter / 2,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  |> patternLinear2d(instances = 2, distance = -(extBendRadius + shelfMountingHolePlacementOffset) + shelfMountLength - shelfMountingHolePlacementOffset, axis = [-1, 0])
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  |> patternLinear2d(instances = 2, distance = width - (shelfMountingHolePlacementOffset * 2), axis = [0, 1])
							 
						 
					
						
							
								
									
										
										
										
											2025-03-26 08:53:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> extrude(%, length = -thickness - .01)
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 23:38:51 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Add mounting holes to mount to the wall
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								wallMountingHoles = startSketchOn(bracketBody, face = seg04)
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> circle(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       center = [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         wallMountLength - wallMountingHolePlacementOffset - bendRadius,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         wallMountingHolePlacementOffset
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       radius = wallMountingHoleDiameter / 2,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  |> patternLinear2d(instances = 2, distance = width - (wallMountingHolePlacementOffset * 2), axis = [0, 1])
							 
						 
					
						
							
								
									
										
										
										
											2025-03-26 08:53:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  |> extrude(%, length = -thickness - 0.1)
							 
						 
					
						
							
								
									
										
										
										
											2025-04-11 12:27:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Apply bends
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fillet(bracketBody, radius = extBendRadius, tags = [getNextAdjacentEdge(seg03)])
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fillet(bracketBody, radius = bendRadius, tags = [getNextAdjacentEdge(seg06)])
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Apply corner fillets
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fillet(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  bracketBody,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  radius = filletRadius,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  tags = [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    seg02,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    getOppositeEdge(seg02),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    seg05,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    getOppositeEdge(seg05)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								)