Rotated Polygons on a Grid – Example 1.1


This is a very basic exercise for creating a simple, dynamic pattern, and introduces some basic concepts regarding data structuring. I will explain the script in a fairly straightforward manner, and afterwards will go through it again with a little more detail about the concept of data structuring, since this will be a very important topic going forward.

To generate this pattern, the script goes through a process of three basic steps, with a fourth optional step to give the shapes a color.

Step 1 – Setup a Basic Organizing Grid


Set up a grid of points. While we are setting it up, I will use a 3×5 grid and will later expand it to 10×10 to show some variations. Usually, it is best to start setting up your scripts with smaller sizes for things until you get the details worked out, and once it is working well, you can easily expand it to any size (within reason). Its usually best to keep things small though while you are setting it up.

For this example we will use a basic “Square Grid” as the structural device for our pattern. Later, you can experiment with some of the other grids to see how the pattern can change with other organizing principles. The “Square Grid” component has 4 inputs and three outputs. For now we are ignoring the first “P” input (which is the starting “Point” for the grid). If you put no value into here, the grid will start at 0,0 by default, the world origin. The next value, “S”, is the size of the cells. The third and fourth value are the number of cells in the X and Y directions respectively.

You can see that this particular component has two outputs. The first output is “C”, the cells themselves. This geometry, when displayed, is equivalent to the grey lines in the image above. The second output is “P” which are the corner points of the cells (displayed in pale blue in the image above). These are the corner points of the cells. Notice on this particular 3×5 grid, the grid of corner points is actually equal to 4 x 6 (24 points in total). We will see in the next step, but if we want an actual 3×5 grid of shapes in our pattern (15 points total), the best thing is probably to use the center points of the cells. To get the center points, we use a component called “Area.” This component is used VERY frequently. It also has two outputs. The first, “Area”, in this case is not too useful for us, but the second, “C” is equal to the center point of each piece of geometry.

Although not completely necessary, I often like to put geometry, especially when moving between major steps in my script, into Parameter containers. You will see that I fed the output of the Area component “C” into a “Point” container. I also put it into a “Group” by itself and labeled this group with what is in the container. You may not do this at first, which is fine, but as you work with grasshopper more and more, you will learn why this is beneficial.

One more thing, a very basic thing in Grasshopper beginners sometimes forget. Grasshopper never “deletes” old geometry. You are creating a multi layered drawing. Usually, you only want to see the “latest” or top layer of your drawing. To turn previous drawing layers OFF, right click a component, and then click “Preview”.  For example, after you draw your grid and your center points, you probably want to turn the original grid OFF. Right click the SqGrid component and turn the Preview Off. Components whose products are displaying are a white color, while components whose preview is off are a darker grey.

Step 2 – Draw a piece of Geometry at Each Center Point


Now that I have a grid of points, I want to draw a certain shape at each one of these points. In this case, I will use the “Polygon” component to draw five sided pentagons, although this can be quickly changed to other shapes if I would like.

The Polygon component also has four inputs. The first, “P” represents the center point of the polygon. I will use the points from the last step and input them here. Grasshopper will draw the indicated polygon at EACH of the points I input into the component. The three other inputs affect the geometry of the Polygon. They are Rradius, Segments (Sides), and (Rf)Fillet Radius. I can change the number of segments to any number 3 or greater, although larger than 12 or so and the shapes will get awfully close to circles. 3 will draw triangles, 4 will draw squares, 6 will draw hexagons, etc… In this case I want pentagons so I input 5. If you want rounded corners, you can change the last parameter, but this is optional.

Step 3 – Rotate the Polygons in Series


The last major step is to rotate the shapes in a sequence, with a predefined angle increment determined by a “Series” component. The shapes I am rotating are located in the “P” output of the Polygon component. To do the rotation, I first use the “List Length” component to measure to total number of values in the “P” output. This list measurement is input into the Count input of the “Series” component. The other input into my series is the iNcrement of the rotation. In the example above, the shapes will rotate with a small (20 degree) increment moving through each shape, starting at the bottom right hand corner  and moving up the column until reaching the top. Because of the way my data is structured (more on this soon), the second and third columns get the exact same rotation sequence as the first column (Shape one, 0°; two, 20°; three 40°…. )

All of this is then input into the “Rotate” component. This has three inputs. The first is the Geometry we want to rotate, in this case our Polygons. The second is the Angle of rotation. Note that by default this angle is in “Radians.” Since most of us are more used to working in Degrees, we either need to convert the values from our Series (which are in degrees) into Radians before inputing them into the Rotate component using a “Radians” component (see image Top Left), OR we can right click on the “A” input on the Rotate component, and change the default setting to accept “Degrees°” instead of Radians (see image Bottom Left). The last input you have to worry about is the center Point of rotation. Since each shape is rotated around its own center, we again measure the shapes with an “Area” component and use the “Center Point” output for this. (Note: You can also use the center points already drawn in “Step One”)

