Sunday, May 10, 2009

Packing Exercise

"Packing is a powerful organizational method in which an element's position in regard to its neighbors is determined by certain rules -- not too close, no overlapping, etc."
--Aranda, Benjamin, and Chris Lasch. Tooling (Pamphlet Architecture). New York: Princeton Architectural Press, 2006.



In order to generate the Packing algorithm, we first dimension our variables. We leave open parentheses which follow the x, y, z and dblRadius variables. This is because we will be passing values from the 'i' and 'j' loops which will be run later in the script.

We then run the 'ReDim Preserve' method when we wish to assign a value to a variable that we have left open at the beginning of the script. Passing the value '0' through each of the open variables. This gives the loop a starting point.

ReDim Preserve x(0), y(0), z(0), dblRadius(0)

Next, we run our first loop. We use the 'i' variable and set the loop to run 100 times. Again, we re-dimension our variables from above. This time we pass the variable 'i', which will insert a value from 1 to 100 each time the loop is run.

ReDim Preserve x(i), y(i), z(i), dblRadius(i)

Passing the 'i' variable through x, y and z creates a discrete amount of instances for each, depending on the number of times the loop is to be run (In this case, 100). Then, we assign a unique value for each of the 100 instances. We will the 'random' method which assigns a random value from 0 to 1. By multiplying this times 50, our values will range from 0 to 50. Because we want our circles to be drawn flat on the x-y plane, our z value remains 0. Also, we want the radius of our circles to vary randomly up to 5.

x(i) = rnd * 50
y(i) = rnd * 50
z(i) = 0

Rhino's 'PlaneFromFrame' method constructs a plane from a point and two vectors in the plane. By passing the 'i' variable through the origin parameter, we create 100 separate instances of the origin point, and ultimately the centers of 100 circles. We then set the overlap string value to 'no', And run our second loop. It is important to note that this loop is being run inside of a larger loop. For every singular instance that the parent loop runs, this child loop will run through its entirety. We have set the child loop (j) to at all times equal one less than the parent loop (i).
Therefore, depending on which instance the (i) loop is at, the (j) loop will run from 0 to 1 less than where the (i) loop is at.

For j = 0 To i-1

Now we write our conditional statement to make sure that our circles do not overlap. It is important that we check this mathematically before the circles are drawn. If not, we would have to manually erase overlapping circles and start the process over each time. We measure the sum of the two most recent circle radii in relation to their x and y coordinates.



We say "If the absolute value of the 'x' component at its 'j' position is subtracted from the absolute value of the 'x' component at its 'i' position is less than the sum of the new circle and its most recent predecessor, and the same occurs for the 'y' coordinates, then we have an overlap.

If this overlap statement is not true, then Rhino draws the circle object as intended, and moves on to the next instance of the loop.

No comments:

Post a Comment