Math expressions in OpenVCAD#
OpenVCAD compiles math expression strings at runtime with the ExprTk library. The same syntax is used wherever you pass an expression string—for example FloatAttribute, Vec4Attribute, and VolumeFractionsAttribute in the attribute-modeling workflow, and other nodes that accept spatial formulas.
Note
Syntax matches most graphing-calculator conventions, with many advanced features available. See the ExprTk documentation for the full language specification.
Coordinate systems#
The following variables may be used in any math expression. You can combine multiple coordinate systems in a single expression.
Name |
Form |
Variable names |
|---|---|---|
Cartesian |
f(x, y, z) |
|
Cylindrical |
f(rho, phic, z) |
|
Spherical |
f(r, theta, phis) |
|
Signed distance |
f(d) |
|
Note
phic is the azimuthal angle in cylindrical coordinates; phis is the polar angle in spherical coordinates. Both use radians.
Note
d is the signed distance to the object surface: zero on the surface, negative inside, positive outside. This supports conformal (surface-following) gradients.
Cylindrical definitions#
rho= sqrt(x^2 + y^2) — distance from the Z axisphic= atan2(y, x) — azimuth in the XY plane (radians, about -π to +π)z— same as Cartesianz
Spherical definitions#
r= sqrt(x^2 + y^2 + z^2) — distance from the origintheta= atan2(y, x) — azimuth in the XY plane (radians)phis= acos(z / r) — polar angle from +Z (radians, 0 to π)
Arithmetic and assignment operators#
Operator |
Definition |
|---|---|
|
Addition ( |
|
Subtraction ( |
|
Multiplication ( |
|
Division ( |
|
Modulus ( |
|
Exponentiation ( |
|
Assignment ( |
|
Compound assignment |
Equalities and inequalities#
Operator |
Definition |
|---|---|
|
Equal ( |
|
Not equal |
|
Inequality comparisons |
Boolean operations#
Operator |
Definition |
|---|---|
|
Boolean literals |
|
Logical operators |
|
Extended logical ops |
General-purpose functions#
Function |
Definition |
|---|---|
|
Absolute value |
|
Mean of arguments |
|
Rounding |
|
Square root (x ≥ 0) |
|
Log and exponential |
|
Power |
|
Extrema |
|
Clamp x to [lo, hi] |
Trigonometry#
Arguments are in radians unless you convert with deg2rad / rad2deg.
Function |
Definition |
|---|---|
|
Basic trig |
|
Inverses |
|
Unit conversion |
Constants#
Name |
Role |
|---|---|
|
Built-in |
|
Built-in |
You can also use numeric literals (e.g. 3.14159).
Tips#
Grouping uses parentheses:
(x + y) * z.Mixing coordinates is valid, e.g.
rho * sin(phis) + z.Colors and fractions often need clamp:
clamp(0, expr, 1)for channels that must stay in [0, 1].