# How to calculate the time an object needs to travel along a parameterized curve?

Imagine you have an object that travels along a trajectory parameterized by time in the form:

$$\vec{p} = \begin{pmatrix} x_0 \\ y_0 \end{pmatrix} + \begin{pmatrix} v_x \\ v_y \end{pmatrix} t + \frac{1}{2} \begin{pmatrix} a_x \\ a_y \end{pmatrix} t^2 + \frac{1}{6} \begin{pmatrix} j_x \\ j_y \end{pmatrix} t^3,$$

where $$\vec{v}$$, $$\vec{a}$$, and $$\vec{j}$$ are the velocity, acceleration and jerk, respectively.

Now given a start time $$t_0$$, I would like to know how long it takes ($$\Delta t$$) the object to travel a certain distance $$d$$ along the trajectory. I assume I would need to solve the following integral (or at least something along those lines, pun intended) for $$\Delta t$$, but I'm not really sure how to do that:

$$d = \int_{t_0}^{\Delta t} |\vec{p}|\text{d}t$$

I would like to do this in Python and I would think that this is a very basic problem, however I haven't found the right tools to do this yet. Numpy for example offers the roots function, and I guess this might help me here, but I haven't figured out how yet.

Also, except for this similar-ish post, I didn't manage to find much on this, probably because I haven't figured out the correct key terms yet.

• The correct formula for the distance is $d=\int_{t_0}^{\Delta t}|\frac{d}{dt}\vec{p}|\,dt$ (add up infinitesimal distances to see this). To invert this in python I would calculate a grid of $d$-values given a grid of $\Delta t$-values and then interpolate reversely: stick the time grid into the slot for the $y$ and the $d$ grid into the slot for $x$ and interpolate to get $\Delta t$ given a $d$. Commented Mar 7, 2022 at 14:45
• Hi @KurtG., thanks! I'm not really sure I understand your aproach on how to implement this in Python however. Can you elaborate a bit more? Feel free to post an answer.
– mapf
Commented Mar 8, 2022 at 12:30

The correct formula for the distance is $$d=\int_{t_0}^{\Delta t}\Big|\frac{d}{dt}\vec p\Big|\,dt$$ (add up infinitesimal distances to see this). To invert this in python I would calculate a grid of $$d$$-values given a grid of $$\Delta t$$-values and then interpolate reversely: stick the time grid into the slot for the $$y$$ and the $$d$$- grid into the slot for $$x$$ and interpolate to get $$\Delta t$$ given an arbitrary $$d$$.

from numpy import linspace, sqrt
from scipy import interpolate

def dp( t, v, a, j ):
return( v + a*t + j*t**2/2 )

def dp_length( t, v, a, j ):
return( sqrt( (dp( t, v, a, j )[0])**2 + (dp( t, v, a, j )[1])**2 ) )

def distance( t, v, a, j ):
return( quad( dp_length, 0, t, args = ( v, a, j ) )[0] )

v = array([[1],[1]])
a = array([[1],[1]])
j = array([[1],[1]])

T = linspace( 0, 10, 10 )
D = linspace( 0, 0, 10 )

for i in range(len(T)):
t = T[i]
D[i] = distance( t, v, a, j )

d = 185
time = interpolate.interp1d( D, T )
print( time(d) )

• Thanks a lot, I think now I get it. You basically create a look-up table for different $\Delta t$ and $d$ values, and then use that to estimate $\Delta t$ for arbitrary $d$, no? But why do you choose $t$ values from 0 to 10? Is there any specific reason, or is it just an arbitrary choice?
– mapf
Commented Mar 8, 2022 at 15:43
• The specific values I have chosen have no particular meaning. It is just a demo. Commented Mar 8, 2022 at 17:21