Learning About Boolean Expressions


In this lesson, you will:

Caution

This is an important lesson because Boolean operations are critical to the modeling process. The order in which shapes are combined and the operators used to combine the shapes will determine how the MGED program interprets your model.

The correct use of Boolean expressions to modify geometric shapes is a key skill in constructive solid modeling. It important to review these concepts as many times as necessary. If it is difficult to absorb them all now, come back to them later.

There are conceptually two objects in MGED that support Boolean operations. One is called a combination, the other is called a region.

As mentioned earlier, a typical geometric shape in MGED is called a primitive. However, single primitives are often insufficient to fully describe the complex shape of the object being modeled. So, combining two or more primitive shapes into other shapes (called combinations) using Boolean operators allows you to artfully imitate the shape and form of most complicated objects.

The previous chapter noted that material properties are associated with regions. Like combinations, regions use Boolean operations to create complex shapes. The difference is that regions are shapes that have material properties. They occupy three-dimensional space, rather than simply defining a shape in space.

You can think of primitives and combinations as a blueprint for an object. The actual object is created when a region is made. For example, you might make a blueprint of an object such as a coffee mug, but then create that mug from different types of material (e.g., ceramic or glass). Regardless of the material, the blueprint is the same.

When Boolean operations are used to build up complex shapes from simpler shapes, we can call the result a shape combination. When they are used to define other logical or hierarchical structure within the database, the result may be referred to as a group or an assembly combination.

The three Boolean operators employed by the MGED program are union, subtraction, and intersection. You can use Boolean operations to combine shapes to produce more complex shapes.

Begin by opening the database shapes.g that you created in Lesson 3. At the Command Window prompt, type: draw sph2.s rcc2.s[Enter] This lets us see the shapes we will be using to create our regions. As seen earlier, the two shapes should look something like the following:

In this lesson, we will create different shapes to demonstrate the function of Boolean operations. In the Command Window, type the following: r part1.r u rcc2.s - sph2.s[Enter] This command tells MGED to:

rpart1.rurcc2.s-sph2.s
Make a regionCall it part1.rMerge...The shape named rcc2.sSubtract...The shape named sph2.s

In the previous lesson, we applied material properties to objects from the Command Line. Now we are going to use the graphical interface to do the same thing. From the Edit menu, choose Combination Editor. This will pop up a dialog box. Select the button to the right of the Name entry box and then Select from All. A drop-down menu will appear with the regions you have created. Select part1.r. The result should look like the following:

Click on the button next to Color and select red from the pull-down menu.

Now click the OK button at the bottom left of the dialog window. This will apply your changes and close the panel.

At the moment, we have only the primitive shapes displayed, not the region. Before we can raytrace, we must remove the primitive shapes from the display, and draw the region. Otherwise, we will not be able to see the region with the color properties we applied. We can do this by typing: B part1.r

We are now ready to raytrace this object. From the File menu, bring up the Raytrace Control Panel and click the Raytrace button. The image you get should look similar to the left-hand image that follows. Note that it may take several minutes to raytrace the window, depending on the speed of your particular system.

Raytraced part1.rRaytraced part2.r

You should see that a spherical "bite" has been taken out of the top of the cylinder.

Next we will make a blue region using the intersection operator instead of subtraction. Once again, we start by creating a region: r part2.r u rcc2.s + sph2.s[Enter]

For comparison to the GUI approach used to make part1.r, let's use the Command Line to assign the color to part2.r: mater part2.r plastic 0 0 255 0[Enter]

Finally, Blast this new region onto the display as follows: B part2.r[Enter]

Now raytrace the object. It should look similar to the preceding right-hand image.

When you use the intersection operator, the order in which you specify the shapes doesn't matter. We would have gotten the same results if we had specified the Boolean operation as r part2.r u sph2.s + rcc2.s

However, when using the subtraction operator, the order of the two shapes is very important. Let's make a region with the order of the shapes reversed from that used for part1.r: r part3.r u sph2.s - rcc2.s

This time we won't bother to set a color. (When no color is set for objects, the raytracer (rt) will use a color of white. However, these objects may appear gray because of the amount of light in the scene.) Blast this design to the display and raytrace it:

Now let's raytrace all three objects we have created together. To draw the three regions at once, we could type: B part1.r part2.r part3.r

Doing this once is no problem. However, if these were three parts that made up some complex object, we might like to be able to draw all of them more conveniently. To make drawing a collection of objects together easier, we create an assembly combination to gather them all together. We will create one called dome.c for our three regions. This is accomplished by the following command: comb dome.c u part1.r u part2.r u part3.r

Notice the similarity between this command and the r command we used to create the regions.

Remember from the discussion at the beginning of this lesson, the difference between a region and a combination is that combinations are not necessarily composed of only one kind of material. Several objects of different materials can make up an assembly combination such as the one we have just created.

All that is necessary to draw all three objects is the much simpler command: B dome.c

Now we can raytrace the collected set and get the following image:

The shapes we have created here are fairly simple. In each case, a single primitive shape is unioned, and subtraction or intersection operations are performed on that single primitive shape. You should know that it is possible to use much more complex Boolean equations to create the shape of objects. When you want to make such objects, keep in mind the precedence of the Boolean operations. In the Boolean notation we are using, the subtraction and intersection operators both have higher precedence than the union operator has. So, for example: comb demo.c u shape1 - shape2 u shape3 - shape4 + shape5

This would result in the following Boolean expression: (shape1 - shape2) u ( (shape3 - shape4) + shape5)

In this lesson, you: