3.4. Math and Logic Functions
Math and Logic Functions in Grasshopper
Operators
Operators in Grasshopper can be found under Math > Operators:
Math operators
Math operators are used to perform arithmetic operations on numbers.
Addition
(Math > Operators > Addition)
Subtract
(Math > Operators > Subtraction)
Multiplication
(Math > Operators > Multiplication)
Division
(Math > Operators > Division)
Modulus
(Math > Operators > Modulus)
Divides two numbers and returns only the remainder.
The division of 9 by 3 returns 0 as a reminder.
The division of 9 by 4 returns 1 as a reminder, since we can contain two times 4 and still have 1 left.
Power
(Math > Operators > Power)
Constants
In Grasshopper we can find certain build-in components with the values of Pi, Natural logarithm (e) and Golden Ratio:
Comparison operators
Comparison operators are used to compare values. They return True or False based on whether a comparison is true or false.
Booleans
Boleans variable can only store two values: TRUE or FALSE, 1 or 0.
Boolean Toggle allows you to quickly change between single True or False values:
Grasshopper has components to test conditions and output Boolean values:
Check if a number is contained inside a certain Domain:
(Maths > Domains > Includes)
Logical operators
Logical operators mostly work with Booleans.
Gate NOT performs boolean negations.
(Maths > Operators > Gate NOT)
AND and OR components takes two arguments as input. Logical operators are used to evaluate something.
(Maths > Operators > Gate AND)
A | B | Result |
---|---|---|
True | True | True |
True | False | False |
False | True | False |
False | False | False |
(Maths > Operators > Gate OR)
A | B | Result |
---|---|---|
True | True | True |
True | False | True |
False | True | True |
False | False | False |
Points
A point is a list of one or more values that are called coordinates.
Depending on the number of coordinates we can know in which dimension of space resides.
Points, Vectors and Planes are the base in order to build geometry in Grasshopper. There are different ways how you can create a point.
(Primitive > Geometry > Point)
(Vector > Point > Construct Point)
Vectors
A Vector is a geometric quantity describing Direction and Magnitude. They are abstract.
Points and vectors are difficult to distinguish, they are both a list of values.
A vector always starts at (0,0,0) and ends at the specific coordinate.
We can easily manipulate them by using mathematical operators:
Series
(See Lists)
We can create series of numbers in Grasshopper in different ways:
(Sets > Sequence > Series)
(Sets > Sequence > Range)
Math Functions
The series of values can be easily manipulated with mathematical operators:
At the same time we can combine them with trigonometrical operations, as for example Sine, Cosine… etc:
(Maths > Trig > Sine)
(Maths > Polynomials > Square)
(Maths > Trig > Sine & Cosine)
Grasshopper allows you to use “Ready to use” components or custom made ones to create your functions:
(Math > Script > Expression)
And by using different parametric functions we will be able to reproduce geometries such as circles, spirals… etc.