Grasshopper: Visual Scripting for Rhinoceros 3D. David Bachman

Чтение книги онлайн.

Читать онлайн книгу Grasshopper: Visual Scripting for Rhinoceros 3D - David Bachman страница 5

Автор:
Жанр:
Серия:
Издательство:
Grasshopper: Visual Scripting for Rhinoceros 3D - David Bachman

Скачать книгу

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 Figure 2.3, connect its output to the input of two Range components (Set tab, Sequence panel). Each of these creates a list of N + 1 numbers in the given interval, where the default value of N is 10. Connect the outputs of both of these components to the X and Y inputs of a Construct Point component (Vec tab, Point panel). Notice the new wires are doubled, indicating the flow of a list of numbers through each, rather than a single number. When both lists are given to the Construct Point component, a point is created using the first element of both lists, then another point with the second elements, etc. The result is thus a diagonal line of points, as shown on the left in Figure 2.3.

img

      Now right-click on the N input of the second Range component and change its value to 15. The result is shown in Figure 2.4. As before, the first numbers coming in to the X and Y inputs are used to create a point, then the second numbers, etc. However, we run out of values of X before running out of Y values. To deal with this Grasshopper will simply repeat the last X input and match it to the rest of the Y inputs.

      To create a grid of points, right-click on the output of the second Range component, and select “Graft.” This changes the output from a single list of 16 numbers to 16 lists, each with a single number. The fact that the output is a list of lists is now indicated visually by a wire that is a dashed double line (see Figure 2.5). Now the Construct Point component sees 16 lists coming in to the Y input and a single list coming in to the X input. As in the previous example, since these numbers are different it will replicate the data coming in to the X input as many times as it needs to in order to match it to each thing coming in to the Y input. Thus, the X list will be matched to everything in the first Y list (a single number), and then again to everything in the second Y list (another number), etc. The result will be an 11-by-16 grid of points, as shown in Figure 2.5.

img

      To make the result a little more interesting, connect the outputs of the Range component to the x and y inputs of an Expression component (Math tab, Script panel). Then, double-click on the Expression component and type “x^ 2-y^ 2.” Finally, connect its output to the Z input of the Construct Point component, as in Figure 2.6. The result is a grid of points on the graph of the equation z = x2y2.

img img

      As a final step, connect the output of the Construct Point component to the “P” input of a Surface From Points component (Surface tab, Freeform panel). This component expects a list of points, rather than a list of lists. To change the input data structure back to a single list, right-click on the “P” input and select “Flatten.” Finally, set the “U” input to 16, indicating that the surface to be created will come from rows of 16 points. As in Figure 2.7, you should now see the graph of the surface z = x2y2 in the perspective viewport.

img

      In the previous section we saw how to create a grid of points by grafting one list of numbers onto another, creating a list of lists (i.e. a data tree) of points. In Figure 2.8 we pass such a data tree to an Interpolate component (Curve tab, Spline panel). This component creates a NURBS curve through the points of a list that is given to its V input. When a list of lists is fed to the V input, the component will create a list of curves. The first curve is determined by the first list of points, the second curve by the second list, etc.

img

Скачать книгу