S206E057 -- Lecture 13, 5/22/2016, Grasshopper – Math and Logic...

S206E057 – Fall 2016
S206E057 -- Lecture 13, 5/22/2016, Grasshopper – Math and Logic Rules
Copyright ©2016, Chiu-Shui Chan. All Rights Reserved.
Interface of Math and Logic Functions
1. Basic mathematic operations:
For example, choose the mathematic operators of +, -, *, / from the Maths tag > Operators panel, define inputs of A
and B variables through number sliders, calculations of these operations will be displayed in a panel.
A+B
A-B
A*B
A/B
Reminder of A/B
AB
Other operators could also be found under Maths > Util panel, for instance, the Natural logarithm or Pi, or even type in
the expression or the name of the Pi or e (natural logarithm) in the panel area. See examples below.
Page 1 (5/1/2016)
Arch534 – Spring 2015
Similarity threshold between A & B is within
10%.
A = B, true or false?
A > B or A ≥ B, true or false?
A< B or A ≤ B, true or false?
2. Mathematic equation input – executing a formula
GH provides some math equations to let users set up their own math equations for geometric calculation and form generation.
For example, it is easy to use an equation to draw a shape in Rhino. This example given in this tutorial handout is based on
the Lynda.com Grasshopper tutorial.
1. Choose Maths tag > Script panel > Evaluate, or double click the
Canvas, type eval to activate the “Evaluation” component;
2. Zoom in to be able to remove the Y index parameter away from the
component.
3. F is an expression, and x & Y are two variables.
Remove Y variable
4. We will use a simple formula Y = X2 to draw a parabolic curve.
In this Eval component, F is the formula, X is the input and the result of the calculation will pass over to r as the
calculation results.
5. There are three ways of setting up the formula, method A is to right click F, type in X*X to the Expression Editor >
click Commit Changes. The Eval component will do the calculation and pass the results in real number format to r
for output.
Page 2 (5/1/2016)
S206E057 – Fall 2016
6. Method B is to click Expression Editor to define a complicate
formula in the window.
Formula could be typed in here and click
Commit changes to complete the input.
7. Method C is to provide a visual clue by choosing Params tag > Input > Panel to display the formula and provide the
expression on the sub-window and provide output to F in Eval. So, create two panels and type in the formula on one
Panel and link it to the F input.
8. For constructing a parabolic, the X input must be a series of numbers. We could use Range component for doing it.
Range divides a domain into a number of equal
sections. It takes two inputs. The first one is Domain,
which gives us the high and the low value between
which to operate. The second is a Number of steps,
which is a number of divisions to make over the domain.
In this example, we have 10 steps, so the function will
generate 10 numbers (steps) evenly spaced between 0
and 10. We could also figure out the space between
those numbers, which is also called the step size, by
dividing the length of the domain by the number of
steps. In this example, 10 over 10 equals 1. So, it
shows in the panel that the values are spaced one unit
apart from each other.
Page 3 (5/1/2016)
Arch534 – Spring 2015
9. The domain could be well-defined by “Construct Domain”.
Delete the old Domain input and replace it with Construct Domain, which will set up a low and high domain, link the
Construct Domain output to the D input in Range. Set up two sliders of -20<-5<0, wire it to A, and 0<5<20 slider for B
in Construct Domain component. Now, wire the Range output to Eval X input.
10. Now show the results in Rhino points. Choose Vector Tag < Point < Construct Point.
While applying the Y=X2 to generate the parabola, the X values are the list of numbers coming
straight out of the range component. So link the R in Range to X in Pt component. Then, in
Rhino, evenly spaced points are shown on the X axis. The Y values are from the Eval
calculated output list. Thus, link the r from Eval to Y in Pt. Then a parabolic shape is
generated in Rhino.
11. Finally draw the curve
Go to the Curve Tag > Spline > Nurbs Curve
Page 4 (5/1/2016)
S206E057 – Fall 2016
The point output of the Construct Point component will serve as the Vertices component of the Nurbs Curve.
So, after the link, the parabola is created in Rhino.
2. Logic expression:
Logic expression relates to the if-then-else, conditional cases, etc… which also be done by Eval component. Here is an
example.
Exercise: For example, if X>Y, then return True value. Here are the steps:
1. Use the component of Panel to set up the formula X>Y.
2. Apply two sliders to provide user input.
3. Use “Evaluation” component. The panel output is the expression input in “Eval”, X and Y are inputs. Return
of the evaluation values, true or false, to another panel for review. Here are the results.
If X>30, then draw a circle, otherwise draw a polygon in Rhino. The radius of these shapes would depend upon the amount of
input value. Here is the algorithm applied in GH.
1. In this example, a dispatch component is used to decide whether it is true or false. The dispatch will sort a list based
on true false pattern output from a conditional statement.
Page 5 (5/1/2016)
Arch534 – Spring 2015
2. Dispatch will receive an input from Eval as the dispatch pattern. If it is true then do A, otherwise do B. A is to draw a
circle, whereas B is to draw a polygon. I also put a panel on both A and B output to get a better idea on (or to
visualize) what the output values are.
What happens if x equals to 30, and how to implement the coding?
The Dispatch function has more ability to sort out the input data into two parts. See the following example:
Input:
List = [A, B, C, D}
Dispatch pattern = [True, False]
Resulting output:
List A = [A, C]
List B = [B, D]
Page 6 (5/1/2016)
S206E057 – Fall 2016
Example 3:
How to separate a list of numbers from -10 to +25 into three different lists?
1. X < -5
2. -5 < X < 15
3. X > 15
Method A: Apply “Series” to create a series of numbers, use three evaluations and three dispatch to provide three lists.
Method B: Same ideas but applying different Boolean operations.
More will be explained in later lectures and exercises. Yet, the most important point is the design thinking and intension that
could be implemented digitally and executed in Grasshopper.
Page 7 (5/1/2016)