"""ISO 10642 (DIN 7991) countersunk socket screw. Envelope: 90 degree head and plain shank in one revolved profile, hex socket. The head's top face is on the XY plane at the origin; `length` is the overall length.""" from steve import Model size = "M4" # Thread size length = 12 # mm Overall length (head included) # size: (head diameter dk, head height k, hex key s) HEADS = { 'M3': (6.72, 1.86, 2.0), 'M4': (8.96, 2.48, 2.5), 'M5': (11.2, 3.1, 3.0), 'M6': (13.44, 3.72, 4.0), 'M8': (17.92, 4.96, 5.0), 'M10': (22.4, 6.2, 6.0), 'M12': (26.88, 7.44, 8.0), } NOMINAL = { 'M3': 3.0, 'M4': 4.0, 'M5': 5.0, 'M6': 6.0, 'M8': 8.0, 'M10': 10.0, 'M12': 12.0, } dk, k, s = HEADS[size] d = NOMINAL[size] cone = (dk - d) / 2 # 90 degree countersink: as deep as it is wide total = max(length, cone + 0.5) model = Model() with model.sketch("profile", on="XZ", name="Profile") as sk: sk.polyline("outline", [(0, 0), (dk / 2, 0), (d / 2, -cone), (d / 2, -total), (0, -total)]) model.revolve("body", "profile", axis="Z") with model.sketch("socket_sketch", on="XY", name="Hex socket") as sk: sk.polygon("hex", (0, 0), s / 2, 6, inscribed=False) model.extrude("socket", "socket_sketch", distance=-0.8 * k, op="cut") result = model.result()