Out shapes will now rotate. You won’t see the grey areas shown in the image above, or the dashed grey lines (these will show up as red lines, however, if you don’t turn the preview OFF for the Polygon component) These are only for reference to make it clear how the rotation is working. Also note that the first piece of Geometry doesn’t rotate. Well, actually, it does rotate in theory, but since the first value in our series is “0°” it rotated exactly that much. If you DID want the first shape to rotate as well, you would have to input a value into the Start input of the “Series” component.

Step 4 – Coloring your Shapes


Once you have all the geometry drawn, you may want to give the shapes some color. To do this, you first need to convert the shape outlines into a surface using the “Boundary Surface” component. Its only input is the Edge of the surface or surfaces. Once this is done, we can use the “Custom Preview” component along with a color “Swatch” to see what it looks like. Click the swatch to adjust the Hue/Saturation/Value and Transparency. Also notice, all previous geometry now has its preview turned OFF. Only the Custom Preview component is white, hence on.



Now that the script is up and working, I want to experiment with the pattern a bit to see what kinds of variations I can create. I can adjust any parameter, but ones you might want to play with are the Angle Increment in the Series, the Number of Sides, and the Radius of the Shapes. You can also change the size and extents of your starting grid.

Three Basic Data Structures

Three Basic Changes to Data Structure

One other thing you can play around with is the “Data Structure” of the center points of the grid. Go back to the “Pt” container from Step One (the container after the “Area” component.) Right click this component and you will be given an option for “graft” and one for “flatten”.  Try these both out to see how the pattern changes. If the data is “flattened”, an arrow pointing down appears. If “grafted” and arrow pointing up.

A Bit More on Data Structuring

So what is going on with these “flattened” and “grafted” data structures.

To illustrate, here is a smaller 3×5 Grid of Points (15 points). If you imagined for a minute these were apples and you were packaging them to sell, you could put all 15 apples into one container, into 3 containers of 5 (or 5 containers of 3), or you could package each individual apple separately. How you package the apples affects how you sell them and how many you sell.

Likewise, data in Grasshopper is gathered into lists. These lists use a metaphor of a tree for the structuring of data. A normal tree might have items grouped into branches, while a “grafted” tree puts everything into its own individual branch. I will talk more about this later, but each branch of a list has a numbered series of items, starting 0, 1, 2, 3, ….

Flattened items are put into one single List. (no branches, one single package) So in the example below you have one list of 15 points. Each triangle associated with a point is rotated in series moving down the list (0°, 10°, 20°, 30°, 40°, 50°, 60°…. 140°). Note the ordering of items in the square grid (Starting bottom right and moving up the columns, then to the next row)

The “Normal” structure for a grid of points in Grasshopper orders items in lists by columns. So a 3 x 5 grid of points is sorted into three lists of 5 items (three branches with five items, or three packages with five items, depending on the metaphor). When the series of rotations is applied, it is applied in the same way to each each of the three branches of the list. So Item 0 in EACH branch is rotated 0°, item 1 is rotated 10° in each of the three branches, and so forth). If you want to change the “Normal” structure to order things by rows instead of columns, you can use the “Flip” component to do this.

When the data is grafted, each point is put into its own branch, its own list, or its own package, whichever metaphor you want to use. So the series of rotations doesn’t really do anything, since every item zero is rotated 0°. So in this case the rotate function is unnecessary. But trying to understand this concept now will help a bunch in the future!


Displaying Data Structure in Grasshopper

To see how data is structured, it is often very useful to use a “Panel” component after any operation to see how the data is being structured. The image below shows the basic elements of a “list” with the structuring in Branches, the identification of branches, as well as the “Item Index”


The image below shows five various ways of structuring our data coming out of the grid, and how the Panel List display is subsequently affected. The default, a “flattened” data structure, a “grafted” data structure, flipping the default data structure, and flipping and flattening the default data structure. Note that if you change the data structure right after identifying the Center Points, all future operations will also inherit the same data structure. This includes the “Series” component and the “List Length” component. The chart below also shows how the series component changes with the different data structures, and ultimately how the polygons are rotated based on these points and rotational angle series.


One last thing, if you are careless with your data structuring, you may at some point get “incompatible” lists like the one below. In general, your lists should be structured the same whenever you are trying to do operations. Lets image though, that you get a series of rotations based on the normal data structure, but right before rotating your polygons, you decide to graft your points. The computer will still try and perform the operation, only the results will probably not be what you are expecting.


Why does this matter? Well, the way you structure data has a huge effect on what you are able to do with algorithms. This will be a recurring issue and recurring headache, but understanding this concept is essential to doing innovative designs later. Anyways, enough of that for now…

Lastly, for reference, here is a screenshot of the Rhino – Grasshopper Script


Click Here to Download GH File