Overview
Forces in Particle Simulator are defined as mathematical functions that can depend on time (t) and position (x, y, z). The system evaluates these formulas in real-time to compute the acceleration and trajectory of each particle.
Force as a Function: F(t, x, y, z)
Every force component can be written as a mathematical expression using:t- Elapsed time in secondsx,y,z- Current position of the particle- Any mathematical function from the available functions library
Vector Force Format
Forces are always specified as three components:Time-Dependent Forces
Forces that change over time use thet variable:
Position-Dependent Forces
Forces that depend on the particle’s current position:Spring/Restoring Forces
Inverse-Square Gravity
Central Force
- Magnitude:
1/r² - Direction: Always toward origin
- Note: The
r³denominator comes from normalizing the direction vector
Combined Forces
You can combine time and position dependencies:Force Evaluation Modes
The simulator supports two calculation modes:- Dynamic Mode (Forces)
- Kinematic Mode
Dynamic Mode: F = ma
Forces are evaluated and Newton’s second law is applied:- Realistic physics simulations
- When mass matters
- Multiple interacting forces
Implementation Details
The force evaluation uses function caching for performance:Key Features:
Function Caching
Formulas are compiled once and cached to avoid repeated parsing
Math Injection
All JavaScript
Math functions are automatically availablePower Operators
Both
^ and ** work for exponentiationError Handling
Invalid formulas return 0 instead of crashing
Common Patterns
Oscillators
Central Forces
Rotating Forces
Pro Tip: Start with simple formulas and add complexity gradually. Use the trajectory examples as a starting point for your own creations.