# Residential Buildings Complex Boundaries Generation Based on Spatial Grid System
## 4 Algorithm
### Generation of 10 by 10 and 20 by 20 Arrays  
This array is the middle step between generating the first sketch and the final array. Every cell value is split into four values as shown in the array:  
\[\left[ \begin{array}{ccccc}c_{(0,0)}\rightarrow\left(\begin{array}{cc} \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(1,0)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(2,0)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(3,0)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(4,0)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)\\ c_{(0,2)}\rightarrow\left(\begin{array}{cc}\ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(1,2)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(2,2)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(3,2)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(3,3)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)&c_{(4,3)}\rightarrow\left(\begin{array}{cc}\ldots& \ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \ldots&\ldots\\ \end{array}\right)\\ \end{array} \right] \tag{12}\]  
Isolating one cell from the 5 by 5 array transformation can be presented as:  
\[c_{(0,0)}\rightarrow\left( \begin{array}{cc}c_{x(0,0)}&c_{x(1,0)}\\ c_{x(0,1)}&c_{x(1,1)}\\ \end{array} \right) \tag{13}\]  
In this case value of the cell \(c_{(0,0)}\) is equal to the sum of values \(c_{x(0,0)}\), \(c_{x(1,0)}\), \(c_{x(0,1)}\), and \(c_{x(1,1)}\). If the value of the 5 by 5 cell is zero then four values corresponding to this value in a 10 by 10 array are 0. Similarly, if the same value is 16, then all four values are equal to 4. When the value is between 0 and 16 first step is to split the number with the rule then no 10 by 10 cell can have a value greater than 4. In order to have a solution without empty cells in the middle of the grid, cells values are preferably 4 or 0. Only one cell out of four per transformation can have a value that is different than 0 or 4. A list of four values is then applied in the 10 by 10 array based on the surrounding cells. If the values of cells around the observed cells are 16 and 0, then minimal values from the list are positioned close to other 0 values, and maximum values of the list are positioned close to cells with value 16. An example of this method is presented in Figure 5.  
The next step is the transformation of a 10 by 10 array into a 20 by 20 array by simple transformation rules. This method for generating the final array has rules similar to the rules from the previous chapter. Every cell of 10 by 10 array is transformed into 4 cells of 20 by 20 array. A value of 0 means all cells are zero. A value of 4 means that all four cells have a value of 1. Values between 0 and 4 are written as a list of four numbers that are either 0 or 1. The sum of the list is equal to the value of the cell from the 10 by 10 array. Similar to the solution shown in Figure 5, minimum values are placed near adjacent cells with a value of 0, and maximum values are placed near cells with a value of 4. The algorithm was designed to validate the final array where solutions that have empty cells in the middle of the building, solutions that are split in more than one building, and solutions that have a different sum of the array from the input number are excluded.