# Generic Solutions in Grasshopper

## Introduction

This page shows generic solutions for common problems in Grasshopper.

## Sweep or Extrude a Profile Along a Curve

When you want to sweep (or extrude) a custom curve along another curve, you need to make sure that this curve is drawn at the starting point of the curve and in the proper plane. In many cases this is not practical and you would want to be able to draw the section (or profile) curve in the XY Plane in a convenient location.

The example uses three inputs:

- component which is set to the curve(s) to extrude along
- component which is set to the section (or profile) curve
- component which is set to a point to be used as a base point. Alternatively you could use a point in 0,0,0 when you draw your curves near the origin.

Use to find the start point of the given curves and the direction of the curve in that point. Input Parameter (t) is set to 0 for the starting point, while the input for the curve is set to *Reparameterize* (RMB-click on the input). The output **P**oint and **T**angent are used to construct a plane using .

With the Point parameter you can construct a plane in that point. In this case we used a , but any other depending on the plane you drew the curve in, will work.

Now we have two planes, one the profile is in and one the profile should be in. You can use to transform the curve in such a way it ends up in the plane that sits at the start of the curve. And that's or goal to make the Sweep work properly.

Using the component, we construct our surface. Note that you need to Graft the inputs for the **R**ail curve and **S**ection curve.

## Grid on Surface

This solution demonstrates one of the various methods to get a 1D grid on an arbitrary surface, for example to be used to create beams or purlins.

[[File:Start with a surface from Rhino. Use the component to link it to Grasshopper. RMB-click the component and choose*Set one surface*to pick the surface in Rhino.

Use the *Naked Edges*, which are at the border of a surface.
Using the component and a slider, we're picking one of the four sides of our surface using a value between 0 and 3. Which one you need depends on the surface. We've connected a Panel to check our list.

Next we're generating perpendicular frames on this curve, which will be used to intersect with our surface. Use the

component. Link the output of the List Item component (one of the sides of our surface) to the Curve input and create a slider for the Count input.**x-1**on the Count input, to subtract 1 from the input value.

Finally, use the

component to generate the intersection lines between the planes and our surface.### Alternative: arbitrary directions

Using a separate curve, we could manipulate the direction of the grid lines, making them run in an arbitrary direction and even not parallel.

Draw a curve along side your surface in Rhino. Use the component to link it to Grasshopper. RMB-click the component and choose*Set one curve*to pick the curve in Rhino.

Link this to the *Curve* input on the *Perp Frames* component, replacing the link from the List Item component.

In our example, we've made it a little fancier, so you can switch between both options, using a toggle button. Use the following extra components:

## Curve manipulation using Graphs

This demonstrates the basic principle of using a graph to manipulate a given curve.

In this example, a flat curve has been manipulated in vertical direction, using a graph - a bezier graph in this case.

Draw a curve along side your surface in Rhino. Use the component to link it to Grasshopper.Also create a *Graph types* and choose a suitable graph. We've used *Bezier*.

Create a **x + 1** points.

For each of these points, we want to look up a value in our graph. As you can see in the axis label, the horizontal axis for our graph ranges from 0 to 1. So for each point we need a number in the range 0 to 1, equally distributed. We'll let Grasshopper generate a number sequence that meets these criteria.

Create a *number of divisions*. We can use our number slider for that value. Either use a component, or use an expression **1/x** on the Step input. For the Count parameter, we need to add 1 to the value of our slider. Either use the Addition component, or an expression: **x+1**.

Connect the output of the Series component to the Graph. The output will be the corresponding value (vertical axis) of the graph on each of the given input values (horizontal axis). If the number of values is not too big, you'll see red vertical lines in your graph.

The output ranges from 0 to 1. This is not very useful in most cases. Let's multiply it with a scale factor. Use a number slider and a multiplication component to change the maximum of our range.

These values can be use to transform the points on our curve. In our example we translate in the Z-direction, using a

component. But of course this could be any other vector as well. These vectors can be used to the points on our curve.Use the

or component to generate a new curve through our moved points.

### Alternative: using a curve instead of the Graph Mapper

The Graph Mapper is nice and easy, but it offers limited freedom. If you want to draw a free-form shape to manipulate a curve, this method shows a method to do that. The idea is that you can use a simple curve (low number of control points) to smoothly modify a more complex curve with a high number of control points. Which would be hard(er) to do without Grasshopper. First make sure you have a curve you want to modify and a control curve. The control curve should be relatively simple for the best result. You could use a Handle Curve for it, for instance.Use the **Z=0** as a reference.

We're subdividing both curves in equal segments using

. For the Control Curve, we're using to extract the Z value of each point.This Z value can be used for any transformation. In this example a Z translation of the corresponding points in our Object Curve.

You can make endless variations on this principle, using a curve to determine rotation of objects that are placed along a curve, scale, translation perpendicular to the curve, etc.