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.
Cuboid:
cube([30, 20, 10]);
Centered cuboid:
cube([30, 20, 10], center=true);
Sphere:
sphere(10);
Smooth sphere:
sphere(10, $fn=100);
Cylinder:
cylinder(h=20, r=5);
Cone:
cylinder(h=20, r1=5, r2=0);
Centered smooth truncated cone:
cylinder(h=10, r1=3, r2=5, $fn=100, center=true);
Regular prism:
cylinder(h=5, r=5, $fn=6);
Rectangle:
square([30, 20]);
Centered rectangle:
square([30, 20], center=true);
Circle:
circle(10);
Regular polygon:
circle(10, $fn=5);
Irregular polygon:
polygon([[0,0], [10,0], [10,10], [5,10]]);
Text:
text("hello", font="Sans", size=20);
Subtracting from a shape:
difference() {
sphere(10);
translate([0,-15,0]) cube([15,30,15]);
}
Multiple subtractions from a shape:
difference() {
sphere(10);
cube([15, 15, 15]);
cylinder(h=15, r=5);
}
Intersection of two shapes:
intersection() {
cube([10, 10, 10]);
cylinder(h=15, r=5);
}
Subtracting from combined shapes:
difference() {
union() {
sphere(10);
cylinder(h=30, r=5, center=true);
}
cube([10, 30, 10], center=true);
}
Convex hull:
hull() {
sphere(10);
cylinder(h=20, r=5);
}
Minkowski sum:
minkowski() {
sphere(10, $fn=50);
cylinder(h=20, r=5);
}
Translation:
translate([5, 10, 0]) cube([5, 3, 1]);
Rotation:
rotate([0, 0, 60]) cube([30, 20, 10]);
Reflection:
mirror([1, 0, 0]) translate([5, 0, 0]) cylinder(h=1, r=5, $fn=5);
Resize dimensions:
resize([15, 20, 4]) sphere(r=5, $fn=32);
Extrude a 2D shape:
linear_extrude(height=10) {
polygon([[0, 0], [10, 0],
[10, 10], [5, 10]]);
}
Rotate an extrusion of a 2D shape:
rotate_extrude(angle=180) translate([10, 0]) circle(5);
Repeat a shape:
for (x=[0:10:40]) {
translate([x, 0, 0]) cube([5, 5, 10]);
}
Vary characteristics of a repeated shape:
for (x=[0:1:4]) {
h = x*5 + 5;
translate([x*10, 0, 0]) cube([5, 5, h]);
}
Repeat the repetition of a shape:
for (z=[0:15:45]) {
for (x=[0:10:40]) {
translate([x, 0, z]) cube([5, 5, 10]);
}
}
3.147.89.85