Generic Solutions in Grasshopper
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 Point and Tangent 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 Rail curve and Section 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:
Use thecomponent to extract the edges from the surface. This will be a single list. We'll 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 thecomponent. 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.
Finally, use thecomponent 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.
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.
Also create acomponent. RMB-click it and choose Graph types and choose a suitable graph. We've used Bezier.
Create acomponent and link the curve to it. Create a slider to control the Count input parameter. This determines the amount of divisions (x) on the curve, resulting in 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 acomponent. Start is set to 0 by default, so that is fine. The step should be 1/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 acomponent. But of course this could be any other vector as well. These vectors can be used to the points on our curve.
Use theor component to generate a new curve through our moved points.
Alternative: using a curve instead of the Graph Mapper
Use thecomponent to link them to Grasshopper. We need to create a reference curve to compare the points on our control curve to to determine the manipulation value per point. We're going to do that looking at Z values. We'll use 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.