import cadquery as cq

sphere_radius = 27.34
stem_base_z = -125.75
stem_radius = 9.84
bore_radius = 6.56
# The original sample stem length is 98.41, ending exactly tangent at z=-27.34.
# Add 2 mm hidden overlap into the sphere for robust fused geometry.
stem_length = 100.41
bore_cut_height = 153.09

primary_body = (
    cq.Workplane("XY")
    .sphere(sphere_radius)
    .union(
        cq.Workplane("XY")
        .transformed(offset=cq.Vector(0.0, 0.0, stem_base_z), rotate=cq.Vector(0, 0, 0))
        .circle(stem_radius)
        .extrude(stem_length)
    )
    .cut(
        cq.Workplane("XY")
        .transformed(offset=cq.Vector(0.0, 0.0, stem_base_z), rotate=cq.Vector(0, 0, 0))
        .cylinder(bore_cut_height, bore_radius)
    )
)

PARTS = {
    "ball_knob_body": primary_body,
}

result = primary_body
r = result
