Grasshopper Attractors

From TOI-Pedia


Result of this tutorial

This tutorial will cover the basic understanding of use of attractors in Grasshopper and will explain this by an example of a parametric componenten system that relates to an attractor. The design for this tutorial will be a simple canopy that will be populated by components. The components will have openings that are parametrically linked with a point that represents the sun.


Using a curve as an attractor to define the radius of a grid of circles .
Creating a Hexagon grid and a rhino curve.
Closest point on curve tool.
Compute a number of values with a larger than function.
Function with one variable.

Attractors in parametric design can have multiple applications. They can be used in pattern design, but maybe more interesting is the application in performative design. For instance optimizing a facade to certain performance towards the sun. The example in the right image of this text is showing a curve attractor that defines the radius of a grid of circles. We will now very quickly go trough the steps that were undertaken to generate the result of this image at the right before we start our design.

First thing we do is creating a Hexagon grid. Go to:

Vector » Grids » Hexagonal

Connect a slider to the S (Size of the hexagon radius) input of the 'Hexgrid' and set this slider to 2. Next you connect one slider to both the Ex and Ey inputs of the 'Hexgrid' component to control the number of hexagons and set this slider to 30.

Then draw in your Rhino screen a random curve on top of the hexagon grid as in the image on the right.

Now we are going to give a relation between the center points of the hexagons and the curve. We are going to find the closest point on a curve comparing to all the center points of the hexagons. We use the 'Curve CP' tool. You can find this tool at:

Curve » Analysis » Curve CP

Connect the curve you created before to the C input (Base curve) of the 'Curve CP' tool and connect the p output (Points at grid centers) of the 'Hexgrid tool' to the P input (Test points) of the 'Curve CP' tool.

We are going to analyse the distances between the points and compute them against a larger then test. The true false values of this test will be the input of a dispatch. For the explanation of the dispatch function, you can read the grasshopper tutorial 6. First we need to create a 'Larger Than' operator. You can find this operator at:

Math » Operators » Larger Than

Connect a slider to the A input of the 'Larger Than' operator. Connect the D output (Minimum distance between test point and curve) of the 'Curve CP' tool to the B input of the 'Larger Than' operator. Then connect the > output of the 'Larger Than' operator to the true false index of a 'Dispatch'. Then connect the p output (Points at grid centers) of the 'Hexgrid tool' to the L output (List to filter) of the 'Dispatch'. Now we have to define what these A and B outputs of the 'Dispatch mean. We will tranfer these outputs to two different circles. Create two Circle components.

Curve » Primitive » Circle

Connect the A output of the dispatch to the C input (center point) of Circle 1 and connect the B output of the dispatch to the C input of Circle 2. Now we have to define the radius for both circles. We create two simple math functions related to the Hexagon radius siler we created before. Create two functions with a single variable.

Math » Script » Evaluate

Type in the first function: X/2 and for the second function X/8. Then connect the outcome of the first function to the R input (Circle radius) of Circle one and do the same with the output of function two with Circle two. Turn the visibility (preview) of all youre grasshopper components off except the preview of the circles. You will now see on you rhino screen Larger circels following the attractor curve.

You now now a basic example of use of attractors. The design of this tutorial will use a little different logic but also will show an other example the application of attractors in grasshopper.

The Design

Visualisation of the relation between the components and the point the represents a sun.

In this tutorial we will create a simple canopy that will be populated with components that are related to a point in the air that represents the sun. The shading components will point towards the sun but will not allow direct sunlight into the canopy.

Building the grasshopper model

Step 1 - Starting the grasshopper model

The start scene needed for this tutorial.
The steps in the creation of the components.
Trianglulation of a surface with an isotrim.
Selecting the midpoints.

To start this tutorial you first need to recreate the scene as shown in the image in the right. You need to create in Rhino a double curved canopy and a point floating in the air. When you are done with this you can start grasshopper.

In the image at the right you can see the steps that er needed to create our shading components. Every curved triangle component has a negative twin component. One is directing towards the attractor point and the other in the negative direction of it's twin. The first step is dividing the squares in triangles. The second step is creating the help lines that define the geometry of the components like the arc you see in the image. The third step is lofting the help lines. And in the last step you see the components without the help lines.

As said before, the first grasshopper task is to triangulate the rhino surface . We will not go deep into this because this topic is allready been coverd in Tutorial 3. Your start definition should look like the image in the right. These triangles will be the basic geometry of our components.

We now continue with the created triangles (the planar surface components) to create the help lines needed to define the geomtery of the components. To work with the triangles we need to explode them in to there 'Brep components'.

Surface » Analysis » Brep Components

Next thing is selecting the A edges of the triangle as in in images at the right. Use a 'List item' component and connect it to the E output (edges of brep) of the 'Brep components'.

Sets » List » List Item

