Programming Course

Chapter 6

Mathematical Programming

6.1 Hierarchy and Similarity

Hierarchy and similarity are two prevailing characteristics of almost all natural and artificial objects. Hierarchy describes the structure of objects that are composed of interrelated parts. Each part may in turn consist of a hierarchical structure and so on, until the lowest level of elements are reached. Similarity is defined as common motives that appear repeatedly in one or a group of objects. Some parts of an object may become identical to other parts of the object after going through some sorts of transformations. Hierarchy and similarity are two fundamental principles used for the simplification of complexity. For example, given an object that is composed of a sequence of elements represented with letters a, b and c, a hierarchical system can be used to simplify the description. Let the object be:

bbaccabccabcbbaccabccabcbbacbbaccabccabcbbacbbacbbaccabccabcbbac.

In this sequence of sixty four letters, the patterns bbac and cabc can be found repeatedly. If we represent these two patterns with V and W respectively, the object becomes VWWVWWVVWWVVVWWV. In this sequence there are again repeated patterns of VWWV and WWVV. By substituting X for VWWV and Y for WWVV we are able to represent the entire sequence with XYYX. Summing up the three levels of representations with equations, we get "XYYX: X=VWWV, Y=WWVV, V=bbac, W=cabc", a shorter and clearer description of the original case. Compared to many more realistic cases, the information that is simplified in this example is minor. In architecture, people are used to describing a building with plans, sections, elevations, and details. This is possible only through the recognition of the hierarchy and similarity in the complex structure of a building.

Computer programming can be seen as a process of identifying hierarchy and similarity within complex problems. For example, a function can be written that calculates the area of rectangles by multiplying the width by the length. Such a function depends on the fact that all rectangles are similar in that the four sides of every rectangle are connected by means of right angles. If this similarity did not exist, then the function would fail. In the sequel, we show some examples and strategies for using hierarchy and similarity to describe complex shapes with programs.

6.2 Parametric shapes

The most fundamental strategy for expressing similarity in a program is parametrization, that is finding properties that remain unchanged (e.g. a square has four sides, this number does not changed regardless of the square's size or location), and parameters that may change (e.g. the length of its sides, rotation angle and location). A square can be defined as a closed, four-sided shape formed by connected lines in a plane which are equal in length and meet at 90 degree angles. If we know the precise length of a side, it can be drawn, i.e. represented as a figure in a medium. Further, if we know its location in some reference coordinate system, it can be accurately placed in space. This is the very process of parametrization. This is the process which is at the heart of most CAD computer programs. A parametric shape is an abstract description of a set of shapes. The abstract description specifies a mapping from a set of parameters to a set of shapes. When all parameters of a parametric shape are assigned with acceptable values, the mapping defines an actual shape.

Most entity creation commands in AutoCAD use such parametric definitions which are programmed as functions with variables. When you invoke one of these commands, you provide specific values for variable parameters. AutoCAD then constructs a representation of the object and stores the information in an internal database.

It is not only the drawing entity commands that are parametrized. For example, when an object is moved from one place to another, its shape and size remain the same, only its location gets changed. These operations, known as transformations, can be expressed as parametric actions as well. Examples of transformation operations are: translate (move), scale, rotate, mirror (a special case of the scale operation), and other AutoCAD editing commands.

There are some techniques that can be used to parametrize complex sets of shapes based on the principle of finding inherent hierarchy and similarity. Basic techniques include finding the common proportion, symmetry or rhythm within one or a set of shapes. The following sections introduce two powerful techniques for defining sets of parametric shapes that are more complex.

6.3 Dimensionless Representation

Parametric representations can be used in quite intricate ways to represent and study architectural designs. By abstracting certain properties or relations and suppressing other details, it is possible to develop computer programs that work with different kinds of abstractions (parametrized data), and generate designs. The following examples illustrate some representations that have been developed in this way.

The following patterns were generated using a parametric program; using a very simple generative strategy. A unit square or rectangle is divided by a fixed number of lines. End points of dividing lines shift just a little bit in each successive unit across and down the plane of the pattern. By restricting these changes to small magnitudes, the generated pattern appears to slowly change across the plane. Similar patterns which used organic motifs were first created by M. C. Escher in his wood cut prints.

6.4 Procedural Similarity

Shapes that are generated by recursive processes can be seen as containing procedural similarity. Sometimes such similarity can be embedded in the shapes in very intricate ways. For example, the shape that is shown in the figure for Exercise 5 is generated by a recursive process. It is not easy to figure out how each of those repeated patterns can be drawn correctly by looking at the drawing. However, when you have finished the exercise, all of the difficult decisions regarding positions and dimensions of patterns become very natural and clear within the scope of this short and simple recursive process. In principle, such shapes can be described by three components: the initial condition, the recursive function, and the number of recursions. Fractals are shapes that can be generated according to this principle with the number of recursions approaching infinity. In practice it is impossible to run a recursive process infinitely many times to show the exact shape of a fractal. However, shapes that are generated by a finite number of recursions can be regarded as approximations of a fractal. The following figure shows some examples of fractal approximations and how they can be specified by procedural similarity. In these examples, the recursive process is described with productions. A production is defined by two parts separated by an arrow. One part is at the left of the arrow, the other part is at the right of the arrow. In each recursive process, all occurrences of the left part of a production in the shape are substituted by the right part of the production. A recursive process may consist of more than one production. In the actual implementation, such a process is usually defined as a recursive function. Parameters can be used in various ways to specify the initial condition and the number of recursions. It is also possible to define the recursive process as a parameter so that the program can be used to generate a broader range of shapes.


Exercises 6a and 6b each count as full exercises towards those required for a Testat. You may choose to do either one or both, according to your own interest.

6.5 Exercise 6a - Parametric Designs

The figure in section 6.2 shows parametric designs that vary over a plane i.e. each pattern is not continuous, rather each unit within the pattern is slightly and systematically altered enough to make it different from all its neighbors, but maintain the similarity of the set. The following figure shows a set of designs generated using a different kind of a parametric program.

Your task is to develop a program that can generate a variety of patterns as shown in section 6.2, or a variety of designs for window profiles as shown below. You will have to study a selected design, identify the minimum number of parameters that you will need, and develop a program to capture the generation process. You are not allowed to use commands like copy or array!

Besides the program file, you are also required to submit a snapshot which shows various designs generated using your program.

6.6 Exercise 6b - Fractals

The following figure shows some examples of approximated fractals and their construction rules in a graphic format. In this exercise, you have to select at least one fractal and write a program that generates the selected shape.

Submit your program file and a snapshot showing some sample compositions generated by your program.