code wiki / (root) / nx_vessel_csg.nx

nx_vessel_csg.nx source

↩ module page · 45 lines · 2170 B

1// nx_vessel_csg.nx -- C1 of the VESSEL-DESIGN ladder: the printable VESSEL 2// SOLID, as constructive solid geometry. A fermentation cup is an outer 3// cylinder MINUS an inner cavity (raised off the floor to leave a base, 4// extended past the rim to leave the top open) -- a watertight SDF solid, 5// pipeline-native to nx_csg_extract_scene -> nx_stl_write_mesh -> slicer. 6// 7// Per the under-ridge lesson, geometry is PROVEN by cheap field-sampling + 8// nx_csg_scene_count_inside (a hollow cup has strictly less material than 9// the solid cylinder), NOT by an OOM-prone high-res mesh. The mesh emit is 10// a separate, low-res manufacturing step. 11// 12// Composes the existing sovereign CAD stack (nx_sdf primitives + nx_csg 13// booleans + nx_csg_scene fold); adds no geometry math. 14// 15// genealogy_id: constructive_solid_geometry + nishi_csg_scene_2026 16 17import "nx_syscalls.nx" 18import "nx_sdf.nx" 19import "nx_csg.nx" 20import "nx_csg_scene.nx" 21 22const NX_VC_Q14: i64 = 16384 // 1 mm in Q14-mm 23 24// Build a hollow cylindrical vessel (cup). All inputs in mm. 25// outer_r_mm outer radius wall_mm wall thickness 26// height_mm overall height base_mm floor thickness 27// Returns a CSG scene = outer cylinder DIFF inner cavity. 28func nx_vessel_csg_build(outer_r_mm: i64, wall_mm: i64, 29 height_mm: i64, base_mm: i64) -> *NxCsgScene { 30 let half: i64 = height_mm / 2 31 let r_out: i64 = outer_r_mm * NX_VC_Q14 32 let r_in: i64 = (outer_r_mm - wall_mm) * NX_VC_Q14 33 let h_half: i64 = half * NX_VC_Q14 34 // cavity sits base_mm above the floor and runs 20 mm past the rim (open top) 35 let cav_bottom: i64 = (0 - half) + base_mm 36 let cav_top: i64 = half + 20 37 let cav_cz: i64 = ((cav_bottom + cav_top) / 2) * NX_VC_Q14 38 let cav_hh: i64 = ((cav_top - cav_bottom) / 2) * NX_VC_Q14 39 let outer: *NxSdfPrim = nx_sdf_make(NX_SDF_CYL, 0, 0, 0, r_out, h_half, 0) 40 let cavity: *NxSdfPrim = nx_sdf_make(NX_SDF_CYL, 0, 0, cav_cz, r_in, cav_hh, 0) 41 let s: *NxCsgScene = nx_csg_scene_new(4) 42 nx_csg_scene_add(s, outer, NX_CSG_UNION, 0) // seed 43 nx_csg_scene_add(s, cavity, NX_CSG_DIFF, 0) // hollow it out 44 return s 45}