Overview
This page showcases real trajectory patterns from Particle Simulator, extracted directly from the codebase. Each example includes the complete particle configuration: initial position, velocity, forces, and mass.
All examples below are taken from the default scene (default.json) and the project README. You can copy these configurations directly into your simulator!
Featured Trajectory Patterns
These examples are specifically highlighted in the README as “Pro Formula Examples”:
Lissajous Resonance Anisotropic harmonic oscillator with Z modulation
Hyperbolic Damping Damped oscillation with bounded nonlinear forcing
Pulsing Vortex Time-varying rotational force creating expanding/contracting spirals
Inverse-Square Gravity Central force following 1/r² law (orbital mechanics)
1. Lissajous Resonance
An anisotropic harmonic oscillator with sinusoidal Z-axis modulation creates beautiful 3D Lissajous curves.
Fx : - x
Fy : - 2.25 * y
Fz : sin ( t * 0.5 ) * 5
Complete Configuration
{
"mass" : 5 ,
"p0_fis" : [ 20 , 0 , 0 ],
"v0_fis" : [ 0 , 8 , 0 ],
"forces" : [
{
"id" : 1 ,
"vec" : [
"-x" ,
"-2.25 * y" ,
"sin(t * 0.5) * 5"
]
}
]
}
Physics Explanation
X-Y Behavior
Z Behavior
Visual Result
Independent oscillators with different frequencies:
Fx = -x: Simple harmonic oscillator, frequency ω₁ = √(k/m) = √(1/5)
Fy = -2.25 * y: Faster oscillator, frequency ω₂ = √(2.25/5) = 1.5 × ω₁
Frequency ratio: ω₂/ω₁ = 1.5 = 3/2This 3:2 resonance creates a Lissajous figure in the XY plane - the path traces out a figure-eight or pretzel shape that repeats every 4 cycles. Starting from (20, 0) with velocity (0, 8) provides the initial conditions for a bounded oscillation. External oscillating force:
Fz = sin(t * 0.5) * 5: Sinusoidal driving force
Slow frequency (0.5 rad/s) compared to XY oscillations
Amplitude of 5 N
This creates vertical oscillations that are:
Phase-independent from XY motion
Driven (not natural oscillation)
Low frequency, causing slow vertical bobbing
The combination creates a 3D trajectory where the 2D Lissajous pattern is lifted and lowered periodically. What you see:
XY plane: Figure-eight or pretzel-shaped path
Z motion: Slow vertical oscillation (period ≈ 12.6 seconds)
3D effect: The 2D Lissajous pattern “breathes” up and down
Pattern characteristics:
Closed curves (periodic)
Complex but predictable
Symmetrical
Never escapes to infinity
The 3:2 frequency ratio ensures the pattern repeats exactly, creating stable, beautiful trajectories.
Variations
2:3 Resonance
Without Z Modulation
Faster Z Oscillation
{
"forces" : [{
"vec" : [
"-x" ,
"-4 * y" , // 2:1 frequency ratio
"sin(t * 0.5) * 5"
]
}]
}
2. Hyperbolic Damping
Damped oscillation with a nonlinear hyperbolic tangent driving force that keeps the motion bounded.
Fz : - z * 0.5 + 20 * tanh ( sin ( t ))
Complete Configuration
{
"mass" : 5 ,
"p0_fis" : [ 20 , 0 , 0 ],
"v0_fis" : [ 0 , 8 , 0 ],
"forces" : [
{
"id" : 1 ,
"vec" : [
"0" ,
"0" ,
"-z * 0.5 + 20 * tanh(sin(t))"
]
}
]
}
Physics Explanation
Damping Term
Driving Term
Combined Effect
-z * 0.5 : Linear damping force
Opposes motion (negative sign)
Proportional to displacement
Damping coefficient: b = 0.5 N/m
This creates a restoring force that pulls the particle back toward z = 0, with the strength increasing linearly with distance. Damping ratio: ζ = b/(2√(km)) = 0.5/(2√(0×5)) = ∞ (undamped case, since there’s no natural spring)Without the external force, this would cause the particle to drift toward the equilibrium at z = 0. 20 * tanh(sin(t)) : Nonlinear periodic forcing
sin(t): Oscillates between -1 and +1
tanh(...): Hyperbolic tangent bounds output to (-1, 1)
Amplitude: 20 N
Why tanh? The hyperbolic tangent provides:
Soft saturation: Smoothly limits force magnitude
Stability: Prevents runaway acceleration
Nonlinearity: Creates interesting dynamics
Result: A smooth, bounded oscillating force that “pushes” the particle up and down but never exceeds ±20 N. Total force: Fz = -z * 0.5 + 20 * tanh(sin(t))The interplay between damping and driving creates:
Equilibrium shifting: The external force shifts the equilibrium point
Bounded motion: Damping prevents escape, driving prevents settling
Phase lag: Response lags behind the driving force
Nonlinear resonance: tanh modifies the response curve
Visual result:
Smooth vertical oscillations
Slightly asymmetric due to nonlinearity
Stable amplitude (doesn’t grow over time)
Complex but natural-looking motion
Extended Example from Default Scene
The default scene uses this pattern with XY vortex forces:
{
"mass" : 5 ,
"p0_fis" : [ 20 , 0 , 0 ],
"v0_fis" : [ 0 , 8 , 0 ],
"forces" : [{
"vec" : [
"-x * abs(cos(t*0.2))" ,
"-y * abs(cos(t*0.2))" ,
"-z * 0.5 + 20 * tanh(sin(t + 0.31))"
]
}]
}
Note the phase offset t + 0.31 for each particle in the circular arrangement!
3. Pulsing Vortex
A rotational force field whose strength oscillates with time, creating spiraling patterns that expand and contract.
Fx : - x * abs ( cos ( t * 0.2 ))
Fy : - y * abs ( cos ( t * 0.2 ))
Complete Configuration
{
"mass" : 5 ,
"p0_fis" : [ 20 , 0 , 0 ],
"v0_fis" : [ 0 , 8 , 0 ],
"forces" : [
{
"id" : 1 ,
"vec" : [
"-x * abs(cos(t*0.2))" ,
"-y * abs(cos(t*0.2))" ,
"0"
]
}
]
}
Physics Explanation
Radial Force
Time Modulation
Trajectory Pattern
Base force structure: -x and -yThese create a radial inward force pointing toward the origin:
Magnitude proportional to distance: F ∝ r
Direction: Always toward (0, 0, 0)
2D force (no Z component)
This is a 2D linear spring: F = -kr with k = 1 N/m. If the coefficient were constant, this would create simple circular or elliptical orbits in the XY plane. Modulating factor: abs(cos(t*0.2))
cos(t*0.2): Slow oscillation (period = 10π ≈ 31.4 seconds)
abs(...): Always positive, range [0, 1]
Effect on spring constant:
k(t) = abs(cos(t*0.2)) oscillates between 0 and 1
k = 0: No force (particle drifts in straight line)
k = 1: Full force (tight orbit)
k = 0.5: Half force (looser orbit)
This creates a breathing effect where the “spring” gets stronger and weaker. What happens:
Full force (k=1): Particle spirals inward
Decreasing force: Spiral loosens, particle moves outward
Zero force (k=0): Particle moves in straight line (tangent to circle)
Increasing force: Particle gets pulled back, begins new spiral
Repeat
Visual result:
Flower-like spiral pattern
Expands and contracts periodically
Never escapes (force always inward on average)
Creates beautiful looping trajectories
The initial velocity (0, 8) provides tangential motion that creates the spiral, while the pulsing force creates the expansion/contraction.
Real Implementation (20 Particles)
The default scene creates a circular formation of 20 particles:
Particle 1
Particle 6 (opposite side)
Particle 11 (opposite side)
{
"id" : 9001 ,
"color" : "#ff00ff" ,
"mass" : 5 ,
"p0_fis" : [ 20 , 0 , 0 ],
"v0_fis" : [ 0 , 8 , 0 ],
"forces" : [{
"vec" : [
"-x * abs(cos(t*0.2))" ,
"-y * abs(cos(t*0.2))" ,
"-z * 0.5 + 20 * tanh(sin(t + 0.31))"
]
}]
}
Pattern: 20 particles arranged in a circle (radius 20), each:
Position: Evenly spaced angles (18° apart)
Velocity: Tangent to circle (magnitude 8 m/s)
Z phase: Offset by 0.314 radians (≈ π/10) per particle
Color: Gradient from magenta → blue → cyan
This creates a synchronized pulsing vortex with vertical waves!
4. Inverse-Square Gravity
A central force following Newton’s law of universal gravitation (or Coulomb’s law), creating orbital mechanics.
Fx : - x / ( sqrt ( x ^ 2 + y ^ 2 + z ^ 2 ) ^ 3 )
Fy : - y / ( sqrt ( x ^ 2 + y ^ 2 + z ^ 2 ) ^ 3 )
Fz : - z / ( sqrt ( x ^ 2 + y ^ 2 + z ^ 2 ) ^ 3 )
Simplified Notation
For a single axis:
- x / ( sqrt ( x ^ 2 + y ^ 2 + z ^ 2 ) ^ 3 )
Or using power operator:
- x / ( sqrt ( x ^ 2 + y ^ 2 + z ^ 2 ) ** 3 )
Complete Configuration
{
"mass" : 5 ,
"p0_fis" : [ 20 , 0 , 0 ],
"v0_fis" : [ 0 , 8 , 0 ],
"forces" : [
{
"id" : 1 ,
"vec" : [
"-x / (sqrt(x^2 + y^2 + z^2)^3)" ,
"-y / (sqrt(x^2 + y^2 + z^2)^3)" ,
"-z / (sqrt(x^2 + y^2 + z^2)^3)"
]
}
]
}
Physics Explanation
The Math
Why r³?
Orbital Mechanics
Goal: Create force F = -k/r² pointing toward originStep 1: Calculate distancer = sqrt ( x ^ 2 + y ^ 2 + z ^ 2 )
Step 2: Unit vector toward originr ̂ = - [ x , y , z ] / r = - [ x / r , y / r , z / r ]
Step 3: Force magnitudeStep 4: CombineF = F_magnitude × r ̂ = ( k / r ²) × ( - [ x / r , y / r , z / r ])
Simplify: Fx = - k × x / r ³
= - x / ( sqrt ( x ^ 2 + y ^ 2 + z ^ 2 ) ^ 3 )
(Here k=1 for simplicity) Common question: “Why divide by r³ instead of r²?”Answer: We need both:
Direction normalization: Divide by r (to get unit vector)
Inverse-square law: Divide by r²
Total: r × r² = r³Breaking it down: // Direction (unit vector)
direction = - x / sqrt ( x ^ 2 + y ^ 2 + z ^ 2 )
// Magnitude (1/r²)
magnitude = 1 / ( sqrt ( x ^ 2 + y ^ 2 + z ^ 2 ) ^ 2 )
// Combined
force = magnitude × direction
= 1 / r ² × ( - x / r )
= - x / r ³
This force creates Kepler orbits! With the given initial conditions:
Position: (20, 0, 0) - distance r₀ = 20
Velocity: (0, 8, 0) - perpendicular to position
Mass: 5 kg
Orbit properties:
Orbital velocity at r=20:
v_circular = √(k/r) = √(1/20) ≈ 0.224 m/s
Given v = 8 m/s >> v_circular
Result: Hyperbolic escape trajectory!
Energy:
Kinetic: KE = ½mv² = ½(5)(64) = 160 J
Potential: PE = -k/r = -1/20 = -0.05 J
Total: E = 160 - 0.05 > 0
Positive energy = escape orbit
What you’ll see:
Particle approaches origin
Curves around it (periapsis)
Flies off to infinity
Never returns (open orbit)
For a closed circular orbit at r=20:
Variations for Different Orbits
Circular Orbit
Elliptical Orbit
Stronger Gravity
With Singularity Protection
{
"p0_fis" : [ 20 , 0 , 0 ],
"v0_fis" : [ 0 , 0.224 , 0 ], // v = √(k/r)
"forces" : [{
"vec" : [
"-x / (sqrt(x^2 + y^2 + z^2)^3)" ,
"-y / (sqrt(x^2 + y^2 + z^2)^3)" ,
"-z / (sqrt(x^2 + y^2 + z^2)^3)"
]
}]
}
Additional Trajectory Types
Helix (Kinematic Mode)
Using kinematic mode for precise parametric control:
{
"isMassless" : true ,
"p0_fis" : [ 0 , 0 , 0 ],
"fx" : "10 * cos(t)" ,
"fy" : "10 * sin(t)" ,
"fz" : "t * 2"
}
Creates: A helix rising at constant rate with radius 10.
Damped Oscillator
{
"mass" : 1 ,
"p0_fis" : [ 10 , 0 , 0 ],
"v0_fis" : [ 0 , 0 , 0 ],
"forces" : [{
"vec" : [ "-x * 2" , "0" , "0" ]
}]
}
Creates: Simple harmonic motion along X axis.
Chaotic Attractor
{
"mass" : 5 ,
"p0_fis" : [ 1 , 1 , 1 ],
"v0_fis" : [ 0 , 0 , 0 ],
"forces" : [{
"vec" : [
"-x + y" ,
"-y + z" ,
"-z + x"
]
}]
}
Creates: Coupled oscillators with complex, quasi-chaotic behavior.
Configuration Parameters Reference
Mass of the particle in kilograms (only used in dynamic mode)
p0_fis
[number, number, number]
required
Initial position vector [x, y, z] in meters
v0_fis
[number, number, number]
required
Initial velocity vector [vx, vy, vz] in m/s
Array of force objects (dynamic mode only) Each force has:
id: Unique identifier
vec: Three-element array of formula strings [Fx, Fy, Fz]
If true, switches to kinematic mode where formulas define position directly
Position functions of time (kinematic mode only)
Hex color code for the particle (e.g., "#ff00ff")
Tips for Creating Trajectories
Start Simple Begin with basic forces like -x, -y, -z and add complexity incrementally
Match Initial Conditions Position and velocity should be compatible with your force for desired orbit
Use Symmetry Symmetric forces create predictable, repeating patterns
Combine Patterns Mix time-dependent and position-dependent forces for rich dynamics
Watch for Instability Avoid forces that grow unbounded (e.g., x^2 without negative sign)
Test Incremental Change one parameter at a time to understand its effect
Avoid singularities! Add small epsilon values to denominators:// Bad: Can divide by zero
sqrt ( x ^ 2 + y ^ 2 + z ^ 2 )
// Good: Protected
sqrt ( x ^ 2 + y ^ 2 + z ^ 2 + 0.1 )
Next Steps
Force Equations Deep dive into force formula syntax
Available Functions Complete function reference
Quick Start Create your first simulation