Contents



Learning Objectives

  • Understand how to use the union() function in OpenSCAD.
  • Learn how to combine shapes to create complex objects.
  • Learn how to apply nested boolean operations.
  • Get familiar with parameterizing objects in OpenSCAD.

Introduction to Boolean Unions

In OpenSCAD, the union() function allows us to combine two or more shapes into a single object. It’s the opposite of the difference() function we’ve discussed earlier. The union() command can be particularly useful when creating complex objects from simple shapes.

For example, the following code combines a cube and a sphere into a single object:

union() {
 cube([10, 10, 10]);
 sphere(5);
}



Practical Applications of union() Function

Now, let’s take a look at some examples where you can apply the union() function:

  • To create an ice cream cone, you can combine a cone (which is a specialized cylinder) and a sphere:
union() {
 cylinder(h=10, r1=0, r2=5); // cone
 sphere(5); // ice cream
}

You can also nest boolean operations. Consider the following code:

difference() {
  union() {
    cube([10, 10, 10]);
    cylinder(h=10, r1=2, r2=2);
  }
  sphere(5);
}

This script first creates a union of a cube and a cylinder. Then it subtracts a sphere from that combined shape.


Review

In this lesson, you learned:

  • How to use the union() function to combine shapes in OpenSCAD.
  • The concept of nested boolean operations, combining union() and difference() functions.
  • How to parameterize objects in OpenSCAD to make your code more versatile and reusable.
  • The basics of 3D modeling and how to visualize complex shapes by combining simple ones.




Resources