Skip to main content

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!
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.

Force Formulas

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

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.

Variations

{
  "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.

Force Formulas

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

-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.

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.

Force Formulas

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

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.

Real Implementation (20 Particles)

The default scene creates a circular formation of 20 particles:
{
  "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.

Force Formulas

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

Goal: Create force F = -k/r² pointing toward originStep 1: Calculate distance
r = sqrt(x^2 + y^2 + z^2)
Step 2: Unit vector toward origin
r̂ = -[x, y, z] / r = -[x/r, y/r, z/r]
Step 3: Force magnitude
F_magnitude = k / r²
Step 4: Combine
F = 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)

Variations for Different Orbits

{
  "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
number
required
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
forces
Force[]
required
Array of force objects (dynamic mode only)Each force has:
  • id: Unique identifier
  • vec: Three-element array of formula strings [Fx, Fy, Fz]
isMassless
boolean
If true, switches to kinematic mode where formulas define position directly
fx, fy, fz
string
Position functions of time (kinematic mode only)
color
string
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

Build docs developers (and LLMs) love