Grasshopper: Visual Scripting for Rhinoceros 3D. David Bachman

Читать онлайн книгу.

Grasshopper: Visual Scripting for Rhinoceros 3D - David Bachman


Скачать книгу
1.6. Lofting two circles will make a cylinder.

      Following the previous method, select the Extrude component and delete it. In its place, drop a Move component (Transform tab, Euclidean panel). Connect the output of the Circle component to the “G” input, and the output of the Unit Z component to the “T” input. As you would likely guess, the Move component will now move the circle up in the Z-direction.

      Now place a Loft component (Surface tab, Freeform panel) on the canvas, above and to the right of the Move component. Connect the output of the Move component to the “C” input of the Loft component. Then, holding down the shift key, also connect the output of the Circle component to the “C” input of the Loft component, as in Figure 1.6. The Loft component is now being given two circles, and will create a surface between them.

      Our fourth method is depicted in Figure 1.7. Begin with a Line component (Curve tab, Primitive panel). Right-click on the “A” input, and choose “Set one Point.” The Grasshopper window will temporarily disappear, leaving you looking at the Rhino viewport. Select the origin. Do the same thing for the “B” input, but this time select the point (0, 0,1). (You’ll have to do this in Rhino’s Front or Right viewport. If you want to select these points exactly, it is helpful to have Grid Snaps on in Rhino.) The Line component should now make a line connecting these two points.

img

      Now drop a Pipe component (Surface tab, Freeform panel) onto the canvas. Connect the output of the Line component to the “C” input of the pipe. Just as in the Rhino “Pipe” command, the Pipe component puts a tube around the curve that is fed into it. A tube around the line segment constructed above is again a cylinder. The radius of the resulting cylinder can be adjusted at the “R” input of the Pipe component.

      Begin with the line segment from the previous method. As in the third method demonstrated previously, move this line segment one unit in the X-direction by feeding it to the “G” input of a Move component, with a Unit X component connected to the “T” input. Place a Revolution component (Surface tab, Freeform panel) on the right side of the canvas. Connect the output of the Line component to the “A” input (thus defining the axis of revolution), and the output of the Move component to the “P” input (defining the curve to be revolved). See Figure 1.8. By default, the input curve is revolved a full 2π radians (360 degrees) around the axis line, in this case creating a full cylinder.

img

       Lists

      As we saw in the previous chapter, wires in a Grasshopper script represent the flow of information between components. In each of the scripts of the previous section, there was a single piece of information passing through each wire. However, one of the things that makes Grasshopper powerful is that wires can simultaneously contain multiple pieces of information in a list. We illustrate this in our next example.

      One of the primitive surfaces in Rhino is a torus, or donut shape, as in Figure 2.1. Unfortunately, at the time of this writing this has not been incorporated as a Grasshopper primitive surface. Perhaps the easiest way to make such a surface is to create a pipe around a circle, just as when we made a cylinder by piping a line segment in the previous chapter. Here we will use a different method as an illustration of a basic use of lists.

      The torus in Figure 2.1 was made with the script of Figure 2.2. To create this script, start by dropping a Circle component (Curve tab, Primitive panel) on the canvas. Connect the “P” input to the output of an XZ Plane component (Vector tab, Plane panel). Then right-click on the “O” input of the XZ Plane component, and choose “Set one Point.” Select the point (3, 0, 0) in Rhino’s front view. Now, as shown in the figure, connect the output of the Circle component to the input of a PolarArray component (Transform tab, Array panel). By default this component creates 10 copies of its input that are obtained from the original by rotating around the Z-axis. You can change the number of copies at the “N” input, and the axis of rotation by choosing a different plane at the “P” input.

img

      Next, connect the “G” output of the PolarArray component to the “C” input of a Loft component (Surface tab, Freeform panel). Notice that the new wire looks like a double-line, rather than a single one. This is a visual representation of a list of objects passing through the wire, rather than a single object. The Loft component expects such a list, and tries to create a surface through all of these input curves, in sequence. In the Rhino viewport you should see a surface that looks like a letter “C.” It is not quite a torus because the loft operation did not connect the first input curve to the last. To fix this, attach a Loft Options component (Surface tab, Freeform panel) to the “O” input of the Loft component. Then, right-click on the “Cls” input, and select “Set Boolean.” Change from the default setting to “True,” and the surface in the Rhino viewport should change to a complete torus.

img

      A single wire can even contain a list of lists, called a data tree. We will use this idea to turn Grasshopper and Rhino into a 3D graphing calculator.

      Suppose, for example, you want to graph the function f (x, y) = x2y2. First we’ll create a grid of points in the XY-plane, and then we’ll use the function f (x, y) to obtain Z-values for these points. Finally, we’ll feed this grid into a special Grasshopper component to create a surface.

      To make a grid of points, begin with a Construct Domain component (Math tab, Domain panel). This component outputs an interval of real numbers, with the default being the interval [0,1]. As in Скачать книгу