Use a slider to control the item index of the 'List item' component. Set the slider at the right value to select the A edges as in the image at the right (don't just copy the value from the screenshot, the double curved rhino object you draw as a base for this tutorial is different then the one used to make this tutorial and this can influence the order of curve edges.

Divide these curves with equal lenght segments:

Curve » Division » Divide Curve

Set the number of divisions to two. Then make a new 'List Item' component. Connect this 'List Item' to the P output (division points) of the 'Divide Curve' component, and set the item index to 1. Now you have selected the midpoints of the A curves as in the image right above.

Step 2 - Creating the link with the attractor point

Line between midpoints and attractor point.
Result of step 2.
Selecting the start mid and endpoints
Error with the IntCrv
Data matching problem
Data matching problem
Interpolated curves working

From the midpoints from last step we will make the connection with our attractor point we created in the beginning of this tutorial. From this relation each component will be defined by two variable relations with the attractor, the direction towards the attractor point and the distance between the attractor point and the midpoints.

To select to rhino point in grasshopper you need a point primitive.

Params » Geometry » Point

Then draw multiple lines between the two midpoint lists from previous steps with the use of a 'Line' component for each list. Make sure you connect the midpoints to the A input of the 'Line' component and the attractor point to the B input.

Curve » Primitive » Line

All the lines will be divide with the same ammount of divisions. This will mean that if the lenght of the lines are variable, then also the division lenght between the points will be variable. So if the midpoint is further away from the attractor point, the divison between the points of the curve will be larger. Use 'Divide Curve' to divide the lines and set the division number to 20.

Now create a new item lister ('List item') and set the item index to 1. Your grasshopper model from step 2 should now look like the image at the right.

We use the same curve as the midpoints are created from to select the start, end and midpoint of these curves. In the image at the right you see to where you need to connect an 'End Points' component. In the image at the right the midpoint is only generated for one of the two triangle series. You should do the same for both triangle series. For the 'End Points' node you got to:

Curve » Analysis » End Points

From the start to the mid to the end points we will draw an interpolated arc. Create a interpolate node:

Curve » Spline » Interpolate

When you connect the start mid and end points to the the Interpolate node (IntCrv) you see that the IntCrv is giving an error. This is because a problem with data matching.

When you use a 'Param Viewer' you can see the tree structure of the lists and discover the problem. The tree structure should be the same for all the list. Both the the start and end points have a list structure like {0;0;A;0;0} but the midpoint list is like {0;0;A;0;0;0;0}. We are going to simplify all the list to a structure of {0;A} so they are all the same. To find the 'Param Viewer' go to:

Params » Special » Param Viewer

We will use a path mapper to change the tree structure of the lists. Find the 'Path Mapper' at:

Sets » Tree » Path Mapper

When you double click on the path mapper you will see a Lexer Combo Editor popping up. In this editor you can type the source tree structure and the target tree structure. For the start and endpoint list type {0;0;A;0;0} as source and {0;A} as target. For the midpoints use {0;0;A;0;0;0;0} as source and also {0;A} as target.

After the interpolated curves are working, a single component should now look like the image at the right.

Step 3 - Lofting the curves

Selecting curve A and B
The flipped loft of an individual component.
The loft after the curve has been flipped.
The elevation of the current and the target component.

To make the surfaces of the components we need to loft each interpolated curve with an edges curve of each triangle. To select the right curves we need to go back a little bit in the script. After the surface was triangulated and divided in two sub lists of planer surfaces, two 'Brep components' nodes were placed to explode the planar triangles into it's components.

We need to select the A curve for the first triangle list and the B curve for the second triangle list from these 'Brep components' like the image at the right. Use an 'Item Lister' to select these curves and use a slider to find the right item index to get this result.

Both curves will be lofted with the interpolated curves from the previous steps. Before you loft them you need to add new 'Path Mapper' again. The tree structure source of the listed A & B curve is {0;0;A;0;0} and should be targeted as {0;A}. When you loft them you would see the individual component doing something like the image at the right. The loft is twisted and that is because the A & B curve need to be flipped before they are lofted. Create af 'Flip' node in grasshopper to flip the curves:

Curve » Util » Flip

With the flip curve node your component should now look like the image at the right. Every square is divided with two triangles that have a curved based on a three point arc pointing towards an attractor point.

Both triangles from each square are pointing in the same (positive) direction. The next and last thing we will do for this tutorial is turning one to the opposite (negative) direction of it's twin triangle. To do this we need to analyse the direction of one of the moved midpoints so we can get the opposite direction.

Step 4 - Getting the negative twin component

The location of the new 'List Item'
Connect item index 0 to A and item index 1 to B
Connect item index 0 to A and item index 1 to B

Go back to the part of the script were we created the link with the attractor point. Make a new 'List Item' and connect this to the point output of the 'Divide Curve' node as in the image at the right. This time we will NOT do this for both triangle series but only one as in the image.

Set the item index of the newly created 'List Item' node to zero.

We will now analyse the vector between the index 0 items and the index 1 items of the same points from the 'Divide Curve' node list. Go to:

Vector » Vector » Vec2Pt

Now connect the 'List Item' node with the index 0 to the A input of the 'Vec2Pt' and the 'List Item' node with index 1 to the B input.

We now need to reverse this vector from the 'Vec2Pt' node to get the negative vector. Use the 'Reverse' component for that:

Vector » Vector » Reverse

This reverse vector will be used to move the point from the 'Item List' with the 0 index. Create a move node:

Transform » Euclidean » Move

Connect the recenly created 'Item list' with an 0 index to the G input (base geometry) of the move node. Then connect the vector from the 'Reverse' node to the T input (translation vector) of the move node. You will now have your negative midpoint that will be used to create the negative curved triangle component.

Connect this new moved point list to the the previous midpoint that was used to create one of the arcs with the 'Interpolate curve' nodes like in the image at the right.

You now have finished the script. Play arround and move the attractor point and see how the components react on it.

Personal tools