-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket-head-cap-screw.kcl
67 lines (59 loc) · 2.22 KB
/
socket-head-cap-screw.kcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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.000
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)