4.2 Recursion in Architecture
As we will see, recursion is also a fundamental concept in architecture. As an example, consider a flight of stairs as outlined in this figure and imagine we intend to define a function called stairs that, given the point \(P\), the tread depth \(d\), the rise height \(h\), and the number of steps \(n\), creates the stairs with the first step starting at \(P\). Given these parameters, the definition of the function should start as:
stairs(p, d, h, n) =
...
Flight of stairs with \(n\) steps, with the first step starting at the point \(P\), and each step containing a tread depth \(d\) and a rise height \(h\).
To implement this function, we will decompose the problem in less complex sub-problems, and this is where recursion provides a great help: it allows us to decompose the drawing of a flight of stairs with \(n\) steps into the drawing of a step followed by the drawing of a flight of stairs with \(n-1\) steps, as illustrated in this figure.
Decomposition of the design of a flight of stairs of \(n\) steps into the design of a flight of stairs of \(n-1\) steps.
This means that the function will be something like:
stairs(p, d, h, n) =
...
step(p, d, h)
stairs(p+vxy(d, h), d, h, n-1)
...
To draw a step, we can define the following function that creates the segments for the tread and riser:
step(p, d, h) = line(p, p+vy(h), p+vxy(d, h))
The problem now is that the stairs function needs to stop creating steps at some point. By successively reducing the number of steps, that moment comes when that number becomes zero. Thus, when asked to draw a flight of stairs with zero steps, the stairs function no longer needs to do anything. Julia provides a value precisely to indicate that nothing is needed: nothing. This means that the function should have the following form:
stairs(p, d, h, n) =
if n == 0
nothing
else
step(p, d, h)
stairs(p+vxy(d, h), d, h, n-1)
end
To see a more interesting example of recursion in architecture, let us consider the Step Pyramid of Djoser, illustrated in this figure, built by the architect Imhotep in the 27th century BC. This pyramid is considered to be the first pyramid in Egypt and the oldest monumental stone construction in the world. It is composed of six progressively smaller steps, stacked on top of each other.
The Step Pyramid of Djoser. Photograph by Charles J. Sharp.
To parametrize the Step Pyramid, we will refer to the illustration in this figure, and we will consider the center of the base of the pyramid as the \(P\) position, and each step as a pyramid frustum.
Scheme of the Step Pyramid.
Although it is clear that a step pyramid is a stack of increasingly smaller steps, another way of looking at it is as just one step on top of which stands another (smaller) step pyramid. This means that we define the step pyramid using the concept of step pyramid and, thus, this is a recursive definition. Formally, we can define a pyramid of \(n\) steps as a step on top of which stands a pyramid of \(n-1\) steps. To complete this definition, it must be said that, when the last step is created, the pyramid of \(0\) steps at the top does not actually exist.
step_pyramid(p, b, t, h, d, n) =
if n == 0
nothing
else
regular_pyramid_frustum(4, p, b, 0, h, t)
step_pyramid(p + vz(h), b - d, t - d, h, d, n - 1)
end
An approximation of the Step Pyramid of Djoser would then be:
step_pyramid(xyz(0, 0, 0), 120, 115, 20, 15, 6)
4.2.1 Exercises 23
4.2.1.1 Question 61
The above definition does not accurately reflect the geometry of the Step Pyramid of Djoser, because it does not consider the sloped surfaces that actually exist between each step. That can be seen in the following scheme, which compares the sections of the pyramid we defined (left) with the actual Step Pyramid of Djoser (right):
Define a more rigorous version of the step_pyramid function that receives, in addition to the aforementioned parameters, the height of each slope. Experiment different parameter values to produce a model similar to the following one:
4.2.1.2 Question 62
The false arch is the oldest form of arch. It is formed by parallelepipeds arranged horizontally like steps, forming an opening that narrows towards the top, ending with a horizontal beam, as shown in the following scheme:
Assuming that the parallelepipeds have a square section measuring \(l\), the opening reduction \(\Delta_e\) is equal in every step, and the point \(P\) is the arch’s center point, define the false_arch function that, with the parameters \(P\), \(c\), \(e\), \(\Delta_e\) and \(l\), creates a false arch.
4.2.1.3 Question 63
Define the stacking_circles function in such a way that the following expressions create the illustration below.
stacking_circles(xy(0, 0), 1.2, 0.3)
stacking_circles(xy(3, 0), 1.2, 0.5)
stacking_circles(xy(6, 0), 0.9, 0.6)
stacking_circles(xy(9, 0), 0.5, 0.8)
Note that the circles’ radii follow a geometric progression with ratio \(f\), being \(0 <f < 1\). That way, the radius of each circle (except the first one) is the product of \(f\) by the radius of the circle below it. The smallest circle must have a radius that is greater or equal to \(1\). The function should have as parameters the center point and the radius of the larger circle, and also the reduction factor \(f\).
4.2.1.4 Question 64
Define a radial_circles function that, given the coordinates of the rotation center \(P\), the number of circles \(n\), the rotation radius \(r_0\), the circles radius \(r_1\), the initial angle \(\phi\) and the angle increment \(\Delta\phi\), draws the circles as shown in the previous figure.
Test your function with the following expressions:
radial_circles(xy(0, 0), 10, 1.5, 0.3, 0, pi/5)
radial_circles(xy(4, 0), 20, 1.5, 0.3, 0, pi/10)
radial_circles(xy(8, 0), 40, 1.5, 0.3, 0, pi/20)
Their evaluation should generate the following image:
4.2.1.5 Question 65
Consider the design of flowers composed of an inner circle around which radial circles are arranged, corresponding to the petals. These circles should be tangent to each other and to the inner circle, as shown in the following image:
flower(xy(0, 0), 1, 10)
Define a flower function that receives the flower’s center point, the radius of the inner circle and the number of petals.
Test your function with the following expressions:
flower(x(0.0), 1.0, 10)
flower(x(3.6), 0.4, 10)
flower(x(8.0), 2.0, 20)
Their evaluation should generate the following image:
4.2.1.6 Question 66
Define a circles function capable of creating the illustration presented below:
Note that the circles’ radii follow a geometric progression with ratio \(\frac{1}{2}\). In other words, the smaller circles have half the radius of the adjacent larger circle. The smallest circles must have a radius greater or equal to \(0.1\). The function should have as parameters the center and radius of the larger circle.
4.2.1.7 Question 67
Define the saw function that, given the point \(P\), the number of teeth, and the length \(l\) and the height \(h\) of each tooth, draws a saw, with the first tooth starting at \(P\) as presented in the following image:
4.2.1.8 Question 68
Define the squares function capable of creating the illustration presented below:
Note that the dimensions of the squares follow a geometric progression with ratio \(\frac{1}{2}\). In other words, the smaller squares have half the size of the larger squares at whose vertices they are centered. The smallest squares must have a length greater or equal to \(0.1\). This function should have as parameters the center and length of the largest square.
4.2.1.9 Question 69
Consider the flight of stairs outlined in the figure below, designed to overcome a slope \(\alpha\).
Define the stairs_slope function that receives the point \(P\), the angle \(\alpha\), the depth \(d\) and the number of steps \(n\), and builds the flight of stairs described in the previous schema.
4.2.1.10 Question 70
Consider the flight of stairs outlined in the figure below, designed to overcome a slope \(\alpha\).
Note that the steps’ dimensions follow a geometric progression with ratio \(f\), i.e., given a step with a depth \(d\), the step immediately above has a depth of \(f \cdot d\). Define the stairs_geometric_progression function that receives the point \(P\), the angle \(\alpha\), the depth \(d\), the number of steps \(n\) and the ratio \(f\), and creates the flight of stairs illustrated in the previous schema.