Illustrating Mathematics with Grasshopper

I’m currently attending a week-long conference on “Illustrating Mathematics” at the Institute for Computational and Experimental Research in Mathematics (ICERM) at Brown University, in Providence, RI. I was asked to give a workshop here on using the Grasshopper plug-in for Rhino, and thought my talk would make a good blog post.

This is the first time I’ve written a tutorial type of post. I’ll try to say something useful for beginners and experts alike, but first I should say a bit about what Grasshopper is and who its for. Rhino is a popular 3D modeling program. I have the sense that it dominates the architecture world, but the majority of the artists and mathematicians I know who do a lot of  3D modeling also use it. Grasshopper is a free plug-in for Rhino written by David Rutten that allows one to build Rhino objects using a visual scripting “language.” Building these scripts involves dragging and dropping various boxes around a virtual canvas, and drawing lines between them. For example, in the image below I’ve created a circle in the Rhino window (shown on the left) by connecting a circle box to a slider at the “radius” input.

Screen Shot 2016-06-30 at 10.05.01 AM

A word of caution is in order for mac users. Since 2007 Grasshopper was only available for the PC version of Rhino. For a long time the Rhino folks were saying that a mac version was a long way off, if it were to ever happen at all. Then, out of the blue, just a few months ago they released a beta version available for the current mac Rhino3D WIP. It consistently crashes on my mac, but several people I know have been using it without any problems. Presumably it’ll get more stable over the next few months. In the meantime, I use Rhino/Grasshopper in a virtual PC environment on my mac.

It’s worth contrasting the use of Grasshopper to build objects vs building them with a traditional programming language like python, which is another option for Rhino users. Grasshopper has two huge advantages: The first is that Grasshopper doesn’t require you to learn how to code. Second, and more importantly, Grasshopper scripts are interactive. All variables in a grasshopper script can be realized by sliders, allowing the user to see how changes in parameter values effect shape in real-time. This is crucial for making aesthetic choices in object design.

Where Grasshopper really loses to more traditional programming is any place where recursion is required. Grasshopper is generally a poor choice for fractal designs, for example (although there are some third-party work-arounds that function reasonably well, such as Hoopsnake).

Fortunately, one doesn’t really have to choose between Grasshopper vs more traditional scripting (python, C#, VB). A Grasshopper box can be a user-defined python script, for example, with inputs that are realized by sliders. This gives you the best of both worlds: it simultaneously makes your python scripts interactive, and allows for “easy” recursion in  Grasshopper.

My idea for the workshop was to go through the design process that I used to create my re-usable coffee sleeve/bracelet/very-small-dog collar (available here on Shapeways).

It’s hard to see this in the pictures, but the curves in opposite directions are woven, reminiscent of the old “Chinese finger trap.” This allows it to form-fit to many cup shapes, and makes it fun to just play with. 3D-printing is the only technology I know of that can produce this design in plastic.

The woven aspect of the design was beyond the scope of a 45-minute workshop. At some point I’ll dedicate an entire blog post to various strategies to achieve a woven effect in Rhino/Grasshopper. Here I’ll just describe one way to make a shape, and create slanting curves on it in each direction. The construction I’ll give is not the most efficient way to do this, but it will illustrate a lot of the important concepts of Grasshopper design. First, examine the following image:

Screen Shot 2016-06-30 at 11.09.09 AM

From left to right: First you see a slider that will determine the eventual height of the object. This gets fed into a component that defines an interval of real numbers. That interval is then passed to a box that is set to choose 10 values in it. Those values are finally passed to the z-coordinate of a point (with the x- and y-coordinates being set to 0 by default). One important thing to note is that there is a double line connecting the third and fourth components, whereas the other components are connected by a single line. A single line represents a single piece of data being passed between components; the double line represents a list of data.

Screen Shot 2016-06-30 at 11.16.17 AM

Once the points are defined we feed them to a component that create horizontal planes centered at each point. Those planes are then given to a circle component to define a family of horizontal circles.

Screen Shot 2016-06-30 at 11.23.11 AM

After defining the circles, we choose 10 points on each. Those points then form a list-of-lists, represented by a dashed double line leaving the box. If we feed each of these lists of points in to a component that makes an interpolated curve through them, we just get the horizontal circles back. Compare that to the following:

Screen Shot 2016-06-30 at 11.26.51 AM

Here I’ve inserted a “flip matrix” box. This component re-organizes the data, creating a new list-of-lists. The first one is comprised of the first elements of all of the input lists, the second list is all of the second elements, etc. Now if we create curves through the points in these lists we get the vertical arcs shown at left.

Screen Shot 2016-06-30 at 11.31.52 AM

To make diagonal lines, we introduce a shift.  This is done with the introduction of two new boxes. The first just produces a list of integers between 0 and 9. Those are fed to a component that shifts each list of points. Note the little up-arrow by the word “shift” in the second component. That represents a “graft,” so that the first input list is shifted by 0, the second list shifted by 1, the third shifted by 2, etc. This sort of data-matching is the hardest thing to learn about when using Grasshopper.

One more thing is required to make the desired diagonal cross-crossing pattern. The reason the lines slope one way instead of the other is that we’ve shifted each list by +1. That’s controlled by the “step” input in to the “series” component shown above (the default value is 1). In the image below you see two copies of this collection of components. The lower copy is the same as before, while the upper copy uses a shift of -1. Together, you see that they give the desired effect.

Screen Shot 2016-06-30 at 11.38.44 AM

Finally, to make a 3D-printable object, we must thicken each curve into a tube. This is achieved with the “pipe” component, pictured below.

Screen Shot 2016-06-30 at 12.01.01 PM

Illustrating Mathematics with Grasshopper

Leave a Reply