1

I have two point $p_1$ and $p_2$. The velocity vectors are $v_1$ and $v_2$ respectively. The length of the velocity vectors are constant.

I want to draw a path from $p_1$ to $p_2$ that enters $p_1$ with velocity $v_1$ and exits $p_2$ with velocity $v_2$. I have functions for quadric and cubic splines to my disposal.

How do I calculate the intermediate points (one or two)?

These points are part of a longer path, but I only know these two points at this time. I cannot wait until I know all the points until I draw the path.

Ludolila
  • 3,034
MBanks
  • 13

1 Answers1

1

You want a cubic Bézier curve with control points $p_1$, $p_1+\frac13v_1$, $p_2-\frac13v_2$, and $p_2$.

Note that this is parametrized with $t\in[0,1]$, so the “time” taken between the end points is $1$, and the velocities $v_1$ and $v_2$ are assumed to be scaled correspondingly. If this assumption is wrong, replace the two factors $\frac13$ with appropriately scaled factors. (The factor $\frac13$ is due to the coefficients $3$ in the expression for the derivative of the cubic Bézier, as you find it on the linked Wikiepedia article.)

  • What would the factors be if t∈[a,b]? I'm interpolating a movement and I need to account for dropped frames. – MBanks Jul 24 '14 at 18:30
  • You can look at it this way: Your curve would have the form $p(t)=q((t-a)/(b-a))$ (for $t\in[a,b]$) where $q$ is a standard Bézier curve on $[0,1]$. Thus $p'(t)=q'((t-a)/(b-a))/(b-a)$, in particular $p'(a)=q'(0)/(b-a)$. You want to plug in $q'(0)$ in place of $v_1$ in the formula, but $q'(0)=(b-a)p'(a)$, so the control points would be $p(a)$, $p(a)+\frac13(b-a)p'(a)$, $p(b)-\frac13(b-a)p'(b)$, and $p(b)$. (And if I managed to get it backwards – which I don't think I did – you should divide by $(b-a)$ instead.) – Harald Hanche-Olsen Jul 24 '14 at 20:00