# Grasshopper 2D Grid

## Introduction

**LEVEL: BEGINNER**

There are several ways of making a 2D grid in Grasshopper. Here, we will demonstrate 3 different options, but there are many other possibilities.

- Grid Option 1: Matrix X,Y,Z-Point
- Grid Option 2: Grid Component
- Grid Option 3: UV Surface Divide

## Matrix X,Y,Z Point

Option 1 generates a grid by using a X,Y,Z point matrix. This definition is easiest to understand, as it does not produce a data-structure. It copies a singular point into two directions and generates a grid by cross-referencing the moved points, using a series component. The variables of the definition will be:

- Location of inital X,Y,Z point
- Number of points in X direction
- Number of points in Y direction
- Distance between points in X direction
- Distance between points in Y direction

To make the grid we start to define the origin of the grid. We use the tool. The default plane coordinates are (0.0,0.0,0.0) are fine in the case of this tutorial, but if you want to locate the X,Y,Z point elsewhere you can define the coordinates by inserting numbers for the X,Y,Z inputs.

The second tool we need is the component. This tool will move a copy of a geometry or multiple geometries to a certain direction.

The direction is defined by a vector. To make a two dimensional grid we need to define the movement both in the X and Y direction. To do this we create an X and Y vector. and To combine the two vectors so you create a vector with a X and Y input you have to use the addition option

You can now see two points on your rhino screen, one is the original point and the other is the moved point. But we need multiple points to form the grids. To do this we need a series of movement vectors.

The series tool in grasshopper can create a series of values with a determined start number, step size and number of values. You can find the series tool in:
Create three sliders and connect them to the three variables of the series tool. Use the panel option to show the list of values you just created.

Now we connect the elements from both previous steps. We need to connect the series tool to the X and Y vector as shown in the image at the right. If you want a square grid, you can use the same series for both X and Y direction. If you want a rectangular grid, you need to generate a separate series for each direction.

Probably you will now see a series of points generated on your screen that are aligned diagonally in a straight line. This is still not what we wanted. We wanted the points to be distributed as a matrix. We wanted the points to be distributed as a matrix. To do this you have to add a 'Cross-reference' component in between. Now you will have X*Y matrix of points.

The points will now be distributed as a matrix as shown in the image at the right. In contrast to the following examples, this grid does not have a data structure. If you connect the grid of points to a panel, you will see that there is a single list of points, not organized by rows or columns and there are no cells. This makes it difficult to transform the grid. This grid is best used for placing objects at the vertices, like columns for example.

## Grid Component

Option 2 uses Grasshopper's built in 'Grid' components.

These tools quickly produce a grid once placed on the canvas, using default settings that can be manipulated. In addition to making a rectangular grid, this option also allows for other base geometries, like a regular hexagon, equilateral triangle or circle. It is important to understand that in addition to points, these components generate cells. In all cases the variables are:

- Location of plane (starting point of grid)
- Number of cells in X direction (radial direction in case of radial grid)
- Number of cells in Y direction (polar direction in case of radial grid)
- Size of the cells.

Only in the case of the rectangular grid you have an additional variable:

- Size of the cells in opposite direction.

For example, let's look at the rectangular grid. We have a grid of 10x5 cells, with a step-size of 4 units wide and 6 units long. The component automatically generates points and cells.

If we look at the data structure using a we see that it groups the cells according to the rows and columns of the grid. If we want to check whether these are grouped by row or by column we can use . Selecting the 1st branch (0), we see that the data structure is organized by columns.

If you want to switch the rows and columns of the matrix you can use . If we now do the same, you'll see that the data structure is organized by row. You can do the same for the other grid-components.

The points derived from the grid components differ. In the case of the square, rectangular and radial grid, the points derived from the component are located at the vertices of the grid. In the hexagonal and triangular grid, the points derived from the component correspond to the centroid of the cell.

If you want to obtain the vertices, it is best to use component. Be aware that now you have duplicate points, as it places a point at the corners of each cell.

## UV Surface Divide

Option 3 allows for most freedom, because it is able to create a grid not only on regular shapes, but also on freeform geometry, both in 2D and in 3D (see Grasshopper 3D Grid from Surface) This method is based on subdivison (defining U and V values), of an input rather than building the grid from scratch with the size and number of cells. This is usefull when you already know the final dimensions of the grid in advance and prioritize this over the size of the cell. Whereas in the other two options, the final size of the grid is a 'result' of a multiplication of the number of cells and cell sizes.

In the first example of Option 3, the variables are:

- Location of plane (starting point of grid)
- Total Width of the Grid (X-direction)
- Total Length of the Grid (Y-direction)
- Number of subdivisions (cells) in U direction
- Number of subdivisions (cells) in V direction

To demonstrate we apply the UV Surface Divide onto a parametric rectangular surface. First define the Width (X) and Length (Y) of a by using Number Sliders. Convert the rectangular polyline into a planar surface by using the component. This is the input we will use for the Surface division.

To obtain the points from a surface, using U and V divisions we can directly use command. This returns the points, not the cells. If you want to retrieve the cells, you will use the command instead.

In both cases you need to define the U and V values using Number Sliders. In the first case, there is a direct input for both U and V value on the component. The Isotrim (SubSurface) requires you to divide a UV Domain based on the input Surface. Connect the divided domain and the input surface to the Isotrim (SubSurface) component. The result is a series of smaller surfaces, you've pannelized the surface. These are the cells of your grid.

**Network Surface**

Since this definition is based on an input surface, it can be applied onto many freeform surfaces. To demonstrate this flexibility we have defined a

A Network Surface is defined by a series of curves in two directions, preferably (not necessarily) perpendicular to each other.

In this case we are using two curves along the Y-axis and two curves along the x-axis to form the surface. Changing the control points of the curves causes the Network Surface to respond. If we plug the Network Surface instead of the Rectangular Boundary Surface, the grid, the cells and the points adjust correspondingly.