Define position of an object as a function of time such that object travels in fancy ways to a given point within a given duration

95 Views Asked by At

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.

1

There are 1 best solutions below

2
On

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:

  • $p(t) = (t, t^{2})$ traces the part of the parabola $y = x^{2}$ with $0 \leq x \leq 1$ as $t$ runs from $0$ to $1$.
  • $q(s) = p(s^{10}) = (s^{10}, s^{20})$ traces the same parabolic arc as $s$ runs from $0$ to $1$, "easing out" of $O = (0, 0)$ and rocketing toward $X = (1, 1)$.
  • $q(s) = p\bigl(\sin^{2}(\pi s/2)\bigr) = \bigl(\sin^{2}(\pi s/2), \sin^{4}(\pi s/2)\bigr)$ traces the same parabolic arc as $s$ runs from $0$ to $1$, "easing out" of $O = (0, 0)$ and "easing in" to $X = (1, 1)$. (The point "oscillates back and forth along the parabola" if we let $s$ vary freely.)
  • $q(s) = (\sin^{2} s, \sin^{4} s)$ traces the same parabolic arc as $s$ runs from $0$ to $\pi/2$, "easing out" of $O = (0, 0)$ and "easing in" to $X = (1, 1)$.
  • $q(s) = p(1 - s) = (1 - s, 1 - 2s + s^{2})$ traces the parabolic arc "backward" from $X$ to $O$ as $s$ runs from $0$ to $1$.