kcl-samples → socket-head-cap-screw →
socket-head-cap-screw
KCL
// Socket Head Cap Screw
// This is for a #10-24 screw that is 1.00 inches long. A socket head cap screw is a type of fastener that is widely used in a variety of applications requiring a high strength fastening solution. It is characterized by its cylindrical head and internal hexagonal drive, which allows for tightening with an Allen wrench or hex key.
// Define constants
screwLength = 1.0
screwDiameter = .190
headDiameter = .313
headLength = screwDiameter
hexWallToWall = 5 / 32
capRatio = screwDiameter / headDiameter
hexRatio = hexWallToWall / headDiameter
hexWallLength = hexWallToWall / 2 * 1 / cos(toRadians(30))
hexStartingAngle = 210 // first angle of hex pattern
hexInteriorAngle = 120
hexChangeAngle = 180 - hexInteriorAngle
// Write a function that defines the Socket Head Cap Screw
fn capScrew(start, length, dia, capHeadLength) {
// Create the head of the cap screw
screwHeadSketch = startSketchOn('XZ')
|> circle({
center = [start[0], start[1]],
radius = dia / capRatio / 2
}, %)
// Extrude the screw head sketch
screwHead = extrude(capHeadLength, screwHeadSketch)
// Define the sketch of the hex pattern on the screw head
hexPatternSketch = startSketchOn(screwHead, 'end')
|> startProfileAt([hexWallToWall / 2, 0], %)
|> yLine(-hexWallLength / 2, %)
|> angledLine({
angle = hexStartingAngle,
length = hexWallLength
}, %)
|> angledLine({
angle = hexStartingAngle - hexChangeAngle,
length = hexWallLength
}, %)
|> angledLine({
angle = hexStartingAngle - (2 * hexChangeAngle),
length = hexWallLength
}, %)
|> angledLine({
angle = hexStartingAngle - (3 * hexChangeAngle),
length = hexWallLength
}, %)
|> angledLine({
angle = hexStartingAngle - (4 * hexChangeAngle),
length = hexWallLength
}, %)
|> close(%)
hexPattern = extrude(-headLength * 0.75, hexPatternSketch)
screwBodySketch = startSketchOn(screwHead, "start")
|> circle({
center = [start[0], start[1]],
radius = dia / 2
}, %)
screwBody = extrude(length, screwBodySketch)
return screwBody
}
capScrew([0, 0], screwLength, screwDiameter, screwDiameter)