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
  1. SESSION 1B
  2. Ranges and expressions 1

Ranges and expressions 3

Spreadsheet programming

PreviousRanges and expressions 2NextRanges and expressions 4

Last updated 9 months ago

Generative Graphing Calculator

While the graphs produced by spreadsheet applications are great, the visualization capabilities of CAD environments are superior. We will thus try to bridge between them using drawing instructions. The objective is to achieve a type of functionality which is neither supported by the spreadsheet nor the CAD environments alone, but greater than both. We will make a generative 3D graphing calculator!

Issuing drawing instruction in CAD applications is conventionally achieved via mouse interactions, i.e. clicking the toolbar or menu buttons and selecting locations in the viewport. Alternatively, we can issue instructions via the command line interface (CLI) where the name of the command is entered, followed by actions involving inputting values using the keyboard exclusively. As an example, the demonstration above uses the “point” command. A few things to note here:

  • The CLI has an auto-complete functionality which allows you to partially type the command name and quickly confirm it or explore other commands with similar text components.

  • To execute a command you need to issue a line-termination keystroke which in this scenario is either the “enter”, “space” or “tab” keys. These are considered white-space characters separating phases of a command’s action sequence.

  • Most commands are interactive. This means they require user input to perform an operation. Those inputs are expected in a particular format, otherwise the command fails.

  • To cancel a command you may press the “escape” button at any time, while any white-space character implies “proceed to the next step”. Pressing “enter” in an empty command line, executes the last command successfully used.

  • For the “point” command, 3D coordinates of a point must be expressed as real numbers, using the dot “.” symbol for decimal separator, and comma “,” for the x, y and z coordinate delimiters.

  • Note that the coordinates shall not contain any white-space character e.g. “1.2, 3.4, 5.6” because those are reserved as instruction terminators. The correct way to issue point coordinates is “1.2,3.4,5.6” without spaces.

Text Operations

Knowing that we can issue commands purely via text, we can use the spreadsheet to translate the data produced earlier to CAD instructions. The goal is to read numerical values from the angle and cosine columns and convert them into text such that the CAD application can understand as drawing instructions: “point {angle},{cosine},0″.

In a new column named “command” we expand the keyword “point” for every row. Each row represents one point instruction. We then create a new column named “coordinates” were we expand the expression seen below. This contains a composite expression for converting numbers to text and combining multiple text fragments, also known as strings, into a single text value.

= concat( fixed( C2, 5 ), ",", fixed( D2, 5 ), ",",0 ) 

The fixed function requires a numerical value and the number of decimal digits to translate into text. For example, fixed( 3.1415, 2 ) → 3.14 i.e. keep only two decimal points. Here we convert the angle and cosine values from columns C and D to text using 5 decimal places of precision.

The concat function requires two or more text values which are joined into one text value. For example concat( “a”, “b”, “c” ) → “abc”. The process of joining multiple string values is known as concatenation, hence .

In the same fashion as the CAD command line interface, we follow conventions when composing complex expressions in spreadsheets:

  • To compose functions we use the mathematical notation of "function( list of variables )”. In math we write f(x,y,z)f(x,y,z)f(x,y,z) for functions of multiple variables and g(f(x))g(f(x))g(f(x)) for functional compositions. In computing we use more descriptive names and the term argument, or parameter, instead of variable for values passed ie. supplied for evaluation, to a function.

  • Commas “,” are used for separating arguments passed to a function. For example, cos(angle) requires one numerical argument, while fixed(number, digits) requires two. Some functions such as concat( … ) or max( … ) we used earlier can process an arbitrary number of arguments; we call those variable-argument functions.

  • To demarcate a text value, also known as a string literal, within an expression, we use the double quote " character to enclose the text value’s contents. We need two double quote characters, one for starting and one for ending a string. If you think about it, we need some special character otherwise, how could we differentiate a sequence of characters from being part of the expression or the text value?

Plotting Points

To draw the commands generated, we just need to select the “command” and the “coordinates” columns (without the column labels) and copy/paste them into the CAD system via the clipboard. The reason this works is that the spreadsheet inserts a tab character (the character mapped to the tab key) between each column and a new line character (the character mapped to the enter key) for each end of row.

To verify this claim, you may open a simple text editor in Rhino using the command ‘Notes’ and paste the contents there. From the perspective of the command line interface, all we are doing here is just typing these commands really really fast.

Note: in the gif above, cell contents are copied then pasted directly into the command line in Rhino 6. However, the copy-paste functionality differs slightly with the latest version Rhino 7. Paste the cell contents into the Notes panel first, then copy and paste the text from the Notes into the command line.

Plotting Polylines

As long as we adhere to the command line expectations i.e. proper use of white space and various text delimiters, we can automate every available command. To verify this we can replace the “coordinates” label with “polyline” and append at the end of the coordinates column the word “enter” to terminate the command.

The “polyline” command draws a polygonal curve by joining consecutive points by linear segments. Once issued, it asks the user for selecting points, on-screen or via point coordinates, until the “enter” or “space” key is pressed, or right mouse button clicked, upon which the command is completed and a polygonal line is drawn.

By now we have already surpassed the capabilities of the CAD system itself as there is no native command for arbitrary mathematical graph plotting! Sure you can draw lines, circles, ellipses and parabolas but there is no sine/cosine or even more complex formula tools. This is the first computational design tool you have developed, a set of capabilities beyond the default or intended use-case of your host environment.

Plotting Curves

The polygonal curve produced looks like the cosine curve but its is only a discrete approximation thereof. To achieve higher resolution we have two options: (a) increase the number of samples by adding more rows, or (b) request the CAD system draw a smooth curve using the points we computed. To increase the number of samples, we just need to select the last row of our table and drag-expand it as needed.

Alternatively, we may replace the “polyline” command with either the “curve” or “interpcrv” command. The “curve” command approximates the points using a polynomial of degree 3, or any order you prefer, but the curve constructed does not pass through the points. The interpolated curve command “interpcrv” does exactly that; it forces the polynomial curve to pass through the supplied points.

These curves are known as Bezier curves, when the number of points equals the curve’s degree plus one; B-Spline curves, when we fix the degree but use arbitrary numbers of points; or NURBS curves, when we want to express conic sections e.g. circles, ellipses, parabolas and hyperbolas using ratios of polynomials. Polynomials are prevalent in computer graphics because they can approximate any curve, planar or spatial, and they are fast to compute.

Practice

  • There are tons of commands that require input of point coordinates. Explore some of them to familiarize yourself with various geometric drawing methods. By clicking any toolbar or menu command you can observe in the command line the equivalent text representation and sequence of arguments required.

  • A sequence of points maps very intuitively to the concept of a curve. What about creating surfaces? Try to produces triples of points and issue triangle commands to generate mesh i.e. triangulated surface geometries. Hint: you need just more columns.

'Point' command in Rhinoceros
Concatenating strings
Pasting the formatted text in Rhino
Plotting a polyline
Plotting a cosine curve