# Ramp Intermediate

## Introduction

LEVEL: INTERMEDIATE
Expected Time: 120 min
Possible result of this tutorial

In this tutorial you will learn how to create a ramp with landings. Landings are parts of the ramp that are flat, so that the user has a moment to rest. There are many ways of building ramps parametrically. This is just one example of creating a ramp along a planar curve. The curve will be the central axis and closely approximates the slope percentage. This definition allows for entering possible constraints defined by Building Codes such as the slope percentage and the maximum length of the ramps before placing a landing.

For this tutorial, it is recommended to have a basic understanding of Data Tree Editing. If you find the tutorial too difficult, take a look at Tutorial 9 - Ramp Easy

Principle of the design

The design will be based on several variables:

• The curve;
• The height of the ramp;
• The amount of ramps and landings;
• The length of a landing.

Furthermore, our script will calculate the maximum slope of the ramp. This value can be used to find the perfect base curve for your design.

## Base curve, division lengths

Create a curve in Rhino

In the first step of this tutorial, we create a curve in Rhino. This curve will be shattered in parts for the ramps and the landings, based on some variable number sliders.

Create a curve in Rhino and set it to a curve parameter in Grasshopper.

• Create a flat curve in Rhino

Add some Number Sliders for the design

Add three number sliders to the canvas: one for the height of the ramp, one for the amount of ramps and one for the length of the landing. As you probably can imagine, the amount of landings is one less than the amount of ramps.

• Add three Number Sliders for the height, amount of ramps and length of landings Params » Input » Number Slider

Calculate the amount of landings

Calculate the amount of landings by subtracting 1 from the amount of ramps number slider. Use a panel as or right-click on the the B input and Set one value.

• Connect the amount of landings Number Slider to the A input of a subtraction Math » Operators » Subtraction
• Set the B value to one using a panel or right-click on the B input and set one value Params » Input » Panel

Calculate the length of the curve

Let’s find out the length of the base curve by using a Curve length component.

• Calculate the curve length Curve » Analysis » Curve Length

Calculate the total landing length

We now want to know how long the ramp parts of the curve will be. First, multiply the landing length number sider with the result of the subtraction. Now you know the total length of all landings together.

• Multiply the landing length with the result of subtraction Math » Operators » Multiplication

Calculate the total ramp length

Subtract the landing length from the curve length. We now know the total length of all ramps.

• Subtract the total landing length from the curve length Math » Operators » Subtraction

If you get a negative result, your total landing length is probably higher than the curve length. Try to make the landing length lower, amount of ramps lower, or change the size of the curve in Rhino.

Divide the ram length by its amount

Now we can divide the total ramp length by the amount of ramps, to get the curve length of an individual ramp.

• Divide the total ramp length by the amount of ramps Math » Operators » Division

Repeat the data twice

Since we are planning to shatter the base curve in multiple pieces, we need to have a alternatively list of ramp lengths and landing lengths. Therefore, we repeat the individual ramp length with the amount of ramps, and respectively with the landing lengths.

• Repeat the ramp length with the amount of ramps Sets » Sequence » Repeat Data
• Repeat the landing length with the amount of landings Sets » Sequence » Repeat Data

The ramp lengths and landing lengths

We now have two lists of ramp lengths and landing lengths.

Weave the lengths into one list

By weaving the values together, we combine the lists in the correct order.

• Weave the ramp lengths and landing lengths together Sets » List » Weave

Since the pattern input is already set to [0, 1] by default, we do not need to change the pattern.

Calculate the partial sums

Unfortunately, we still do not have the data we need to shatter the curve. Use a mass addition to find the partial results of the lengths. You now have a successive list of ramp start values and landing start values.

• Connect the Weave output to a Mass Addition Math » Operators » Mass Addition

## Shatter the curve

In this step we shatter the curve in ramps and landing. These components will be divided in points, which will be used to move the base curve to the correct height.

Evaluate the curve at different lengths

First we need to find the parameters of the lengths we found on the base curve. Use an Evaluate Length component to find the Parameters.

• Use an Evaluate Length component using the original curve and the Partial Results as Lengths Curve » Analysis » Evaluate Length
• Set the Normalized input to False RMB on Normalized » Set Boolean » False

Shatter the base curve (the relay is the same as the original curve parameter)

Shatter the curve according to the parameters. We now have successive segments of ramps and landings.

• Shatter the curve at the found parameters Curve » Division » Segments

Divide the shattered segments

Divide the ramp and landing curves into points. Using a higher count input will take your script longer to calculate, but also makes the model more precise. Use a Number Slider to define the count, we will need this value again in a later stage

• Divide the shattered segments Curve » Division » Divide Curve
• Use a Number Slider to define the Count Params » Input » Number Slider

The current stage of your model

Your model should now look like the following illustration:

## Calculate the slope

Calculate the ramp slope

Since we have defined the total height of the ramp and we found the total length of the curves used by the ramp parts, we can calculate the slope.

