relativity.scad OpenSCAD Library

repository·master·Indexed 41 days ago

https://github.com/davidson16807/relativity.scad

An OpenSCAD library for relative sizing, positioning, and orientation of geometric primitives. It enables the separation of structural model definitions from final presentation and assembly using the $parent_size variable, anchor parameters, and the align() module.

Tokens
793
Snippets
2
Records
3
Agent score
2%

What's inside relativity.scad

  1. Core Concept: Relative Sizing and Positioning

    master

    The 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);
  2. Separating Presentation from Content

    master

    The library implements a pattern similar to CSS for HTML, allowing you to separate the definition of a model (content) from how it is rendered (presentation).

    • Content Layer: Define all parts of a project and how they interact (e.g., using attachment points).
    • Presentation Layer: Use CSG operations like show, hide, or attach to isolate specific parts for printing or to assemble components like Lego blocks.
  3. Reference: CSG Operations Modules

    master

    The library provides several modules to perform Constructive Solid Geometry (CSG) operations based on object classes. These allow for complex pattern generation and visibility control.

    Module | Description
    --------- --------------
    mirrored | form bilaterally symmetric objects using the `mirror()` function 
    rotated | form radially symmetric objects by repeated calls to `rotate()` 
    translated | form repeating patterns by repeated calls to `translate() `
    hulled | performs `hull` between objects of a given class
    intersected | performs `difference` between objects of a given class
    differed | performs `difference` between one class of objects and another
    show | renders only the specified class 
    hide | renders everything but the specified class 
    attach | attaches child to the parent at an attachment point of a given class