"""Parametric eight-hole circular flange generated with build123d.""" from math import cos, radians, sin from build123d import Align, BuildPart, Cylinder, Location, Locations, Mode OUTER_DIAMETER_MM = 50.0 INNER_DIAMETER_MM = 20.0 THICKNESS_MM = 4.0 BOLT_HOLE_COUNT = 8 M3_CLEARANCE_DIAMETER_MM = 3.4 BOLT_CIRCLE_DIAMETER_MM = 40.0 def polar_point(radius: float, angle_degrees: float) -> tuple[float, float]: angle = radians(angle_degrees) return radius * cos(angle), radius * sin(angle) def gen_step(): """Return one STEP-ready flange solid in millimeters.""" with BuildPart() as flange: Cylinder( radius=OUTER_DIAMETER_MM / 2.0, height=THICKNESS_MM, align=(Align.CENTER, Align.CENTER, Align.MIN), ) with Locations(Location((0.0, 0.0, -1.0))): Cylinder( radius=INNER_DIAMETER_MM / 2.0, height=THICKNESS_MM + 2.0, align=(Align.CENTER, Align.CENTER, Align.MIN), mode=Mode.SUBTRACT, ) for index in range(BOLT_HOLE_COUNT): angle_degrees = 360.0 * index / BOLT_HOLE_COUNT x_pos, y_pos = polar_point(BOLT_CIRCLE_DIAMETER_MM / 2.0, angle_degrees) with Locations(Location((x_pos, y_pos, -1.0))): Cylinder( radius=M3_CLEARANCE_DIAMETER_MM / 2.0, height=THICKNESS_MM + 2.0, align=(Align.CENTER, Align.CENTER, Align.MIN), mode=Mode.SUBTRACT, ) part = flange.part part.label = "flange_8x_m3_clearance" return part