Introduction to 3D Modeling. Section 2. Library of Shapes
- Create a variety of 2D and 3D shapes.
- Assign colors to objects.
- Create convex hulls and extrude 2D objects to 3D.
This section serves mainly as a database of shapes and it is intended for reference rather than for systematic study. You may want to browse through it quickly to get an overview what shapes are available, but our goal is to move to design projects quickly. Note in Subsection 2.2 how colors are assigned to objects. Your first project is awaiting you in Section 3 and it will only require cubes and boxes.
The command CUBE(a) creates a cube of dimensions a × a × a. Every newly created object
comes in a default steel color. To visualize objects, we use the SHOW command, that can be
abbreviated by V. Type the two lines below into the PLaSM input cell and press the green
After a moment, the following image should appear in your web browser:
The command COLOR, possibly abbreviated as C, assigns a given RGB color to a 2D or 3D
object. Its use is best illustrated on the following example, where we change the color of the
cube from steel to brass:
Note that PLaSM keywords are written in capital letters. This is to avoid conflicts with user-defined variables (names of objects, custom colors, etc.). For newcomers to programming – in the above program, c is a user-defined variable (intentionally chosen to be lowercase), and CUBE, COLOR, BRASS and SHOW are PLaSM keywords. After executing the script, you will see the following:
Note that the axes in the grid are color-coded using the word "RGB" for convenience:
x = R, y = G, z = B.
Note that the axes in the grid are color-coded using the word "RGB" for convenience: x = R, y = G, z = B.
The keyword BRASS is just a predefined triplet of numbers [255, 250, 83]. PLaSM offers
the following predefined colors:
GREEN = [0, 255, 0]
BLACK = [0, 0, 0]
BLUE = [0, 0, 255]
BROWN = [139, 69, 19]
CYAN = [0, 255, 255]
MAGENTA = [255, 0, 255]
PINK = [255, 0, 255]
ORANGE = [255, 153, 0]
PURPLE = [128, 0, 128]
WHITE = [255, 255, 255]
RED = [255, 0, 0]
YELLOW = [255, 255, 0]
and metallic colors:
BRASS = [181, 166, 66]
COPPER = [184, 115, 51]
BRONZE = [140, 120, 83]
SILVER = [230, 232, 250]
GOLD = [226, 178, 39]
PLaSM makes it possible to work in a two-dimensional setting of the axes x and y (in
addition to 3D). Here, the z axis is not present. The first 2D command that we will explore is
SQUARE(a) which renders a square of edge length a. Its usage is illustrated by the following
The square is shown in Fig. 14. Again note where it is positioned - all newly created squares are positioned like this.
The planar square introduced in the previous paragraph is a purely 2D object that cannot be
combined with 3D objects. However, sometimes we need to do this – such as when
constructing conic or cylindric sections. For this purpose, PLaSM has a command
SQUARE3D(a) that creates a square of edge length a in the 3D space. Otherwise the square is
located in the same way as the one created via the SQUARE(a) command. Sample script
creating a square in the 3D space is
In reality, this object is a thin 3D solid (cube whose third dimension was scaled down to 0.001). Later we will learn how to rotate, move, and scale such objects, and how to intersect them with other 3D objects. The output of the above acript is shown in Fig. 15.
and press the green arrow button. The result is displayed in Fig. 16.
Planar rectangle of dimensions a, b can be created with the command RECTANGLE(a, b).
For illustration, the output of a sample script
is shown in Fig. 17. Note that the rectangle is located in the first quadrant with its edges aligned with coordinate axes, and that its bottom-left vertex lies at the origin (0, 0).
To operate with rectangles in the 3D space, we have the command RECTANGLE3D(a, b)
which works analogously to the command SQUARE3D(a). Its usage can be illustrated using
that creates the same rectangle as before but renders it as thin 3D solid. The rectangle is again located in the first quadrant, with one vertex at the origin (0, 0, 0), and its edges are aligned with the coordinate axes x and y. In reality, this is a box whose third dimension is 0.001. The output is shown in Fig. 18.
Tetrahedron in PLaSM is defined using four 3D points that do not lie in the same plane.
Every 3D point in PLaSM is a triplet of real numbers enclosed in square brackets, such as
[0, 0, 0] (the origin). To keep our script readable, it is a good idea to introduce new variables
for points. Such as, the points [-2, 0, 0], [1, 0, 0], [0, 4, 1], [0, 1, 2] can be called a, b, c and d. Then
the command TETRAHEDRON(a, b, c, d) creates a tetrahedron with the vertices a, b, c
and d. The output of the code
is shown in Fig. 19.
Planar triangles are created using the command TRIANGLE(a, b, c) where a, b, c are 2D
points (pairs of real numbers enclosed in square brackets). For example, the triangle with
vertices [-1, 0], [1, 0], [0, 2] is created using the following code:
The output is shown in Fig. 20.
Knowing how squares and rectangles work in the 3D setting, you will not be surprized by
learning that the command TRIANGLE3D(a, b, c) creates a 3D triangle. The points a, b, c
are 2D points though, and the triangle will lie in the xy-plane. Let us create the same triangle
as in the previous paragraph:
The output is shown in Fig. 21.
Sphere with radius r and center at (0, 0, 0) is created using the command SPHERE(r):
The output is shown in Fig. 22.
Notice that the surface is approximated using small flat sections. We will discuss this in more detail in Subsection 2.14 where we will also show how the spherical surface can be made smoother or coarser.
Planar circle with radius r and center at (0, 0) can be defined using the command
The output is shown in Fig. 23.
In fact this is a polygon with many edges. In Subsection 2.14 we will show how to reduce the number of edges in order to obtain various equilateral polygons.
Finally, the command CIRCLE3D(r) creates a 3D circle with center at the origin (0, 0) that
lies in the xy-plane. This is the last in the series of 2D objects created as thin 3D solid, and it is
constructed via the following script:
The output is shown in Fig. 24.
As all the square, rectangle, and triangle in the 3D space also the circle is in reality a cylinder of height 0.001. The knowledge of this technical detail will be useful for performing operations such as intersection, union, difference and xor of these 2D objects.
In 3D computer graphics, curved surfaces are always approximated using small linear
triangular segments. This is how computer hardware is built. Also PLaSM works in this way.
Each curved object comes with a default division that the user can adjust if needed. For the
SPHERE command, the default divisions are 64 in the angular direction and 32 in the
z-direction. This yields a uniformly spaced grid. The division can be used as an optional
argument. If there are two divisions, they are always enclosed in square brackets. Hence, the
is equivalent to
It is easy to calculate that the default sphere is approximated using 2 ⋅ 32 ⋅ 64 = 4, 096 linear
triangles. Therefore its rendering will take longer than a cone which has only around 100, and
much longer than cube which only has 12. If you decide to make it look better by using twice
finer division in both directions,
then the number of linear triangles jumps to 2 ⋅ 64 ⋅ 128 = 16, 384. This is a lot, and you are
likely to wait.
Making the number of linear triangles large means nicer image
but also more computing, more data transfer, and a longer wait.
Making the number of linear triangles large means nicer image
The knowledge of the subdivisions can be used to create various interesting objects such as a
The output is shown in Fig. 25.
Another object that can be created using the SPHERE command with subdivisions [64, 8] is a baloon shown in Fig. 26.
in 2D, the CIRCLE(r) command is equivalent to CIRCLE(r, 64) and it approximates the circular boundary using an equilateral polygon with 64 edges. Various equilateral polygons can be created by using a number less than 64:
Given any 2D polygon b and a positive number h, the command PRISM(b, h) creates a prism with the base b and height h. For illustration, prisms of height h = 3 corresponding to the polygons shown in Fig. 27 are depicted below:
The basis also can be a SQUARE, RECTANGLE, TRIANGLE and even a CIRCLE. In the last case, we obtain a cylinder. Since cylinders are used very often, PLaSM provides a separate command for them:.
Cylinder with radius r and height h can be defined using the command CYLINDER(r, h),
possibly abbreviated as CYL(r, h). The cylinder’s axis is in the z-direction, and
the midpoint of its base circle lies at the origin (0, 0, 0). The output of the sample
is shown in Fig. 29.
By default, the curved surface is split into 64 vertical linear segments. To change the division
to another integer number m, use
This can be used to create prisms. By using m = 3, 4, 5, 6 we obtain the prisms from Fig. 28.
Tube of inner radius r1, outer radius r2 and height h is rendered using the command
TUBE(r1, r2, h). The tube is positioned in the global coordinate system same as the
cylinder – its axis coincides with the z-axis and the center of its base is at (0, 0, 0). The output
of the sample code
is shown in Fig. 30.
By default, the inner and outer curved surfaces are split each into 64 vertical linear segments.
To change the division to another integer number m, use
This can be used to create tubes with various polygonal cross-sections.
Cone with radius r and height h is created using the command CONE(r, h). The cone’s axis
coincides with the z-axis and the center of the base circle lies at the origin (0, 0, 0). The output
of the sample code
is shown in Fig. 31.
By default, the curved surface is split into 64 linear triangles. To change the division to
another integer number m, use
The linear surface representation can be used to render pyramids, as shown in Fig. 32.
Truncated cone with bottom radius r1, top radius r2 and height h is created using the
command TCONE(r1, r2, h). The cone’s axis coincides with the z-axis and the center of
the base circle lies at the origin (0, 0, 0). The output of the sample code
The output is shown in Fig. 33.
By default, the curved surface is split into 64 trapezoidal linear segments. To change the
division to another integer number m, use
The output is shown in Fig. 34.
Command TORUS(r1, r2) creates a torus (donut) with inner radius r1 and outer radius
r2. It is used as follows:
The center of the torus is at the origin (0, 0, 0) and its axis is the z-axis. This is illustrated in Fig. 35.
By default, the major (large) circle is split into 64 linear segments and the minor
(small) one into 32. Thus the default command TORUS(r1, r2) is equivalent to
TORUS(r1, r2, [64, 32]). To change the divisions to other integer numbers [m, n],
Also here, the piecewise-linear surface representation can be used to create interesting objects. Fig. 36 shows the output of the command TORUS(3, 5, [64, 4]).
Fig. 37 shows the output of the command TORUS(3, 5, [4, 64]).
Constructing convex hulls of finite point sets in 2D and 3D is one of the most important algorithms in computational geometry. A 2D or 3D object is convex if for any two points located inside, the straight line connecting the points lies entirely inside. For illustration, Fig. 38 shows a convex object on the left and a non-convex one on the right.
By convex hull of a set of 2D or 3D points we mean the smallest convext set that contains all the points. To construct convex hull of a large number of points efficiently is not a trivial task at all. It can be proven mathematically that the complexity of finding a convex hull of n points is always at least (n log n) where n is the number of points
The complexity of more recent convex hull algorithms can be characterized in terms of both input size n and the output size h (the number of vertices of the hull). Such algorithms are called output-sensitive algorithms. They are often asymptotically more efficient than (n log n) algorithms in cases when h is much lower than n.
The earliest output-sensitive algorithm was introduced by Kirkpatrick and Seidel in 1986
(who called it "the ultimate convex hull algorithm"). A much simpler algorithm was
developed by Chan in 1996, and is called Chan’s algorithm. That’s the one used in PLaSM.
The CONVEXHULL command (possibly abbreviated as CHULL or CH) takes a set of points and
creates their convex hull:
This code renders a 2D trapezoid spanning the points (-1, 0), (1, 0), (0.5, 1) and (-0.5, 1) as shown in Fig. 39.
creates a 3D object shown in Fig. 40.
If you already have a list of points, defined for example as
then just insert it into the CHULL command:
A (regular) dodecahedron is an object with 12 identical pentagonal faces. It is one of the
Platonic solids – convex symmetric 3D objects whose faces are regular polygons. There are
only five of them – the (regular) tetrahedron, cube, octahedron, dodecahedron and
icosahedron. For their extraordinary symmetry, these objects have been studied by
geometers for thousands of years. In PLaSM, a dodecahedron is created simply
A (regular) icosahedron is an object with 20 triangular faces that also belongs to the five
Platonic solids. In PLaSM it is created via
The object is shown in Fig. 42.
An arbitrary 2D object that lies in the xy-plane can be extruded to 3D using the PRISM
command that we already know from Subsection 2.15. For illustration, let us extrude a
sample 2D polygon obtained as convex hull:
The output is shown in Fig. 43.
The command PRISM(b, h) uses a single interval in the z-direction. For future reference, let us also introduce the command EXTRUDE(b, h, angle, n) that with angle = 0 yields the same extruded geometry as the PRISM command, but it subdivides the extrusion height h into n equally long subintervals. This will be practical for working with curved shapes.
PLaSM also provides useful commands GRID and PRODUCT that make it easy to work with
grids and Cartesian product geometries. The command GRID takes a list of positive and
negative numbers where the positive ones stand for intervals (more precisely for
their lengths) and negative for the lengths of spaces between the intervals. The
intervals and spaces are placed on the right of the origin in the real axis. For example,
creates a single interval (0, 5). The command
creates three intervals (0, 1), (1.5, 2.5) and (3, 4), leaving empty spaces of length 0.5 between
them. There is no limit on the number of intervals. Next, the command
creates a 2D object G in the xy-plane which is the Cartesian product of the two grids g1 and g2. This object is shown in Fig. 44.
This 2D object can be multiplied with a third grid in the z-direction. Let’s say that the third
Then the result of the Cartesian product
is a 3D geometry shown in Fig. 45.
Just to show one more application of GRID and PRODUCT, let’s do:
The object is shown in Fig. 46.