Skip to main content

Arithmetic

Arithmetic

Overview

Used to perform common mathematical operations on two or more Parameter Nodes, useful for creating complex parameterized objects using Parameter nodes wired to multiple inputs.

Usage

  1. Attach 2 or more parameter nodes to the Arithmetic node's input slots
  2. Select the equation type from the drop-down list
  3. Expose the target node property by right-clicking, select export and pick the value you wish to parameterize.
  4. Wire the Arithmetic output to this new slot.

Interface

Several operations are available:

Add. returns the sum of an addition operation

Subtract. returns the difference of a subtract operation

Multiply. returns the product of a multiplication operation

Divide. returns the quotient of a division operation

Maximum. returns the largest of the input values

Minimum. returns the smallest of the input values

Expression. Create equations using common functions and variables.

Expressions Editor

To add an expression, select Operation>Expression and press Edit Expression to open the Expression Editor

To create complex parametric relationships, the Expressions Editor uses a straightforward mathematical syntax comprising operators +, -, *, /, etc constants (pi, e, etc.), RailClone's built-in variables, numerical inputs, and functions (including standard, trigonometric, vector, rounding, and conditional functions that take one or more arguments and return a result). To find out which built-in functions, operators and constants are available, a full list is included in the Expressions Pane on the left hand side of the window. To see an explanation for each function, single click on it and a description and example syntax will display in the Expressions Help Pane at the bottom of the interface.

Interface

Expressions pane. found on the left, lists all usable variables and functions. Double-click a list item to add it to the edit window or single click to display help.

Edit Window. used to create and edit the expression, to see the effects of an expression press Update. To construct a variable you can either type it in manually or add variables and functions by double-clicking them from the expressions list.

Expressions Help. this window provides information about the currently selected variable or function.

caution

RailClone 3 included a new expressions' engine. Be aware that there are a couple of key changes to remember.

  • The new version uses a double == for conditional tests

  • The way you write numbers is now important, for example in RailClone 3:

    1 = an integer

    1.0 = a float

    This means that in RailClone 3 the expressions:

    return 1/2;

    Will result in 0, because both values are integers.

    To return a float value you would use:

    Return 1.0/2.0;
  • To send a value to the arithmetic node's output you must add a return command, for example:

    return degToRad(90);
note

Using expressions to control a segment's transform properties

When using expressions to control a segment's transform properties it is necessary to use a Transform operator. The current workflow will not allow you to connect an expression directly to a segment node. RailClone will detect an incompatible connection and display a warning.

Expressions Syntax

Expressions use a straightforward mathematical syntax comprising operators +, -, *, /, etc. mathematical Functions that take one or more arguments and return a result, RC's built-in variables (which we have called Attributes for clarity), user declarable Variables, and customisable Inputs. There are many built-in functions, and attributes already available and these are all documented in the Command List on the left hand side of the Expressions Editor. To see an explanation for each entry, single click on it and a description and example syntax will display in the Help pane at the bottom of the interface. General syntax rules are describe below.

Return

To send a value to the node's output you use the return command. For example: return degToRad(90);

Only one return command can be used in an expression.

Functions

Functions provide pre-built commands that can be used to perform common mathematical expressions. To use a function you use the name followed by any required arguments enclosed in parentheses. For example, to convert 90 degrees to radians you use the degToRad function as follows:

degToRad(90)

Where a function requires multiple arguments, these should be separated using commas. For example to generate a random integer between 0 and 350 you would use the randomInt function as shown below:

randomInt(0,359)

Functions can also be nested by including them as arguments, for example:

degToRad(randomInt(0,359))

You can find a full list of supported functions, including information about the arguments they require here .

Attributes

Attributes are RailClone's pre-defined variables. Dot syntax is used to access an attribute's values. This means that when using an attribute, the statement must always start with a reference to some object, followed by a full stop (. or dot) and then the name of the property you wish to access. Each dot represents a move from more general access to the object to more specific levels of parameter detail. For example XSplineCoords refers to a vector value. Continuing down the hierarchy, XSplineCoords.Z refers only to the Z axis.

Be aware that attributes in the Command List cannot be edited using expressions.

Markers

Introduced in RailClone 4, the RC Spline Modifier allows you to apply Markers to a spline which contains an ID channel and 9 Data channels. To access these in expressions you would use the following.

