"""Hexagon socket button head screw, ISO 7380-1, M3 to M16, any length. Envelope model for assemblies: domed head (a spherical cap of diameter dk max and height k max), hexagon socket (key size s, depth t min) and a plain shank at the nominal thread diameter d (the thread is not modelled). The head's bearing face is on the XY plane at the origin, the head above it, the shank along -Z; `length` is the nominal length l, measured from under the head. """ import math from steve import Model size = "M5" # Thread size length = 10 # mm Nominal length (under the head) material = "steel" # Material # ISO 7380-1:2011, Table 1 (official preview p. 3: # https://cdn.standards.iteh.ai/samples/53671/84df01c5fcce4a91896ac3b0c55ca128/ISO-7380-1-2011.pdf); the same values in # ISO 7380-1:2022, Table 1 (https://cdn.standards.iteh.ai/samples/78699/a175805085534f98983d6c8aa583a5b0/ISO-7380-1-2022.pdf). size: (thread d, head diameter dk max, head height k max, hexagon socket s, socket depth t min) DIMENSIONS = { "M3": (3.0, 5.7, 1.65, 2.0, 1.04), "M4": (4.0, 7.6, 2.2, 2.5, 1.3), "M5": (5.0, 9.5, 2.75, 3.0, 1.56), "M6": (6.0, 10.5, 3.3, 4.0, 2.08), "M8": (8.0, 14.0, 4.4, 5.0, 2.6), "M10": (10.0, 17.5, 5.5, 6.0, 3.12), "M12": (12.0, 21.0, 6.6, 8.0, 4.16), "M16": (16.0, 28.0, 8.8, 10.0, 5.2), } # material choice: (STEVE material library id, appearance colour) MATERIALS = { "steel": ("steel-generic", "#2b2d30"), # property class 10.9 / 12.9, black oxide finish "stainless-a2": ("stainless-304", "#c9ccd0"), # ISO 3506-1 A2-70 "stainless-a4": ("stainless-316", "#c9ccd0"), # ISO 3506-1 A4-70 / A4-80 } d, dk, k, s, t = DIMENSIONS[size] material_id, colour = MATERIALS[material] r = dk / 2 dome_r = (r * r + k * k) / (2 * k) # radius of the spherical cap through the head's rim and top start = math.degrees(math.atan2(dome_r - k, r)) model = Model() with model.sketch("head_profile", on="XZ", name="Head profile") as sk: sk.line("base", (0, 0), (r, 0)) sk.arc("dome", (0, k - dome_r), dome_r, start, 90) sk.line("axis", (0, k), (0, 0)) model.revolve("head", "head_profile", axis="Z", name="Head") with model.sketch("shank_sketch", on="XY", name="Shank") as sk: sk.circle("shank_circle", (0, 0), d / 2) model.extrude("shank", "shank_sketch", distance=-length, name="Shank") model.plane("head_top", on="XY", offset=k, name="Head top") with model.sketch("socket_sketch", on="head_top", name="Hexagon socket") as sk: sk.polygon("hex", (0, 0), s / 2, 6, inscribed=False) model.extrude("socket", "socket_sketch", distance=-t, op="cut", name="Socket") model.material(material_id, color=colour) result = model.result()