# 4. Calculating motion¶

The `travel` module implements movement in a functional, Pythonic style.

class `turberfield.utils.travel.``Impulse`

Impulse(tBegin, tEnd, accn, pos)

An Impulse object defines a change in motion over a short interval of time.

tBegin
The start of the time interval.
tEnd
The end of the time interval.
accn
The second derivative of position over the time interval.
pos
The position at the start of the time interval.

The module defines functions for calculating motion using `Impulses`.

`turberfield.utils.travel.``trajectory`(limits=None)

A motion engine implemented as a Python generator. Like all generators you must prime it first by sending None.

You operate it by repeatedly sending it `Impulses`. The first of these establishes the initial position of the body. The second is to initialise the movement of the body. Thereafter, the generator is self-sustaining and need only be fed from its own output to keep it going.

The generator yields `Impulse` objects, from which all the instantaneous parameters of motion can be accessed or derived.

Here is an example of simulating a fall under gravity in one dimension with an initial positive velocity:

```motion = trajectory()
motion.send(None)

zero = decimal.Decimal(0)
dt = decimal.Decimal("0.5")
v0 = decimal.Decimal("65.0")
gravity = decimal.Decimal("-9.806")

for n in itertools.count():
if n == 0:
imp = motion.send(Impulse(zero, dt, gravity, zero))
elif n == 1:
imp = motion.send(Impulse(
imp.tEnd, imp.tEnd + dt, gravity,
v0 * dt + 0.5 * gravity * dt * dt))
else:
imp = motion.send(Impulse(
imp.tEnd, imp.tEnd + dt, gravity, imp.pos))
```
`turberfield.utils.travel.``time_correct_verlet`(state, t, accn, mass=1)

This low-level function implements a single step of Time-corrected Verlet position integration. See Jonathan Dummer’s article on TCV for a full description of the algorithm.

Parameters: state – a 2-tuple of `Impulses` . Element 0 is the most recent in time. t – a time quantity. accn – an acceleration quantity. a new state 2-tuple. acceleration type to support multiplication over time type.