SCAD (17 lines)
// M8 六角ボルト(単位: mm、ねじ山省略)
head_across_flats = 13;
head_height = 5.3;
shank_diameter = 8;
shank_length = 30;
// 正六角形の外接円半径 = 対辺距離 / (2 * cos(30°))
head_radius = head_across_flats / (2 * cos(30));
union() {
// 頭部: z = 0 ~ 5.3
cylinder(h = head_height, r = head_radius, $fn = 6);
// シャンク: z = -30 ~ 0
translate([0, 0, -shank_length])
cylinder(h = shank_length, d = shank_diameter, $fn = 96);
}