# Reference: computeParticleTrajectory

```computeParticleTrajectory(expr, var, r, v, t0, t1, δt) computes the curve in n-dimensional space that a particle will trace out if the force field is expr, a string representing a real-valued expression in var, a string representing a valid identifier. r ∈ R^n is the particle's initial position, and v ∈ R^n is its initial velocity. t0 and t1 is the initial and final time, respectively. δt is the temporal resolution, typically 0.001 for a high-res simulation of a few seconds. To plot the trajectory, simply use drawSet/drawLines or drawSet3/drawLines3, if n = 2 or n = 3, respectively.

computeParticleTrajectory(expr, var, r, v, t0, t1, δt, BB), where BB ∈ R^2n, will impose a box which the particle will not be able to move outside of; instead, if it hits the inside of the box, it will bounce back. The two first components of BB are the lowest and highest bounds of the first dimension, the third and fourth components are the lowest and highest bounds of the second dimension, and so on. Thus ❨-10, 10, -10, 10❩ is a symmetric 20×20 2D box, and ❨-10, 10, -10, 10, -10, 10❩ is a symmetric 20×20×20 3D box, and so on.

computeParticleTrajectory(expr, var, r, v, t0, t1, δt, BB, f) uses the box BB and the factor f of speed preservation at each bounce. If f = 0, all kinetic energy is lost at every (in practice, the first) bounce, and if f = 1 it will continue to bounce indefinitely.

Example: Bouncing ball in gravity in a 2D box
trajectory ≔ computeParticleTrajectory("❨0, -1❩", "r", ❨-10, 10❩, ❨1, 0❩, 0, 100, 0.01, ❨-10, 10, -10, 10❩, 0.8)
drawSet("trajectory", "colour:red")
```