Core Concept: Relative Sizing and Positioning
masterThe relativity.scad library introduces a set of modules designed to replace standard OpenSCAD primitives. These new primitives allow objects and their children to align and size themselves relative to their parent's dimensions using the $parent_size variable.
Instead of manually calculating offsets using hardcoded dimensions (e.g., translate([cube_h/2, 0, 0])), you can use anchor parameters and the align() module to position objects based on their own geometry and the geometry of their parents.
// Standard OpenSCAD approach (manual calculation)
cube_h=10;
cylinder_d=7;
translate([0,0,cube_h/2]){
cube(cube_h, center=true);
translate([cube_h/2 + cylinder_d/2,0,0])
cylinder(d=cylinder_d, h=cube_h, center=true);
}
// relativity.scad approach (relative positioning)
box(10, anchor=[0,0,-1])
align([1,0,0])
rod(d=7, h=$parent_size.z);