For context, I am trying to write animation software and, in doing so, have encountered this problem. I ask that you not be too critical of the setup I have going on because I have no background on the topic.
Let $p(t)$ represent an object's position as a function of time $t\in\mathbb{R}_{\ge0}$. Call $O$ the starting point and $X$ the target point such that $p(0)=O$ and $p(d)=X$, where $d>t$ is the time duration of the movement from $O$ to $X$.
If $O$, $X$, and $d$ are given, how should I go about finding $p(t)$?
Of course, there is more to consider here. We could always write an obvious step function $$ p(t)=\begin{cases}O\quad\text{if}\quad t<d\\X \quad\text{if}\quad t=d\end{cases}, $$ but this is being used for animation; the movement should be somewhat artistically desirable.
If we want the object to move at a constant speed in a straight line from $O$ to $X$, the solution is simple. We have $$ p(t)=O+\frac{t}{d}(X-O),\tag1 $$ which is really just a parametric equation for a ray with origin $O$ cast towards $X$.
I get stuck when I want to get fancier.
- What if I want to have variable movement speed? Say, acceleration at the start of the movement and deceleration near the end, similar to that of a car?
- How about nonlinear paths? Say I want the object to follow a parabolic (or even sinusoidal, bezier, etc.) curve from $O$ to $X$.
I feel as though the answers to the questions above are simple (just some expression involving $O$, $X$, $t$, and $d$), but I cannot visualize solutions past the simple constant speed linear case. What am I thinking wrong?
The only thing I've managed to put together is a more general version of $(1)$: $$ p(t)=O+\frac{f(t)}{f(d)}(X-O), $$ where $f$ needs to satisfy $f(0)=0$ and $f(d)\ne0$ so that when $t=0$, we have $$ p(0)=O+\frac{f(0)}{f(d)}(X-O)=O+0(X-O)=O. $$ and when $t=d$, we have $$ p(d)=O+\frac{f(d)}{f(d)}(X-O)=O+X-O=X. $$ By defining $f$ in different ways, I can finally see some acceleration and deceleration effects. However, I do not know how $f$ exactly relates to the behaviour of the movement which is a big concern when writing software that should be intuitive. Still have no ideas on nonlinear movement either.
One way to express things is by using Cartesian plane cordinates. Motion of a point may be modeled as a path: a pair of continuous functions $$ p(t) = \bigl(p_{1}(t), p_{2}(t)\bigr) $$ satisfying $p(0) = O$ and $p(d) = X$. The image of this path, namely the set of points actually traced out, is the resulting curve. The classic toy Etch-A-Sketch implements motion separated into Cartesian components, with one knob controlling $p_{1}$ and one controlling $p_{2}$.
If both components $p_{1}$ and $p_{2}$ are differentiable, the point has a velocity $p' = (p_{1}', p_{2}')$ at each time. Note that a differentiable path can trace a curve with corners; a classic example is the infinitely differentiable path $p(t) = (\cos^{3} t, \sin^{3}, t)$, which traces the astroid. If the velocity of $p$ is nowhere zero, however, then a differentiable path traces a curve having a tangent line at each point (aside from technicalities about self-crossing, where we can nitpick what we mean by tangent line).
Separately, suppose $p$ is a choice of path from $O$ to $X$, and defined for $0 \leq t \leq d$. "Varying the speed" can be modeled by reparametrization. If we want our path to be defined for time $s$ between $a$ and $b$, we can pick a function $\tau$ mapping $[a, b]$ to $[0, d]$ and satisfying $\tau(a) = 0$, $\tau(b) = d$, and considering the path $$ q(s) = p\bigl(\tau(s)\bigr) = p(t). $$ If $\tau$ is strictly increasing, $q(s)$ "moves from $O$ toward $X$" as $s$ runs from $a$ to $b$. If $\tau$ "wiggles up and down," $q(s)$ "wiggles back and forth along the chosen curve."
We can "trace a path backwards" by instead picking $\tau$ so that $\tau(b) = 0$ and $\tau(a) = d$. If $\tau$ is strictly decreasing, $q(s)$ "moves from $X$ toward $O$" as $s$ runs from $a$ to $b$. A standard choice is $$ q(s) = p(d - s), $$ which is defined for $0 \leq s \leq d$.
<>
For example: