# Attractors

## Contents

## Introduction

**LEVEL: ADVANCED**

Expected Time: 90 min

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.

The tutorial consists of two parts:

- A basic example of 2D attractor
- A design for an attractor canopy

## Attractors

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.

Create a hexagonal pattern using the respective component. Define the X and Y size using a numerical input.

- Add a Hexagonal component to the canvas
- Define the X and Y size with a Number Slider

Draw a curve in the hexagonal grid. The curve may intersect with the boundary of the grid. Set the curve to a curve parameter in the Grasshopper script

- Draw a curve through the grid in Rhino
- Add a Curve parameter to the canvas
- Set the curve to the parameter

Now we want to find the distance between the hexagon centers and the closest point on the curve. This can be easily done using the Curve Closest Point component.

- Find the distance between the curve and the hexagon centers

Next, we want to remap the available distance values to another range. Since we have done that several times already, we will not explain this extensively. Make sure you first **flatten** the distance output! If you are having trouble understanding the remapping, take a look at Tutorial 12.

- Flatten the distance output
- Find the bounds of the distance values
- Remap the values
- Define the Target domain using a Construct Domain component

Based on the remapped distances, we create circles with the hexagon centers as origin. The radius is defined by the remapped distance. Make sure you flatten the Plane input.

- Add a circle component to the canvas
- Flatten the Plane input and connect the hexagon center points
- Define the Radius with the remapped numbers

To make the result a bit more visible in 3D, we can of course also extrude the circles based on their distance to the curve. One method could be to remap the numbers again, but in this case, we will use a simple multiplication and a Z Unit vector to define the height.

- Connect a Unit Z vector to the Mapped output
- Multiply the Unit Z vector with a factor
- Extrude the circles using the Multiplication output as Direction

Finally, you will have to cap the cylinders.

- Cap the cylinder holes

The result is a cylindrical pattern in which the size of a cylinder is an expression of the distance to the curve.

As alternative, you could also create a script where cylinders are removed if they are lower than a certain distance limit. This would lead to the following adjustments.

Now your final model looks like the following image.

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

## The Design

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 - Creating the canopy with openings

First we need to create a basic shape for the canopy. It doesn’t really matter how it looks like, but you can take the right picture as reference. One method could be to use the Rhino Sweep1 command. Based on one center curve and two section curves, you can create a surface like the image on the right. Next, set the surface on a Surface parameter.

- Create a surface in Rhino
- Set the Rhino surface to a Grasshopper surface parameter

Now we need to divide the surface in triangular openings, which will be used for the shading component in a later stage. Therefore, we can use the first part of Tutorial 17 - Populate Surface. In the right image, you can see the script. The output of the script is the stage where the triangles on the surface are created using the polyline component.

- Recreate the first part of Tutorial 17 - Populate Surface
- Connect your referenced Rhino Surface to the script

Your models should now look like the following image.

### Step 2 - Create the shading component base

The shading component will be created as you can see in the following illustration.

- 1. We use the triangles of the surface as base.
- 2. The top and bottom of the shading surface is reshaped to a curve, perpendicular to the surface normal, based on an attractor point.
- 3. The side edge of the triangles is lofted to the new created curves
- 4. All shading components are implemented into the roof

First we need to deconstruct the triangles in faces, edges and vertices using the Deconstruct Brep component. After that we use a list item component to find the top and edge of the triangle. In most cases you can use the Index input to 0. We will also need the side edges in a later stage, so it can be helpful to click on the +1 icon, to also extract that edge.

- Deconstruct the polylines
- Find the top and bottom edge of the shading component using a List item
- Also extract the side edges for a later stage

*If you are not able to find the top and bottom edge of the triangles using Index 0, try another value for the Index input.*

Now we find the middle of the top and bottom shading edge, using the Curve Middle component.

- Find the Curve Middle for the top and bottom edge

### Step 3 - Creating the attractor

In this tutorial we will use a point as attractor object. This point could represent the sun for example, to define the direction of the shading system. First create a point in Rhino, preferably above your canopy surface, and set it to a Grasshopper Point parameter.

- Create a point in Rhino
- Set it to a Grasshopper Point Parameter

To visualize the attractor, we create a line between the Curve Middle Points from the previous step, with our attractor.

- Create a line between the Curve Middles and the attractor point

Now we find a point on the line which will define the height and location of the canopy shading components. One method to do this, is to use the Point On Curve component.

- Find a point on the lines to the attractor using the Point On Curve component

As described in the step 2, we need to create a curve between the original top and bottom edge of the shading component, and the point on the attractor line. First we find the end points of the top and bottom edge.

- Find the Start and End point of the top and bottom edge of the shading components

Now we merge the points in the correct order: first the start, then the Point on Curve, and finally the end.

- Merge the points for the curve

*The merge component can be useful to make sure you are using the right order to create some geometry. Only holding the shift-button to connect some wires to an input, can lead to an incorrect order of data an lead to unexpected results.*

Finally we interpolate the points using the Interpolate Component.

- Interpolate the merged points

Your model should now look like the following image. When you change the location of the attractor point, the curves top should move to another location. Changing the Point On Curve slider defines the height of the canopy shading components.

### Step 4 - Lofting the Curves

Now we want to create a surface between the shading curves and the side edges. Since the original triangle polyline is created in the direction of the polyline, we have to flip the diagonal line directions first. You can find the side edges in the output of the List Item component. Make sure you check if you are using the correct triangle edges.

- Flip the direction of the side edges

By lofting the side edge and Interpolated Curve we can create the shading component surface. Make sure you first simplify the Curve output, to match the data tree of the side edges!

- Simplify the Curve output
- Loft the side edges and Interpolated Curves

As you can see in the following image, by simplifying the Curve output, the data tree matches to the side edges.

Now our model looks like this. Unfortunately, both triangle surfaces of the shading component, are in the same direction. In the final step we will fix this.

### Step 5 - Getting the negative twin component

In the final step we will make sure the negative component of the shading system will be inwards, as displayed in this image. To do this, we need to analyze the direction of one of the midpoints, so we can get the opposite direction.

Find the direction of one of the bottom shading triangle. Connect the Curve Middle to the Point A input of a Vector 2pt and the Point on Curve to the Point B.

- Connect the bottom Curve Middle to a Point A input of a Vector 2Pt component
- Connect the related Point On Curve to the Point B input

We now found the direction.

Next, we reverse the direction to make sure the direction goes inwards.

- Reverse the vector

Move the bottom Curve Middle using the reversed vector.

- Move the bottom Curve Middle using the reversed vector

Replace the D2 input of the bottom Merge component, with the Moved Curve Middle.

- Replace the D2 input.

Your shading system now fluently reflects the sun from your attractor point.

Finally connect the Lofted curves to a Geometry parameter.

- Finalize your script with a Geometry parameter

Your final canopy: