Name
function — manipulate data with mathematical expression
Syntax
function function string
Description
The function command can be used to manipulate data values in Polydata (i.e. points and lines) and Structured Points (i.e. grids). The specified function will be performed on each point in the dataset.
The function string can be a combination of several sub functions for each component you want to manipulate. Each sub function should be separated with a semi colon character ;.
Each sub function is a combination of a target variable, an equal sign, and a mathematical expression.
for example:
function "x = x + 100 ; y = x + y"
The variables in the function are always from the original dataset. In the example above, the x, and y variable in the second sub function will not be affected by result of the the first sub function.
The mathematical expression may contain these operators: +, -, *, /, abs, exp, ceil, floor, ln, log10, sqrt, sin, sinh, cos, cosh, tan, tanh, asin, acos, atan, min, max, sign.
A conditional expression is also supported. An "if" test may be a part of the mathematical expression. The syntax should be if(condition, result if true, result if false).
For example:
function "z = if(z<0, 5, z)"
will replace all values with z less than zero with 5.
Polydata target variables:
x = the x value of the current point
y = the y value of the current point
z = the z value of the current point
s = the scalar value of the current point
Structured Points target variables:
z = the value of the current point.
dx = point spacing in x direction.
dy = point spacing in y direction
origo_x = the X coordinate of the grid origo which is the lower left corner of the Structured Points dataset
origo_y = the Y coordinate of the grid origo which is the lower left corner of the Structured Points dataset
Common Function variables:
The following variables are available to all datasets:
x = the x value of the current point
y = the y value of the current point
z = the z value of the current point
Polydata Function variables:
In addition to the common variables, the following variables are available for polydata
x_ = the x value of the next point
y_ = the y value of the next point
z_ = the z value of the next point
_x = the x value of the previous point
_y = the y value of the previous point
_z = the z value of the previous point
s_ = the scalar value of the previous point
s = the scalar value of the current point
_s = the scalar value of the next point
Structured Points Function variables:
In addition to the common variables, the following variables are available for structured Points
xmin = the x value of the leftmost column of the Structured Points dataset
xmax = the x value of the rightmost column of the Structured Points dataset
ymin = the y value of the uppermost row of the Structured Points dataset
ymax = the y value of the bottommost row of the Structured Points dataset
dx = point spacing in x direction
dy = point spacing in y direction
rows = number of rows
cols = number of columns
origo_x = xmin = the x coordinate of the grid origo which is the lower left corner of the Structured Points dataset
origo_y = ymin = the Y coordinate of the grid origo which is the lower left corner of the Structured Points dataset
Examples:
Example 1: Switch Polydata x and y values
function "x=y ; y=x"
Example 2: Multiply z by 1000 (Structured Points or Poly Data)
function "z=z*1000"
Example 3: Translate polydata 100 in x direction
function "x=x+100"
Example 4: Translate structured points dataset100 in x direction
function "origo_x=origo_x+100"
Example 5: Use formula on a structured points dataset
This example may be run on a grid. It will replace the grid values with a wave pattern. Try the following command
function "z=dy*sin(sqrt(x*x +y*y)/(dx*10))"
See also
swi - Switch coordinates , add - Add to dataset