Duncan Wither

Home Notes Github LinkedIn

OpenSCAD

The Open SCAD Tutorial is excellent, as is the cheatsheet.

$fa

There are special variables $fa, $fs and $fs. Adjust the first two if your circles are looking like pentagons, or other polygons. Normally I’ll have the following at the top of a file:

$fa = 1; //Adjust for Render /uality.
$fs = 0.1;

Small values look better, but take longer to render. See the reference material on the subject.

Notes / Why OpenSCAD?

Open Scad is an interesting CAD package because it’s more programmable. Your objects are generated based on a list of commands you give it. Thus all your software tools (like version control) work with wonders it.

I used it to create the primitive shell for the [[1 - Mechanical Hardware|Ping Pong Light]] project, however I found the lack of several features inferior to a traditional CAD package. Shelling for instance had to be done manually.

I did like the scripting aspects though, like for loops etc:

// Adding the Ping Pong Balls:
for (row = [0:4]){
    for (col = [0:5]) {
        r = crad + 20+1; // 1 for the LED
        theta = 90 * col/6 + 90/12;
        
        x = r * cos (theta);
        y = r * sin (theta);
        z = 40 * row+20;
        translate([x,y,z])
            sphere(38/2);
    }
}   

Notes:

Function for creating 2D arc points.

function arc(rad,ang,points) = [ for (i=[0:(ang/points):ang]) [rad*sin(i),rad*cos(i)]];

Reverse a list:

function reverse(list) = [for (i = [len(list)-1:-1:0]) list[i]];

Cumulative sum of a list, courtesy of the tips and tricks page:

cumsum2 = [ for (a=0, b=values[0]; a < len(values); a= a+1, b=b+(values[a]==undef?0:values[a])) b];

Conditionally assign a variable value (valueA when i>0 and valueB otherwise):

var = i > 0 ? valueA : valueB;