# Trajectories of Hamiltonian systems

Depicting trajectories of physical objects
Available with Zymplectic v.0.1.1

#### Example applications

Trajectories are a practical tool for describing the motion of any particle. Symplectic integrators additionally ensures preservation of the Hamiltonian, which allows for qualitatively accurate long-term depiction of the trajectories. A long-time trajectory simulation of the Swinging Atwood's machine is shown below:

While not being an ideal method for depicting chaos, trajectories may reveal chaotic behavior and irregular orbits found in some system under certain initial conditions. For instance consider two pendulum-carts with springs, differing only by 0.1 radiens of the pendulum angle initial condition:

These systems are along with others simulated in the video:

#### Implementation

Zymplectic supports default object tracking (enabled with "track" in GUI or "Z.track = 1" in initialization)

If trajectory coordinates need to be calculated, for instance converting angle-action variables to Cartesian coordinates, it is necessary to utilize auxiliar functions such as Z.OnIter to achieve this.
//Incomplete code. Does not run a simulation
void OnIterFunction() { //called on every iteration
double CalcX = cos(obj_q[0][0]);
double CalcY = sin(obj_q[0][1]);
draw.track_add(CalcX,CalcY); //pixel value increment at these coordinates. The shown color is based on the values of all pixels
//draw.track_set(CalcX,CalcY,10); //assign a specific value to a coordinate useful for a limited color palette
}

void OnDrawFunction() { //called each time the GLUT-window updates (depends on framerate)
//optional function to draw primitives such as points, lines, vertices...
//note that draw.track_add should generally not be called from OnDraw because it is called less frequent than OnIter
}

void main() {
Z.H(EnergyFunction,DerivativeFunction,0,0);
Z.OnDraw = OnDrawFunction;
Z.OnIter = OnIterFunction;
Z.track = 1; //enabled here or in the GUI. required also for non-standard objects
}