Divide the height by the length

Divide the total height of the ramp by the total ramp length.

• Divide the total height by the total length of the ramp parts Math » Operators » Division

Multiply the result by 100

Multiply this value by 100 to get the slope in percentage.

• Connect the value to a multiplication node Math » Operators » Multiplication
• Set the B input value to 100 RMB on B input » Set one value

Visualise the slope

Connect a panel to the Result output. You now have the slope in percentage. If the slope percentage is too high according to your building regulations, change the shape of the curve, increase the amount of landings or make the max height lower.

• Connect a panel to the result Params » Input » Panel

## Find the height of the ramp steps

In the “shatter the curve” chapter we have divided the curve ramps and landings into points. Now we will find the correct height of each point. In a later stage, these points will be connected with a line, to get the base for our ramp.

Construct the height domain

Construct a domain from 0 to the max height of the ramp. We will have to divide this domain in smaller segments, to get the step differences of all points.

• Add a Construct Domain component and connect the height Number Slider to the Domain End Maths » Domain » Construct Domain

Divide the domain again

Divide the domain with the amount of ramps.

• Divide the Domain Maths » Domain » Divide Domain
• Connect the amount of ramps Number Slider to the Count input

### The step heights of the ramp parts

Calculate the height of the ramp points

In this part, we will calculate the z-coordinates of the points on the ramp segments.

Graft the result

Each segment relates to a single ramp. This segments need to be divided again in the amount of points we divided them with. First you will have to graft the output, so that each segment is calculated individually.

• Graft the Segments output RMB on segments output » Graft

Divide the domain based on the amount of division points

Divide the domains of the calculated segments with the amount of division points.

• Divide the domain of the segments with the amount of division points Maths » Domain » Divide Domain

Deconstruct the smaller domains

Deconstruct the domain to find the start and end.

• Deconstruct the Segments domains Maths » Domain » Deconstruct Domain

Last height of first ramp and first height of second ramp are not matching

At first sight, it seems that the ends of the domains are the correct height for each point on the ramps. However, as you can see, one value is missing in the beginning. If we would create a final ramp from these values, the landings would still have a slope, because the last value of the first ramp, and the first value of the second ramp do not match. Therefore we will need to add this value to the lists of points.

Extract the first item of the domain starts

Take the first item of the Start output. We now have the first start of the domain of each ramp.

• Use a List Item component to extract the first Start item Set » List » List Item

Insert the found start in the list of ends

Insert the value we found into the list of Ends.

• Connect the Domain End to the List input of an Insert Item component Set » List » Insert Item
• Connect the List item output to the Item input
• Set the Indices input to 0 with a panel or internally RMB on Indices » Set one value

Now we have a list of z-coordinates that we can use to move the points on the ramp segments to the correct height.

### The step heights of the landing parts

Calculate the height of the landing points

In the previous chapter we have found the z-coordinates of all points of the ramps. Now we need to find the z-coordinates of all points of the landings.

Deconstruct the overall ramp domains

Deconstruct the domains of the overall ramp segments. The End output should give you an amount of values, equal to the amount of ramps.

• Deconstruct the domain of the grafted segments output Maths » Domain » Deconstruct Domain

Cull the last items of the lists

Since we do not have a landing after the highest ramp, we do not need the first value. Flatten the End output and cull the last index using the value -1.

• Flatten the End output of the Deconstruct Domain component RMB on End output » Flatten
• Use a Cull Index component to Cull the End output Set » Sequence » Cull Index
• Set the Indices input to -1 RMB on Indices input » Set one value

Graft the output

Finally graft the output. We now have the heights of all points of the landings.

• Graft the List output RMB on List output » Graft

Finalise this part with two Number Parameters

To make the script more clear, connect a number parameter to both List outputs and rename them to "Ramp heights" and "Landing heights".

• Connect two Number Parameters to the List outputs Params » Geometry » Number
• Rename the Number Parameters

## Find the correct height

Now comes the tricky part of this tutorial. We will need to split the points on the base curve into the ramp and landing part. After that, we move them to the correct height based on the values we found in the last tutorial. Finally we merge the moved points together again.

Simplify the output

Simplify the Points output of the Division points.

• Simplify the division points output RMB on Points output » Simplify

Simplifying reduces the branches of a data tree. For example {0;0;0} becomes {0}. This can help you to make two different lists interact with each other in the correct order. Generally speaking, we try to avoid simplifying, because we lose information about the origin of data.

Get the tree statistics f the Points output

Let’s extract al the tree paths that belong to the ramps and landings. An easy method is to use the Tree statistics component.

• Find the branches of paths of the Points output Set » Tree » Tree Statistics

Dispatch the Paths in ramps and landings

Now we will dispatch the Paths output. Since the Dispatch pattern is already True-False, we can leave the input empty. By connecting a panel to the List A and List B output, you can see that List A contains all the ramp branches and List B contains all the landing branches.

• Dispatch the paths output Set » List » Dispatch

