Overview
Particle Simulator injects the entire JavaScriptMath library into your formulas, giving you access to a comprehensive set of mathematical functions and constants.
All functions from JavaScript’s
Math object are automatically available - no prefixes or imports needed!Variables
| Variable | Type | Description |
|---|---|---|
t | number | Elapsed time in seconds since simulation start |
x | number | Current X position of the particle |
y | number | Current Y position of the particle |
z | number | Current Z position of the particle |
Trigonometric Functions
Standard trigonometric functions (angles in radians):Available Functions:
sin(x)- Sine of x (x in radians)cos(x)- Cosine of xtan(x)- Tangent of xasin(x)- Arcsine (inverse sine)acos(x)- Arccosine (inverse cosine)atan(x)- Arctangent (inverse tangent)atan2(y, x)- Two-argument arctangent (returns angle in correct quadrant)
Example Use Cases:
Oscillations
Circular Paths
Angular Force
Lissajous Patterns
Hyperbolic Functions
Hyperbolic trigonometric functions (useful for damping and bounded growth):Available Functions:
sinh(x)- Hyperbolic sine:(e^x - e^(-x)) / 2cosh(x)- Hyperbolic cosine:(e^x + e^(-x)) / 2tanh(x)- Hyperbolic tangent:sinh(x) / cosh(x)asinh(x)- Inverse hyperbolic sineacosh(x)- Inverse hyperbolic cosineatanh(x)- Inverse hyperbolic tangent
Why Use Hyperbolic Functions?
- Smooth Saturation
- Damping
- Growth & Decay
tanh(x) provides smooth bounded output:- Limiting forces without discontinuities
- Soft transitions
- Sigmoid activation
Exponential and Logarithmic
Exponential growth/decay and logarithmic functions:Available Functions:
exp(x)- Euler’s number raised to x:e^xlog(x)- Natural logarithm (base e)log10(x)- Base-10 logarithmlog2(x)- Base-2 logarithmsqrt(x)- Square root:√xcbrt(x)- Cube root:∛xpow(x, y)- x raised to power y (can also usex^yorx**y)
Operators
Arithmetic Operators
| Operator | Description | Example |
|---|---|---|
+ | Addition | x + 5 |
- | Subtraction | y - 10 |
* | Multiplication | x * 2.5 |
/ | Division | x / (y + 1) |
^ or ** | Exponentiation | x^2 or x**2 |
Power Operator: Both
^ and ** work for exponentiation. The system automatically converts ^ to **.Comparison & Logic
While primarily for events, these can create conditional behaviors:| Operator | Description | Example |
|---|---|---|
> | Greater than | Used in event conditions |
< | Less than | Used in event conditions |
>= | Greater or equal | Used in event conditions |
<= | Less or equal | Used in event conditions |
== | Equal to | Used in event conditions |
!= | Not equal | Used in event conditions |
Utility Functions
Practical functions for common operations:Available Functions:
abs(x)- Absolute value:|x|sign(x)- Sign of x: -1, 0, or 1floor(x)- Round down to nearest integerceil(x)- Round up to nearest integerround(x)- Round to nearest integertrunc(x)- Remove fractional partmin(a, b, ...)- Smallest valuemax(a, b, ...)- Largest valuerandom()- Random value in [0, 1)
Practical Examples:
Pulsing Force
One-Way Force
Stepwise Force
Random Noise
Mathematical Constants
Predefined constants from JavaScript Math:| Constant | Value | Description |
|---|---|---|
PI | 3.141592653589793 | Ratio of circle circumference to diameter (π) |
E | 2.718281828459045 | Base of natural logarithms (e) |
SQRT2 | 1.4142135623730951 | Square root of 2 (√2) |
SQRT1_2 | 0.7071067811865476 | Square root of 1/2 (1/√2) |
LN2 | 0.6931471805599453 | Natural logarithm of 2 |
LN10 | 2.302585092994046 | Natural logarithm of 10 |
LOG2E | 1.4426950408889634 | Base-2 logarithm of e |
LOG10E | 0.4342944819032518 | Base-10 logarithm of e |
Advanced Techniques
Composition
Combine functions for complex behaviors:Avoiding Singularities
Performance Optimization
Function Categories Summary
Trigonometric
sin, cos, tan, asin, acos, atan, atan2Hyperbolic
sinh, cosh, tanh, asinh, acosh, atanhExponential
exp, log, log10, log2, powPower & Root
sqrt, cbrt, ^, **Rounding
floor, ceil, round, truncUtility
abs, sign, min, max, randomNext Steps
Now that you know all available functions, explore:Trajectory Examples
See these functions in action with real trajectory patterns
Force Equations
Learn how to structure your force formulas