"""Parallel pin (dowel pin), ISO 2338 (DIN 7), d 0.6 to 50 mm, any length. A cylinder of the nominal diameter d and length l with an end chamfer c (ISO 2338 gives c as an approximate value; drawn here at 45 degrees) on both ends. One end face is on the XY plane at the origin, the pin along +Z. """ from steve import Model diameter = 4 # mm Nominal diameter d length = 20 # mm Length l material = "steel" # Material # ISO 2338:1997 table (DIN EN ISO 2338:1998-02, https://www.fasten.it/en/Norms/Norm/DIN%20EN%20ISO%202338). d: c (approximate end chamfer) CHAMFERS = { 0.6: 0.12, 0.8: 0.16, 1: 0.2, 1.2: 0.25, 1.5: 0.3, 2: 0.35, 2.5: 0.4, 3: 0.5, 4: 0.63, 5: 0.8, 6: 1.2, 8: 1.6, 10: 2.0, 12: 2.5, 16: 3.0, 20: 3.5, 25: 4.0, 30: 5.0, 40: 6.3, 50: 8.0, } # material choice: (STEVE material library id, appearance colour) MATERIALS = { "steel": ("steel-generic", "#b4b7bb"), # ISO 2338 steel (unhardened) "stainless-a1": ("stainless-304", "#c9ccd0"), # austenitic stainless (A1) } if diameter not in CHAMFERS: raise ValueError(f"ISO 2338 has no diameter {diameter} mm; diameters: {', '.join(str(k) for k in CHAMFERS)}") c = CHAMFERS[diameter] if length <= 2 * c: raise ValueError(f"length must be more than twice the end chamfer ({2 * c} mm)") r = diameter / 2 material_id, colour = MATERIALS[material] model = Model() with model.sketch("profile", on="XZ", name="Profile") as sk: sk.polyline("outline", [(0, 0), (r - c, 0), (r, c), (r, length - c), (r - c, length), (0, length)]) model.revolve("pin", "profile", axis="Z", name="Pin") model.material(material_id, color=colour) result = model.result()