Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
{alias:function}

h2. Name

*function* — manipulate data with mathematical expression

h2. Syntax
{panel:|borderStyle=solid|borderWidth=1|bgColor=#ffffaa}

*function* _function string_

{panel}

h2. Description

The Function command can be used to manipulate data values in Polydata and Structured Points. 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:

{noformat:|borderWidth=1|bgColor=#eeeeee}
function "x = x + 100 ; y = x + y"
{noformat}
The variables in the fuction 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:

{noformat:|borderWidth=1|bgColor=#eeeeee}
function "z = if(z<0, 5, z)"
{noformat}
will replace all values with z less than zero with 5.

h4.


h4. 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

h4. 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 = &nbsp;the X coordinate of the grid origo which is the lower left corner of the Structured Points dataset
origo_y = &nbsp;the Y coordinate of the grid origo which is the lower left corner of the&nbsp;Structured Points dataset

{color:#000000}{*}Common Function variables:*{color}


{color:#333333}The following variables are available to all datasets:{color}

x = the x value of the current point
y = the y value of the current point
z = the z value of the current point

h4. 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

h4. 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&nbsp;Structured Points dataset
xmax = the x value of the rightmost column of the&nbsp;Structured Points dataset
ymin = the y value of the uppermost row of the&nbsp;Structured Points dataset
ymax = the y value of the bottommost row of the&nbsp;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&nbsp;Structured Points dataset
origo_y = ymin = the Y coordinate of the grid origo which is the lower left corner of the&nbsp;Structured Points dataset

h2. Examples:

h4. Example 1: Switch Polydata x and y values&nbsp;


{noformat:|borderWidth=1|bgColor=#eeeeee}
function "x=y ; y=x"
{noformat}

h4. Example 2: Multiply z by 1000 (Structured Points or Poly Data)


{noformat:|borderWidth=1|bgColor=#eeeeee}
function "z=z*1000"
{noformat}

h4. Example 3: Translate polydata 100 in x direction


{noformat:|borderWidth=1|bgColor=#eeeeee}
function "x=x+100"
{noformat}

h4. Example 4: Translate structured points dataset100 in x direction


{noformat:|borderWidth=1|bgColor=#eeeeee}
function "origo_x=origo_x+100"
{noformat}

h4. 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

{noformat:|borderWidth=1|bgColor=#eeeeee}
function "z=dy*sin(sqrt(x*x +y*y)/(dx*10))"
{noformat}

h2. See also

[swi - Switch coordinates] , [add - add valueAdd to dataset]

{pagebreak}