Extract the points that belong to the ramps or landings

Use two Tree Branch components to extract the points that belong to the found branches.

• Extract the points with two Tree Branch components Set » Tree » Tree Branch

The current stage of the model

In your viewport you can see that by selecting one of the Tree Branch nodes, only the points of a ramp/landing type are selected.

### Move the ramp points

Match the data trees

When you connect a panel to the points of the ramps we found and a panel to the heights of the points of the previous chapter, you will see that the numbers of the branches do not match. You can solve this by using a Match Tree component and use the points as guide.

• Add a Match Tree component to the canvas and connect the ramp Tree Branch output to the Guide input Set » Tree » Match Tree
• Connect the ramp heights to the Tree input

Convert values to a Z Unit vector

Create a Z-unit vector from the heights.

• Connect a Z-unit vector heights from the Match Tree component Vector » Vector » Unit Z

Move the points to their location

Move the ramp points to the correct height.

• Move the ramp points with a move component Transform » Euclidian » Move

The points of the ramps placed at the correct height

In your viewport you will see that all the ramp points are moved to the correct location.

### Move the landing points

Cull the first and last item of the list

Moving the landing points works exactly the same as the ramp points. However, since the first and last point of the ramp are already implemented by the ramps, we will need to cull them. You will need to simplify the output.

• Connect the landing Tree Branch output to a Cull Index List input Sets » Sequence » Cull Index
• Set the Indices input to 0 and -1 RMB on Indices input » Set multiple values » Type 0 enter -1
• Simplify the output RMB on List output » Simplify

Match the data tree

Match the height values data tree using the landing points data tree as guide.

• Add a Match Tree component to the canvas and connect the landing Cull Index output to the Guide input Set » Tree » Match Tree
• Connect the landing heights to the Tree input

Convert values to a Z Unit vector

Convert the height values to a z-unit vector.

• Connect a Z-unit vector heights from the Match Tree component Vector » Vector » Unit Z

Move the points to their location

Move the points using the z-unit vector.

• Move the landing points with a move component Transform » Euclidian » Move

The points of the landings placed at the correct height

In your viewport you will see that all landing points have been moved to the correct height.

Merge the ramp and landing points

Finally merge the moved ramp points and moved landing points into one data tree.

• Merge the moved ramp and landing points Sets » Tree » Merge

## Create the ramp

A polyline from the flattened point list

In this chapter we convert the points to a real ramp. First create a polyline from the points.

• Flatten the Result output
• Create a polyline from the merged points Curve » Spline » Polyline

Calculate the point parameters on the curve

We need to find the curvature at each point on the polyline. Therefore, we will need its parameter. Use a Curve Closest Point component to find the parameter of the points.

• Connect the Result output to a Point input of a Curve Closest Point component Curve » Analysis » Curve Closest Point
• Connect the Polyline output to the Curve input

Evaluate the curve tangents

Evaluate the curve at the found parameters to get the Points and Tangents.

• Evaluate the Curve at the found Parameters Curve » Analysis » Evaluate Curve

The tangent vectors visualised

In the right image, you can see the Tangent vectors of each point.

Calculate the perpendicular vector with the cross product

We now need the vector perpendicular to this Tangent vector. Use the cross product to find the perpendicular vector. You will need to connect a Z-unit vector to the Vector B input.

• Calculate the Cross product of the Tangent output Vector » Vector » Cross Product
• Connect a Z-Unit Vector to the Vector B input Vector » Vector » Unit Z

The cross product is a mathematical calculation to find the perpendicular vector to vector A and B.

The perpendicular vectors visualised

In the right image, you can see the perpendicular vectors to the Tangent vectors in the XY plane.

Create two SDL lines in different directions

From the cross product vector, create two SDL lines from the original points. For one of the two SDL-lines, use a negative component, to alternate the direction.

• Create two SDL lines from the Point output using the Cross Product Vector as direction Curve » Primitive » Line SDL
• Connect a Negative node to one of the Length inputs Negative » Operators » Negative
• Connect a Number Slider to the Length input and the Negative input Params » Input » Number Slider

The current stage of the model

Your viewport should now look similar to the following image. By changing the length of the SDL-lines, you can change the width of the ramp.

Join the SDL lines

Join the SDL-lines in positive and negative direction.

• Join the SDL lines Curve » Util » Join Curves

Loft the SDL lines into a surface

Loft the joined curves.

• Loft the joined curves Surface » Freefrom

The current stage of the model

You now have the base surface of your ramp.

## Thickness of the ramp

Extrude the surface to give it a thickness

You may want to give a thickness to the ramp. Extrude the surface in the negative z-direction to give your ramp a thickness.

• Extrude the surface Surface » Freeform » Extrude
• Connect a Negative component to the Direction input Math » Operators » Negative
• Create a Z-Unit vector to the Negative input Vector » Vector » Unit Z
• Define the thickness with a Number Slider Params » Input » Number Slider

The final model