# 3D Grid from Surface

## Introduction

**LEVEL: ADVANCED**

Expected Time: 20 min

This tutorial is focused on three useful tools in Grasshopper: UV subdivision of surfaces, box morphing and finally coloring based on surface properties. First we create a lofted surface in Rhino. The surface can be changed by control points along the curves of the loft.

## 3D Grid from Surface

First you set two curves drawn in Rhino and create a loft between them using the loft component.

- Create two curves in Rhino
- Create a curve parameter in Grasshopper
- Set the curves on the curve parameter
- Loft the curves

Subdivide the surface with UV segments using the isotrim component

- Subdivide the surface
- Connect two number sliders to the U and V input
- Trim the surface using the UV domain

The result is a series of smaller surfaces, you've pannelized the surface. These are the cells of your grid.

## BoxMorph

Once the surface is pannellized into a uv-grid, you can use it for many different transformations. One of the transformations we will demonstrate here are the Surface Box and the BoxMorph tool. A SurfaceBox creates 3D cells (with a specified height) from the 2D cells of the divided Surface. The Boxmorph places an object within those 3D cells, automatically adjusting the dimensions of your geometry. It adjusts the BoundingBox of the geometry to match the 3d boxes on the surface, and scales the geometry accordingly.

First, you need to convert the 2D cells to 3D by using the SurfaceBox command. Connect the original surface and use the **D**omain from the Divide Domain component. Specificy the **H**eight by using a Number Slider. Now you have generated the **T**arget boxes for the geometry.

- Create boxes on the grid using the surface, isotrim and a Height number slider as input
- Define the height with a Number Slider. You may have to use a negative value

Now you can create a geometry in Rhino that you want to morph over the surface. Then set it on a geometry parameter in Grasshopper.

- Design the geometry you want to morph over the surface in Rhino
- Create a geometry parameter
- Set the geometry on the parameter

Now we create a bounding box around the object. A bounding box is the smallest possible box around an object using the axes of a specific plane. After that, we morph the geometry back to the surface.

- Use the bounding box function on the geometry using the
**c**ontent input - Create a surface morph node. Plug the BoundingBox into the
**R**eference Box input on the Boxmorph tool. Finally add the**T**arget boxes from the SurfaceBox command.

*The box morph is a computationally expensive process, so it may take a while to get the result*

If you want to morph multiple objects to the surface, you can change the bounding box setting by right-clicking and selecting Union Box. You also need to group the objects for the Geometry input.

- If using multiple geometries, set bounding box to union box
- Group the geometries before the Geometry input

## Surface Analysis

The surface subdivision can also be useful in analyzing the surface. For example, by using Evaluate Surface node, we can evaluate the surface based on a uv coordinate.

- Turn off the preview of the Box Morph section
- Connect the isotrim surface to an Evaluate Surface node

UV coordinates refer to the domain of the surface. For our purposes we will reparametrize the surface, meaning we redistribute the uv domain from 0-1.

- Right-click on the
**S**urface input of the Evaluate Surface component and select Reparametrize

Using the MD Slider is visually easy to understand as the square lay-out of the slider mimics the uv-point in relation to the surface. The output of the slider is a x,y,z coordinate where the z is always 0.

- Calculate the center point of the surface with the MD Slider, do not change the values
- Connect the MD Slider output to the Point input of the Evaluate Surface node

To keep your definition compact you can decide to internalise the uv-coordinate. This means that the data is stored inside the component and is permanent until substituted with another input. Right-click the uv-input and select *internalise data*

## Color by Slope

The Evaluate Surface component returns a **P**oint, a **N**ormal and a **F**rame (plane derived from geometry). We can use this data to analyze the curvature of the surface. In order to visualize this data, we will color the subdivisions according to their slope. This could be useful when you are generating a walkable surface and the slope cannot by higher than 10% (wheelchair accessibility, for example. This can be done in many ways, but to understand the process exactly we calculate the vector of the normal compared to a vertical vector. If we multiply this by 100, we obtain the slope percentage.

To visualize the process we will first draw two SDL-lines. One SDL-line will **S**tart from the evaluated surface **P**oint following the **D**irection of the **N**ormal. The **L** doesn't matter, a Number Slider can be used in this case. The other SDL-line follows the z-**D**irection, **S**tarting from the same **P**oint, using the same Number Slider for the **L**ength.

- Create two SDL-lines from the Evaluate Surface Point output
- Define a random length with a Number Slider
- For the second SDL line, use a Z-Unit Vector as input, instead of the Normal output

Make sure they have the same orientation, if not (like in the example here) one of them needs to be inverted by using the

.- If necessary, flip the direction of one of the SDL line direction inputs

Now we extract the Endpoints of the lines to easily generate a 2-Point Vector, ensuring the correct direction of both vectors instantly.

- Find the endpoints of the SDL lines
- Create two vectors from the endpoints per line

Compute the angle between the two vectors. This equals the slope since calculating the difference between the horizontal vector and the tangent vector on the surface (90 degrees rotated normal) returns the same number.

- Compute the angle between the vectors
- Multiply the output angle with 100

For a colored representation of the different slopes we can use a color gradient option. Connect the slope percentages from the Multiplication component into the Parameter **t** of the Color Gradient. Plug the Divided **S**urface geometry into a Custom Preview component. Then enter the output of the Color Gradient into the **C**olor input of the Custom Preview.

- Display the angles of the surface using the t input of a gradient
- Set the Upper Limit input to 90
- Connect the gradient output to a Custom Preview Shader input
- Connect the isotrim surfaces to the geometry input of the Custom Preview node

There are different pre-sets if you right-click on the colored component. Moving the small dots adjusts the corresponding colors and percentages.