Once I get to introduce arrays and loops to work with points, I’m used to introduce nested arrays and loops to follow the constructive geometry logic of going to the next level: **curves**. And since is pretty obvious by itself, I go one more step to **surfaces**. The key concept to understand here is that a curve needs an array of points —which are arrays of numbers, so is an array of arrays— and a surface needs an array of curves —an array of arrays of arrays!

To set this level of nested arrays with loops, you have to nest the loop as well. The simplest example to understand this in RhinoScript is presented here. I’m using $x$ and $y$ as iteration variables, so the relation with the point arrays and the geometrical output is more clear. For the $z$ component, I’m using the pseudo random function (`Rnd`

) in order to get a differentiated output without adding more lines of code.

A student once told me that it looks like a *tsunami* and remembering it I did this second image, with 21 iterations in $x$ and 51 in $y$ dimension. Notice that `Rnd`

has no specified seed, so it’ll generate a different surface every time it runs. The script:

Call IncrementalRndSrf() Sub IncrementalRndSrf() Dim Pts(20) Dim Crvs(50) Dim x, y For y = 0 To 50 For x = 0 To 20 Pts(x) = Array(x, y, Rnd*x) Next Crvs(y) = Rhino.AddCurve(Pts) Next Call Rhino.AddLoftSrf(Crvs) End Sub

## No comments:

## Post a Comment