Most of them have a bunch of variables listed, but in our examples we will
only use a few. The rest of the variables are assumed to have default values.
In the OpenSCAD manual, you might see more than we even list since func-
tionality gets added to the program all the time.
Default, in this case, means that the program says, “unless you tell me oth-
erwise, I’m assuming that all the other variables have certain predefined
values.” For example, most OpenSCAD shapes have a variable called
ce n te r, which is defaulted to false. The meaning varies a bit depending on
the shape (see the OpenSCAD manual), but for example center = false
for a cylinder creates the cylinder upward from the x-y plane, and center =
true has half of the object above and half below the x-y plane.
Your math teacher probably won’t let you get away with saying, “just assume
all the default values” but OpenSCAD will, with a few exceptions. You usually
have to supply dimensions, for example. A cube 4mm on a side in OpenSCAD
is:
cu b e(4);
But, as we saw in Chapter 2, we can have a “cube” (in OpenSCAD’s opinion)
with different-length sides. If we only give cube() one number, the default
is that all of the sides are the same. Therefore the last example can also be
written as:
cube([4, 4, 4], center = false);
which would be pretty annoying to type over and over.
POLYGONS AND POLYHEDRONS
Now that we have a few definitions out of the way, let’s meet some new
shapes and see what they look like in OpenSCAD. Polygons are 2-dimen-
sional mathematical shapes that have at least three sides, and that
completely split a space into an area outside the polygon and one inside it.
There are special cases that have been known and studied for a few thou-
sand years, and they form the basis of much of the geometry we know today.
We’ll take a look at those first.
REGULAR POLYGONS
Polygons that have all edges the same length and all the angles between the
edges the same are called regular polygons. Where the sides connect, they
34 Chapter 3: Simulating Geometry Make: Geometry 35
Geometry_Chapter10_v15.indd 35Geometry_Chapter10_v15.indd 35 6/23/2021 9:08:39 AM6/23/2021 9:08:39 AM
form a vertex (plural, vertices). An example is the corner of a square. Some
of the regular polygons are a triangle with all sides equal (3 sides), a square
(4 sides), and the regular pentagon (5 sides), hexagon (6 sides), and octagon
(8 sides). Each of these shapes, except for the square which is defined to
have all its sides the same, can have sides of different lengths, but then they
would no longer be regular. We’ll spend all of Chapter 5 exploring triangles
in-depth, and then see in later chapters how many other polygons you can
build up from them.
OpenSCAD can easily create regular 2D polygons, and then extrude them
in the third dimension to be 3D-printable. The following single line in Open-
SCAD will print a pentagon, extruded to be 10mm tall:
linear_extrude(10) circle(r = 15, $fn = 5);
Making $fn equal to 5, 6, and 8 will give the results shown in Figure 3-1
You might wonder why we are using the “circle” function to create a pentag-
onal solid and why the pentagon is not 15 mm on a side. Let’s deconstruct
what is happening here, since it will give you insights into how the program
thinks.
The variable “r” is called the radius of the polygon; it is the radius of the circle
that just touches each vertex, or the circumscribed circle. This is the smallest
circle that the polygon will fit inside, shown in blue (See Figure 3-2). Some
books call this the circumradius of the polygon, but we will use the simpler
convention of just calling it “the radius of the polygon.” The circle that just
touches the center of each side of the polygon, is called the inscribed circle. It
FIGURE 31: A regular pentagon, hexagon, and octagon
36 Chapter 3: Simulating Geometry Make: Geometry 37
Geometry_Chapter10_v15.indd 36Geometry_Chapter10_v15.indd 36 6/23/2021 9:08:40 AM6/23/2021 9:08:40 AM
is the largest circle that will fit inside the polygon, shown in red. This works
both ways: the polygon is inscribed in the blue circle (see chapter 7 for more).
The red circle’s radius is the vertical line, and is called the apothem of the
polygon.
OpenSCAD creates a circle by using short line segments, which it calls frag-
ments. The $fn variable is the number of fragments used to create a closed
regular polygon. Thus $fn = 5 makes a closed curve consisting of five
equal straight lines with equal angles between them, otherwise known as a
regular pentagon. If you used $fn = 4, you would get a square. $fn = 6 is
a hexagon, and $fn = 8 is an octagon. As you use a bigger and bigger value
of $fn, you’ll see that the polygon looks more and more like a circle. We will
explore this in Chapter 7, when we talk about inscribed and circumscribed
polygons. You can generate a pretty good circle with
FIGURE 32: Inscribed and circumscribed circles in a polygon
36 Chapter 3: Simulating Geometry Make: Geometry 37
Geometry_Chapter10_v15.indd 37Geometry_Chapter10_v15.indd 37 6/23/2021 9:08:40 AM6/23/2021 9:08:40 AM
linear_extrude(10) circle(r = 15, $fn = 100);
Incidentally, be careful of setting $fn too high on complex shapes. This can
make OpenSCAD take a long time to process, or even crash (and lose all
your model coding). Be sure to save your model before trying to preview or
render it.
POLYHEDRONS
Now that we have looked at 2D shapes, we can move up to 3D. Polyhedrons
are solid objects that do not have any curved surfaces. For example, a 3D
rectangular box is a polyhedron, but a cylinder is not (because its sides are
curved). Each side of a polyhedron (like the top or bottom of a cube) is called
a face, and we usually call the line connecting two faces an edge.
Just as there is a special category of polygons with all sides equal, there is
also a category for solids that have the same regular polygon making up all
their sides. These are called Platonic Solids, and there are only five of them.
PLATONIC SOLIDS
There are just five solids that meet the definition of Platonic solids, named
after the Greek philosopher Plato, who lived about 2400 years ago and was
very into things being symmetrical and regular. To be a Platonic solid, the
edges must be equal, all the angles at which those edges meet must be
equal, and the same number of faces must meet at each vertex. They are the
tetrahedron (4 triangular faces), the cube ( 6 square faces), the octahedron (8
triangular faces), the dodecahedron (12 pentagonal faces), and the icosahe-
dron (20 triangular faces). We will see a lot more of them in Chapter 9.
PLATONIC SOLIDS MODELS
The file platonicSolids.scad can be used to create these objects, as shown
in Figure 3-3. It creates all of the solids at once, scaled to be size millime-
ters tall when they are resting on one face. If you elect to scale the models in
your slicing software, note that they will cease to be Platonic solids if you do
not scale them uniformly. You can however change the value of size and all
the solids will scale consistently.
We also have a second file, edge_platonic_solids.scad which allows you
to print a set of Platonic solids defined by the length of each edge of the
polygons. You might find this one more useful later on in Chapter 9 when we
study the surface area, and it is more convenient in general for calculation to
38 Chapter 3: Simulating Geometry Make: Geometry 39
Geometry_Chapter10_v15.indd 38Geometry_Chapter10_v15.indd 38 6/23/2021 9:08:40 AM6/23/2021 9:08:40 AM
specify it this way. In this case, you would make the variable edge whatever
length (in millimeters) you wanted, within reason. (You would, of course, need
to make it small enough so that it fits on your printer.)
You might notice in that model that after defining the variable edge there is a
block like this:
translate(edge * [.75, -.75, 0]) tetrahedron(edge);
translate(edge * [1.5, 1.5, 0]) cube(edge);
octahedron(edge);
translate(edge * [2, 0, 0]) dodecahedron(edge);
translate(edge * [.5, 1.6, 0]) icosahedron(edge);
If you wanted to skip creating any of these models, you could comment out
ones you did not want. (See Chapter 2’s discussion on altering models.) For
example, this would 3D print the cube and octahedron, and ignore the others
(which are commented out with “//” at the beginning of the line):
// translate(edge * [.75, -.75, 0]) tetrahedron(edge);
translate(edge * [1.5, 1.5, 0]) cube(edge);
octahedron(edge);
// translate(edge * [2, 0, 0]) dodecahedron(edge);
// translate(edge * [.5, 1.6, 0]) icosahedron(edge);
You will observe that the tetrahedron, octahedron, and icosahedron are
made up of triangles, the cube is made of squares, and the dodecahedron
is made of pentagons. The reason there are only five Platonic solids comes
from the equal-angle constraint. If you think about it, the angles at each
FIGURE 33: The Platonic solids
38 Chapter 3: Simulating Geometry Make: Geometry 39
Geometry_Chapter10_v15.indd 39Geometry_Chapter10_v15.indd 39 6/23/2021 9:08:41 AM6/23/2021 9:08:41 AM
..................Content has been hidden....................

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