GenerativeComponents Help

Predefined Functions in GenerativeComponents

A set of commonly used functions are available within GenerativeComponents. These functions include common mathematical expressions such as Sin and Cos and data management-related functions operating on lists of data. There are also a number of functions that generate lists as output for use in any node input that accepts lists as input (as indicated by the [ ] or [ ][ ] sign behind the variable type, or the (repl.) if lists are only an option).

In general, functions are a small set of expressions or a small program that is defined within a named function block. To use this capability, you call the function by using its name in combination with the number of inputs it requires. The combination of inputs a function requires to execute is also referred to as the function signature. A commonly used function for mathematical expressions is Sin. If we want to get the value of the Sin function at, for instance, 30 degrees we can use the predefined function Sin in GenerativeComponents. If we want to assign the result to the YTranslation of a point, the expression would look like this:

YTranslation = Sin(30)

Though, the standard library and script functions that used to quickly apply to FunctionCall nodes, through Functions dialog, the list of available functions and their brief documentation is available under the Functions tab of Expression Builder. The Functions tab and other tabbed resources can be found when clicking the button from the Script Editors taskbar.

In the Expression Builder dialog, click the Functions tab to access the function documentation. Here it says that Sin interprets the input value as a number in degrees as opposed to radians (degrees range from 0 to 360 for one full revolution and radians from 0 to 2*PI).

Selecting the function in the list and clicking Insert brings the correct expression in the script editor. To use the function you have to replace the input placeholder, in this case the angle, with an actual value or a variable that is defined in the current session. In this example, it would be 30.

Clicking Apply in the script editor places it in the selected variable field.

After clicking <Enter>, the function is executed with the value given and YTranslation is assigned the return value of the function, in this case 0.5. The current value of the variable field is always shown in brackets.

Another commonly used GenerativeComponents-specific function is the Series() function

The documentation defines the Series() function as a function that creates a list of values ranging from a start value to a final value by a specified increment. For instance, the range could be 1 as the start value, 5 as the final value, and 1 as the increment. The function call would look as follows:

Series(1, 5, 1)

The return value would be a list of values corresponding to the inputs given by you in this case:

{1, 2, 3, 4, 5}

This list output is the equivalent to a list you could have typed by hand, as shown in the list documentation in the previous section. The advantage of using a function to create the list is that it is much faster and more flexible for simple series of data by equal increments as above. Changing the input values to the Series function in turn regenerates the list values without manual retyping. Thinking of typing a list of {1, 2, 3, 99,100} for instance, should make the advantage of using a generative function clear. A function does not have to be that simple but can perform any function you define. The list output, once generated, is treated the same way as any other list of values. For instance if it is used for the XTranslation value of a Point.ByCartesianCoordinates, it would replicate the point along the X axis. In combining the series function with the Sin function from above, you can generate a series of points that graph the Sin function along the x-axis.

Here, the XTranslation and YTranslation properties of a point node use the Series() function to achieve different effects:

XTranslation = Series(0, 10, 1);
YTranslation = Sin(Series(0,360,36));

The Series() function is a versatile function, and can further define how to access this list of points when combined with the MembersAt() function. To use alternating points from this list as the endpoint of a line, place the following code into the end point input property of a new line node:

EndPoint = MembersAt(point01,Series(1,9,2))

Another example extending the previous one applies the point offset in the Y-direction on a plane arrayed along a BSplineCurve in space. This way the resulting sequence of points embodies both the Sine curve of the function results and the curvature of the BSplineCurve. This is also referred to as a composite curve.



Rather than using points, one can also apply the results of the Sin function to the radius of a circle and loft the circles in sequence to get an undulating tube-like surface. It is important to adjust the results from the Sin function to prevent self-intersection of the lofted surface.

A Sin function output ranges from maximal +1 to minimal -1 over a full cycle. In order for the radii of the circle not to become negative or zero, we need to offset the result from Sin by at least the minimum value plus any minimal radius we want in the circle series. In this case the equation was written as

Radius = (Sin(plane01.T*720)+1.3)*1.5)

where 720 stands for 2*360, therefore two sine periods. It is multiplied by the T value of the CoordinateSystem that runs along the BSplineCurve. The offset mentioned above is set to 1.3. In order to scale up the radius overall the entire expression is multiplied by 1.5. The result is shown below.



This shows how the combination of simple functions and simple mathematical expressions can create complex geometry constructs that still can be parametrically edited interactively.