// Shelf Bracket
// This is a shelf bracket made out of 6061-T6 aluminum sheet metal. The required thickness is calculated based on a point load of 300 lbs applied to the end of the shelf. There are two brackets holding up the shelf, so the moment experienced is divided by 2. The shelf is 1 foot long from the wall.


// Define our bracket feet lengths
shelfMountL = 8 // The length of the bracket holding up the shelf is 6 inches
wallMountL = 6 // the length of the bracket


// Define constants required to calculate the thickness needed to support 300 lbs
sigmaAllow = 35000 // psi
width = 6 // inch
p = 300 // Force on shelf - lbs
L = 12 // inches
M = L * p / 2 // Moment experienced at fixed end of bracket
FOS = 2 // Factor of safety of 2 to be conservative


// Calculate the thickness off the bending stress and factor of safety
thickness = sqrt(6 * M * FOS / (width * sigmaAllow))

// 0.25 inch fillet radius
filletR = 0.25

// Sketch the bracket and extrude with fillets
bracket = startSketchOn('XY')
  |> startProfileAt([0, 0], %)
  |> line(end = [0, wallMountL], tag = $outerEdge)
  |> line(end = [-shelfMountL, 0], tag = $seg01)
  |> line(end = [0, -thickness])
  |> line(end = [shelfMountL - thickness, 0], tag = $innerEdge)
  |> line(end = [0, -wallMountL + thickness])
  |> close(%)
  |> extrude(length = width)
  |> fillet({
       radius = filletR,
       tags = [getNextAdjacentEdge(innerEdge)]
     }, %)
  |> fillet({
       radius = filletR + thickness,
       tags = [getNextAdjacentEdge(outerEdge)]
     }, %)

sketch001 = startSketchOn(bracket, seg01)
  |> startProfileAt([4.28, 3.83], %)
  |> line(end = [2.17, -0.03])
  |> line(end = [-0.07, -1.8])
  |> line(end = [-2.07, 0.05])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close(%)
  |> extrude(length = 10)
