10.014 CTD
  • Overview
  • Schedule
  • Administrative
    • Accessing Rhino remotely
    • Rhino for Mac
  • ASSIGNMENTS
    • Dates and rubrics
    • Generative design
      • Generative design
    • Parametric design
      • Parametric design
    • Simulated design
      • Simulated design
      • Simulated design
  • SESSION 1B
    • Computer Aided Design
    • Ranges and expressions 1
      • Ranges and expressions 2
      • Ranges and expressions 3
      • Ranges and expressions 4
      • Ranges and expressions 5
      • Ranges and expressions 6
  • SESSION 2A
    • Visual programming 1
      • Visual programming 2
      • Visual programming 3
      • Visual programming 4
    • Associative modelling 1
      • Associative modelling 2
      • Associative modelling 3
  • SESSION 2B
    • Logical Patterns 1
      • Logical patterns 2
      • Logical patterns 3
  • SESSION 3A
    • Spatial geometry 1
      • Spatial geometry 2
      • Spatial geometry 3
      • Spatial geometry 4
      • Spatial geometry 5
      • Spatial geometry 6
      • Spatial geometry 7
    • Curve geometry 1
      • Curve geometry 2
      • Curve geometry 3
      • Curve geometry 4
  • SESSION 3B
    • Surface geometry
    • Parametric modelling 1
      • Parametric modelling 2
      • Parametric modelling 3
      • Parametric modelling 4
  • SESSION 4A
    • Information nesting 1
      • Information nesting 2
      • Information nesting 3
    • Data landscapes 1
      • Data landscapes 2
      • Data Landscapes 3
      • Data landscapes 4
  • SESSION 4B
    • Mesh geometry 1
      • Mesh geometry 2
      • Mesh geometry 3
  • SESSION 5A
    • Space and time 1
      • Space and time 2
    • Modelling entities 1
      • Modelling entities 2
      • Modelling entities 3
  • SESSION 5B
    • Multibody dynamics 1
      • Multibody dynamics 2
    • Material elasticity 1
      • Material elasticity 2
      • Material elasticity 3
  • SESSION 6A
    • Form-finding 1
      • Form-finding 2
      • Form-finding 3
      • Form-finding 4
  • SESSION 6B
    • AI Image generation 1
      • AI Image generation 2
      • AI Image generation 3
  • APPENDIX
    • Spirograph 1
      • Spirograph 2
    • Curves
    • Swarm Intelligence 1
      • Swarm Intelligence 2
    • Hybrid programming 1
      • Hybrid programming 2
Powered by GitBook
On this page
  • Arithmetic Conditionals
  • Logic Conditionals
  1. SESSION 2B

Logical Patterns 1

Conditionals and control flow

PreviousAssociative modelling 3NextLogical patterns 2

Last updated 8 months ago

In this session we introduce conditional expressions and Boolean algebra. We use those concepts to express arithmetic and logical tests as well as to direct and control the flow of execution. We will approach the exposition of these new ideas using the visual analogies of selecting and filtering geometric objects.

Arithmetic Conditionals

In the construction below we compute the nearest neighbours of a point within a fixed proximity distance sense from a set of random points. The notion of proximity is captured by the distance between points being “less than” a constant value.

This introduces arithmetic conditional operators which include: <, ≤, ≥, >, =, ≠. Note that because some of those do not map directly to keyboard keys we use instead the following equivalent: <=, >=, “==, !=.

The double equal symbol == is often used to differentiate between equality testing and value assignment. Python and many programming languages use this notation. The “expression” component, spreadsheets and many other programming languages use the single = for equality testing. The inequality symbol is sometimes expressed using <> e.g. the “expression” component and spreadsheets.

In detail, we use the “populate 2D” component to produce a set of random points within a rectangular region and an on-screen controllable point as the selector. We compute the distances from the control point to all other points and use the “smaller than” component to produce a list of true / false values. Each value is the result of whether a random point is closer than the fixed distance defined by the slider.

The “dispatch” component splits a list in two new lists, given an equally sized list of true / false values. All items of the true category go in one list while the rest in the other. Its use is for filtering lists using a condition aka predicate.

The way the control point adjusts its support points while traversing the random point set is fascinating. To better visualize the proximity criterion we may draw a circle centred about the control node with radius equal to the proximity distance.

It is evident that points falling within the circle are selected using the conditional selection mechanism developed. In other words, we have expressed the concept of testing for point being inside a circle. For visualization purposes we also draw small spheres centred about the selected points and colour-code them.

Practice

  • Try using the greater and greater or equal than operators to select points outside the range of the control point.

  • Notice that the equal operator selects nothing, while the not equal selects all points. This is because real numbers have finite resolution. Use the “integer” component after the distance to force dropping the decimal points and convert distances to integers where equality can be computed in an exact sense.

Logic Conditionals

We next duplicate the above setup creating a second control point and its nearest neighbours. The objective here is to select the points that are common to both neighbourhoods. For this we use logic conditional operators. Their use is for allowing us to combine conditions.

Logic AND

In general, for the result of “and” to be true, both A and B must be true. Another way to consider logical “and” is as the intersection of two sets, which is what we have visually captured in the graph.

AND

False

True

False

False

False

True

False

True

Logic OR

The symmetric counterpart of “and” is the “or” operator. We use it here to select the points that fall either within the influence of the first control points or the second.

The truth table for “or” is illustrated below. For example if A is true and B is false, then the result is true. In general, for the result of “or” to be true, either A and B must be true. Another way to consider logical “or” is as the union of two sets.

OR

False

True

False

False

True

True

True

True

Logic XOR

The next Boolean operator of interest is “xor” or “exclusive or”. The goal is to select the points that belong to either control points but not both.

The truth table for “xor” is illustrated below. For example if A is true and B is false, then the result is true. In general, for the result of “xor” to be true, either A and B must be true but not both. The exclusive or operation is fascinating because it behaves sometimes like addition; when the sets don’t overlap all items are selected; but sometimes like subtraction; when the two sets overlap.

XOR

False

True

False

False

True

True

True

False

Logic NOT

The logical “not” operation inverts the a Boolean value or the result of one of the above mentioned operators. It is the last logic or Boolean operation.

The “not” operation unlike the previous is unary as opposed to binary i.e. it requires one operand instead of two. Therefore the truth table is more like a truth row.

NOT

False

True

True

False

“And” is a Boolean operator; an algebra [] using only true / false values, sometimes also denoted as 1 / 0, respectively. Given two possible values i.e. true / false, and two Boolean operands, say A and B, we can express all possible outcomes using a “truth table” seen below. For example if A is false and B is true, then A and B results to false.

This concludes the introduction to Boolean expressions and value. We used Venn diagrams [] to visually convey the core ideas of logic operators. Nevertheless, the verbosity of the graphs produced is rather frustrating.

>
>
Populate 2D component
20KB
1_NearestNeighbours.gh
31KB
2_BooleanLogic.gh
AND
OR
Xor