3
CHAPTER 3
SIMULATING
GEOMETRY
30 Chapter 3: Simulating Geometry Make: Geometry 31
Geometry_Chapter10_v15.indd 30Geometry_Chapter10_v15.indd 30 6/23/2021 9:08:39 AM6/23/2021 9:08:39 AM
In Chapter 2, we introduced the basic mechanics of OpenSCAD. In this chapter, we will first introduce
some concepts you’ll need as we start talking about more complicated shapes. Then, we’ll introduce
our first real model, and talk through what it does and how to modify it.
Then, we’ll jump into using OpenSCAD to simulate some of the basic ideas in geometry. If you were to
compare the table of contents of a geometry book and the list of commands in OpenSCAD, you would
notice a lot of overlap. This is, after all, why this category of CAD programs is called “Constructive Solid
Geometry.”
We highly recommend that as we walk through the chapter, you actually type the short models into
OpenSCAD as we discuss them. As you do this, you should mess with the numbers, change things, and
see what happens.
In this chapter, we’ll also introduce a few of the more sophisticated coding constructs and OpenSCAD
features that we use in upcoming models. If you
aren’t interested in learning to make models
yourself you can skip some of this detail, but we
hope that you are inspired to take the program out
for a spin too. In some cases, you’ll need material
from later in the book to fully appreciate what is
going on. In those cases, we will note where the
material is explored later in the book, but intro-
duce the OpenSCAD capability here. That way, the
OpenSCAD-focused (versus geometry-focused)
material is in one place for you as a reference.
We will walk you through using one of the models
to create Platonic solids, which are objects whose
faces are all regular polygons, all of which meet
at equal angles. This will give you some practice
with using a model from the repository and mod-
ifying it.
We’ll guide you through a model that makes a
simple (but very extensible) castle, to tie together
OpenSCAD and geometrical concepts and give
you some experience with going step-by-step
through a model. Finally, we’ll also briefly discuss
Tinkercad, a simpler CAD program that can do
some of this simulation as well.
3D Printable Models Used in
this Chapter
The following models are discussed in this
chapter. See Chapter 2 for directions on how to
download them. There are also quite a few model
fragments scattered in this chapter. Be sure to
type them in and try them out.
platonicSolids.scad
Prints one of each of the five Platonic solids. This
model scales all five so they are the same height
as each other on the print bed.
edge_platonic_solids.scad
Prints one or more Platonic solids, scaled by the
user input length of one edge.
castle.scad
Prints a castle, developed as an exercise in the
various moving and scaling functions in this
chapter.
30 Chapter 3: Simulating Geometry Make: Geometry 31
Geometry_Chapter10_v15.indd 31Geometry_Chapter10_v15.indd 31 6/23/2021 9:08:39 AM6/23/2021 9:08:39 AM
PRELIMINARIES
Before we start typing some more interesting models in OpenSCAD, we
need to get through a few definitions and background concepts. You might
have used some of the words before, but we’ll use them a little more spe-
cifically here than you might in everyday discussion. Mathematicians can be
awfully picky about exactly what a word means, so we’ll give you their defini-
tions before we start hanging out with them.
CIRCLES AND PI
A circle is a closed curve that is a constant distance, the radius, from its
center. You’ve probably heard that the area of a circle is pi times the radius
squared, but what is pi? It is written as the Greek letter π, and pronounced
like the word “pie”. It is the ratio between the circumference, the distance
one would travel to go all the way around a circle, and the diameter, which is
twice the radius, or the longest distance across a circle.
Pi also appears in many other branches of math, and is an irrational number
that equals roughly 3.14159. Irrational doesn’t mean the mathematicians
who came up with pi are crazy. It means that there is no way to show pi as
a fraction — a ratio — of one whole number over another, as you can with
values like 10/3 and 3/5. (Numbers like 3 are rational because you could
express them as 3/1, since anything divided by 1 is just the number itself.)
You can roughly approximate pi with 22/7 or (slightly closer) with 355/113,
but these are not exact.
You might think 10/3 is irrational since it is a decimal that never ends. It’s
3.333... on to infinity. The difference is that the fractional part repeats (or
terminates) for rational numbers, but does not in an irrational one. For
example, 10.3 and 10.4 are rational numbers, since they could be written
103/10 and 104/10, respectively.
People have computed pi to tens of trillions of digits, and there’s never any
end in sight. (That’s not a typo. Tens of trillions, really.) You can see the first
million at piday.org. If you really want to get into it, Pi Day is March 14 (3.14),
and geeky observances abound around the world, usually involving eating
pizza or other kinds of pie in the pun-loving parts of the English-speak-
ing world. For some years, MIT released its offer of admissions on March
14, and took it some more digits in 2020 by moving the release to 1:59 PM
(3.14159...).
32 Chapter 3: Simulating Geometry Make: Geometry 33
Geometry_Chapter10_v15.indd 32Geometry_Chapter10_v15.indd 32 6/23/2021 9:08:39 AM6/23/2021 9:08:39 AM
There is also another symbol for 2π—the Greek letter tau, ?. Some people
think tau is more intuitive when talking about circles than pi is, but it never
really has caught on as an alternative. Pi comes up all over the place in
geometry, and we needed to let you know about it before we dive too far into
other shapes. OpenSCAD bases a lot of other shapes on the circle (or cylin-
der) as we will see a little later in this chapter.
ANGLES AND DEGREES
Stand in one place facing forward and stick your right hand at shoulder
height directly in front of you. Now swing your right arm around clockwise
until your hand is pointing directly to the right. You just swept your arm
through an angle of 90 degrees. A degree in geometry is a measure of how
much something has rotated about its center. 90° angles are often called
right angles.” Wikipedia says this is from the Latin word rectus, forupright,
since something sticking straight up forms a 90° angle from the ground.
If you sweep through 90 degrees (written 90°) and keep going for 90 more,
you will be pointing in the exact opposite direction from where you started.
Two times 90° is 180°, so you can think of a straight line as a 180° angle.
If you kept going all the way around to bring your hand back to where you
started, you would have turned 360°, which is a full circle.
PARALLEL AND PERPENDICULAR
Imagine you have a perfectly rectangular box. The top and bottom of the box
are always at the same distance from each other everywhere if the box was
perfectly square at all its corners. Now imagine that the top and bottom of
the box went on to infinity; that would still be true.
Planes (or lines) that never meet (another way of saying they stay the same
distance from each other everywhere) are said to be parallel to each other.
An example of a pair of parallel lines would be two opposite edges of the
bottom of a (finite) box. If you drew a line through each and extended those
lines to infinity, they would never cross.
Where two sides of the box meet, however, they intersect at a right angle.
Surfaces (or lines) that intersect at 90 degrees are said to be perpendicular to
each other. You can explore this with a box, or print out a cube in OpenSCAD
with this command, which prints out a cube 40 mm on a side.
cube(40);
32 Chapter 3: Simulating Geometry Make: Geometry 33
Geometry_Chapter10_v15.indd 33Geometry_Chapter10_v15.indd 33 6/23/2021 9:08:39 AM6/23/2021 9:08:39 AM
The top and bottom sides of the cube are parallel to each other. The top or
bottom and any side are perpendicular. Opposite sides of the cube are paral-
lel to each other.
CODE VERSUS MATH CONVENTIONS
Some things are a little different in OpenSCAD and regular math. Let’s talk
about a few of those here.
EQUAL SIGN
When we see 2 + 2 = 4 in a math class, we know that anything we do on one
side of the equal sign we can do on the other. For instance,
2 + 2 + 2 = 4 + 2
In a math class, the equals sign says, “the stuff on either side has to be
the same.” However, in a computer program, an equals sign sort of means
“becomes.” So we might say:
apples = 2;
That means that wherever the word apples appears in the code, you can
replace it with a 2. (In OpenSCAD at least — this is different in different pro-
gramming languages.) But you can’t say:
apples + 2 = 2 + 2;
without the program giving you an error message. But you could say:
apples = 2 + 2;
In which case apples would be 4 after that line of code was executed by the
computer. You also can’t say:
2 = apples;
OpenSCAD would think 2 was the variable, and you’d be trying to set it to
the value of a variable you haven’t defined called apples. Unlike algebra, the
equals sign in OpenSCAD has a direction to it.
DEFAULTS
We will start to use more complicated OpenSCAD functions in this chapter.
34 Chapter 3: Simulating Geometry Make: Geometry 35
Geometry_Chapter10_v15.indd 34Geometry_Chapter10_v15.indd 34 6/23/2021 9:08:39 AM6/23/2021 9:08:39 AM
..................Content has been hidden....................

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