B
OpenSCAD Visual Reference

This appendix is a quick visual reference for drawing, transforming, and combining the 3D and 2D shapes covered in this book. Paired with each screenshot is an example OpenSCAD statement that can be used to generate the image. In some cases, we’ve included a “shadow” object to illustrate what shapes looked like before an operation took place. Example code statements don’t generate these shadow objects.

3D Primitives

Cuboid:

cube([30, 20, 10]);
fb03001

Centered cuboid:

cube([30, 20, 10], center=true); 
fb03002

Sphere:

sphere(10); 
fb03003

Smooth sphere:

sphere(10, $fn=100); 
fb03004

Cylinder:

cylinder(h=20, r=5); 
fb03005

Cone:

cylinder(h=20, r1=5, r2=0); 
fb03006

Centered smooth truncated cone:

cylinder(h=10, r1=3, r2=5, $fn=100, center=true); 
fb03007

Regular prism:

cylinder(h=5, r=5, $fn=6); 
fb03008

2D Shapes

Rectangle:

square([30, 20]); 
fb03009

Centered rectangle:

square([30, 20], center=true); 
fb03010

Circle:

circle(10); 
fb03011

Regular polygon:

circle(10, $fn=5);
fb03012

Irregular polygon:

polygon([[0,0], [10,0], [10,10], [5,10]]); 
fb03013

Text:

text("hello", font="Sans", size=20);
fb03014

Combining Shapes

Subtracting from a shape:

difference() {
  sphere(10);
  translate([0,-15,0]) cube([15,30,15]);
}
fb03015

Multiple subtractions from a shape:

difference() {
  sphere(10);
    
  cube([15, 15, 15]);
  cylinder(h=15, r=5); 
}
fb03016

Intersection of two shapes:

intersection() {
  cube([10, 10, 10]);
  cylinder(h=15, r=5); 
}
fb03017

Subtracting from combined shapes:

difference() {
  union() {
      sphere(10);
      cylinder(h=30, r=5, center=true); 
  }
  cube([10, 30, 10], center=true);
}
fb03018

Convex hull:

hull() {
    sphere(10);
    cylinder(h=20, r=5); 
}
fb03019

Minkowski sum:

minkowski() {
    sphere(10, $fn=50);
    cylinder(h=20, r=5); 
}
fb03020

Transformations

Translation:

translate([5, 10, 0]) cube([5, 3, 1]); 
fb03021

Rotation:

rotate([0, 0, 60]) cube([30, 20, 10]);
fb03022

Reflection:

mirror([1, 0, 0]) translate([5, 0, 0]) cylinder(h=1, r=5, $fn=5); 
fb03023

Resize dimensions:

resize([15, 20, 4]) sphere(r=5, $fn=32); 
fb03024

Extrude a 2D shape:

linear_extrude(height=10) {
    polygon([[0, 0], [10, 0], 
             [10, 10], [5, 10]]); 
}
fb03025

Rotate an extrusion of a 2D shape:

rotate_extrude(angle=180) translate([10, 0]) circle(5);
fb03026

Loops

Repeat a shape:

for (x=[0:10:40]) {
    translate([x, 0, 0]) cube([5, 5, 10]);
}
fb03027

Vary characteristics of a repeated shape:

for (x=[0:1:4]) {
    h = x*5 + 5;
    translate([x*10, 0, 0]) cube([5, 5, h]);
}
fb03028

Repeat the repetition of a shape:

for (z=[0:15:45]) {
  for (x=[0:10:40]) {
    translate([x, 0, z]) cube([5, 5, 10]);
  }
}
fb03029
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.89.85