User Tools

Site Tools


hyperfun:hf_operators

HyperFun: Operators and Expressions

There are two types of expressions permissible in the language: 'functional' expression and 'logical' expression.

Functional expression

The functional expression is a conventional numerical expression built with using:

  • numerical constants,
  • external numerical parameters 'a[i]',
  • coordinate variables 'x[i]',
  • attribute variables 's[i]',
  • local variables (including elements of arrays),
  • arithmetic operators,
  • special geometric operators,
  • standard mathematical functions,
  • FRep library functions,
  • geometric objects defined before.

Arithmetic operators

There are conventional arithmetic operators, all of them always result in a floating point (double) number:

  • Addition ('+'), e.g., 5 + 0.2;

'+' is also used as unary in prefix form, e.g., +100;

  • Subtraction ('-'), e.g. 5 - 0.2;

'-' is also used as unary in prefix form, e.g., -100;

  • Multiplication ('*'), e.g., 5 * 0.2;
  • Division ('/'), e.g., 5 / 0.2;
  • Power ('^'), e.g., 5^0.2;

Special geometric operators

There are the following geometric operators relevant for F-rep that are applied to any functional expressions semantically treated as geometric objects:

  • Set-theoretic union '|' used in infix form as binary operator,

e.g., sphere1 | sphere2;

  • Set-theoretic intersection '&'used in infix form as binary operator,

e.g., sphere1 & sphere2;

  • Set-theoretic subtraction (difference) '\'used in infix form as binary operator,

e.g., sphere1 \ sphere2;

  • Set-theoretic negation '~' used in prefix form as unary operator,

e.g., ~sphere;

  • Set-theoretic Cartesian product '@' used in infix form as binary operator,

e.g., disk @ segment.

Standard mathematical functions

The following mathematical functions taking any numerical (functional) expressions and resulting in double number can be used in the functional expressions:

  • Unary functions: 'sqrt', 'exp', 'log', 'logd', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'abs', 'sinh', 'cosh', 'tanh', 'sign', 'int', 'floor', 'ceil', 'frac'.
  • Binary functions: 'max', 'min', 'atan2', 'mod'.

FRep library functions

An extensible FRep library contains functions representing geometric primitives, operations, and attributes. Each function has its own set of arguments (parameters) of predetermined types, all of which are functional expressions. The result returned through the function name is a real number. Some functions can return numerical values or arrays of numerical values through output or input/output parameters.

Examples of library functions:

Primitives:

  • Sphere: hfSphere;
  • Torus with x, y, z axes: hfTorusX, hfTorusY, hfTorusZ;
  • Blobby object: hfBlobby;
  • Metaball object: hfMetaball;
  • BГczier spline: hfBezierSplineF

Operations:

  • Scaling tranformation: hfScale3D;
  • Blending intersection: hfBlendInt;
  • Twisting around x, y, z axes: hfTwistX, hfTwistY, hfTwistZ;

Atributes:

  • Gardner Solid Noise: hfA_NoiseG;
  • Pulse: hfA_Pulse;
  • Smooth Look up table: hfA_SmoothLookUpTable;
  • Set Colors: hfA_SetColor

Geometric objects defined before

There can be references in the functional expression to geometric objects defined in the same program or saved in the special library. The form of a corresponding call stems from a syntax of object's head. The result returned through the object name is a real number. The third parameter representing attribute array can also be output parameter.

Examples:

Sphere(xx,aa);
ColorSphere(xc, ac, sc);

Logical expression

The logical expression is built of functional expressions as its arguments using relational and boolean operators. The functional expression value '0' is treated as boolean 'false'; other values are treated as 'true' in the logical expressions.

There are the following relational operators:

'<', '>', '⇐', '>=', '=', '/='.

There are two infix boolean operators ('and', 'or') and one being used in prefix form ('not'). Examples:

i < 4;

(x[1] = a[1] and (2 ⇐ xx[3] < 5.5))

In both kinds of expressions, parentheses can be used by a traditional manner and are recommended for usage to make expressions structure clearer. The rules of precedence in the expressions are also traditional. Note only that the special geometric operators have lower precedence (and accordingly are executed later) than the arithmetic operators.

hyperfun/hf_operators.txt · Last modified: 2023/12/19 03:07 by 127.0.0.1