To access the ID channel for markers on the X or Y spline, use

XMarkerID
YMarkerID

To access the data channel assigned by markers on the X or Y spline, use

XMarkerData[#]
YMarkerData[#]

where # can be 0 to 9 to access the 9 data channels available in each marker.

Variables

In addition to built-in attributes, variables can be created and edited in the expression script. They are declared as one of three types, either real for float values or scene units, int for whole numbers, or vectors. They are not case-sensitive but there are a few restrictions on naming:

  • Cannot be the same as an existing attribute, function, variable or parameter.
  • Must only consist of alphanumeric symbols and underscores (_).
  • Cannot start with a number.
  • Cannot contain spaces.
  • Variables are local to the RailClone Object, this means you can use the same variable name in different objects without problems.

Below are examples that illustrate how to create each of the three types of variable as well as illustrating some acceptable ways to construct variable names based on the rules outlined above.

int objectCount = 4;
real object_rotate_z = 10.5;
vector objectPosition1 = [10,10,0]

You can also create variables without assigning a value as follows:

int objectCount;
real object_rotate_z;
vector objectPosition1;

Once a variable has been declared, you assign a new value using equals (=). For example

objectCount = 5;
object_rotate_z = 22.5;
objectPosition1 =[20,20,20];

Variable types cannot be changed once created and though you can assign an integer value to a real variable, you can't assign a real value to an integer. In this case you will need to use the rounding functions ceil(), floor(), trunc(), or round() to convert the real value to an integer, for example:

int integer;
real float = 12.3;
integer = floor(float);
print integer;

If you evaluate this code then 12 will display in the output window. This is because the floor function rounds 12.3 to the lowest adjacent whole number which can then be assigned to the integer variable with no errors.

Inputs

Inputs are a special type of variable whose values are assigned in tan attached Numeric or Constant node, this enables a user to control effects without needing to understand the code. An input is named after the order in which is attached to the Node, Input1 in the first slot, Input2 in the second and so on.

Operators

The operators described below can be used to manipulate data.

Mathematical Operators

The following arithmetic operators are supported:

OperatorExample UseDescription
+p+qAddition
-p-qSubtraction
--pReturns the negative of a variable's value
*p*qMultiplication
/p/qDivision
^p^qPower

Vector Operators

When using vectors the following operators apply:

OperatorSyntaxExample UseDescription
xV.xXSplineCoords.xReturns the 1st component of a vector
yV.yXSplineCoords.yReturns the 2nd component of a vector
zV.xXSplineCoords.zReturns the 3rd component of a vector
+V+WXSplineCoords + YSplineCoordsAddition
-V-WXSplineCoords - YSplineCoordsSubtraction
*V*WXSplineCoords * YSplineCoordsDot Product
*V*pXSplineCoords * 5Scalar Multiplication
/V/pXSplineCoords / 2Scalar Division
^V^WXSplineCoords ^ YSplineCoordsCross Product

Comparative Operators

RailClone includes an If function to allow you to create conditional rules. This function uses the following syntax:


if(p,q,r)

Where p is a logic test which returns q if it returns true or r if it returns false.

To create the conditional tests for an IF function you use following operators:

OperatorExample UseDescription
==p==qReturn true if p is equal to.
<p<qReturn true if p is less than.
>p>qReturn true if p is greater than.
>=p>=qReturn true if p is greater than or equal no q
<=p>=qReturn true if p is less than or equal to q
|p|qReturn true if p or are true
&p&qReturns true if p and are true

Instruction separation

Each command must be terminated by a semicolon ( ; ).

Comments

Comments are added by starting the line with a # symbol. Anything after the # on the same line will be ignored:

# This is a comment

# This is another comment

Note that comment lines do not need to be terminated with a semicolon, though it won't affect anything if you do so.

Debugging

To help debug effects we have provided a print command that displays the results of an expression or contents of a variable, parameter or attribute to the Output window. For example, the expression below will print 5.0 to the output window.

real exampleVariable = 5.0;
print exampleVariable;

Because you are often creating scripts designed to manipulate the values on thousands of scattered items it is not possible, or desirable, to see the results for every instance. Therefore, the print command displays values for only the first scattered object

Case Sensitivity

Functions, variables, properties and attributes are not case sensitive.