I need to get a curve that passes through three points with another requirement.
If I have points P0 P1 and P2 and a value Mu in the range $0..1$ representing where on the curve we are,
mu=0 should result in P0
mu=.5 should result in P1
mu=1 should result in P2
Also:
mu=.25 should result in the halfway point between P0 and P1
mu=.75 should result in the halfway point between P1 and P2
I need a Mu value of $.25$ or $.75$ is halfway along the curve between P0 and P1 or P1 and P2
Unfortunately, everything I've tried to do results in a curve whose midpoint of P0->P1 or P1->P2 is closer to $.255$ than to $.25$
I've tried a few different algorithms -- using this page http://blog.sklambert.com/finding-the-control-points-of-a-bezier-curve/#disqus_thread to figure out how to use P1 to find control points that I can use to make a cubic bezier curve mostly works, but the width of the tangent
I also just tried to straight up calculate the offset between the mid point of a quadratic curve and P1, then add $offset*abs((1-mu)^2)$ to the resulting bezier curve, which has a result pretty close, but also wrong. The bezier algorithm weights the samples towards P1, instead of evenly distributing them.
Is there a way to do what I want?
Thanks, Ben
Is there a way to do this?
Having $\mu=\frac14$ result in the point half way between $P_0$ and $P_1$ feels like a unit speed parametrization of that first half of the curve. If you do the same for the second half, you will get a discontinuity at $P_1$ unless that point itself is half way between $P_0$ and $P_2$.
Personally I'd take a projective view on this. Three points on a conic define a projective scale, so I'd consider something like the circle through these three points (which becomes the line through them if they are collinear). Usually a projective scale is defined in terms of $0,1,\infty$ instead of $0,\frac12,1$. But the point for $\mu=\infty$ can be constructed like this: construct tangents in $P_0$ and $P_2$. Connect the point where these intersect with $P_1$. That line will intersect the circle in a second point, which is the point for $\mu=\infty$. For the collinear case, using the tangents like this won't work, but there is an alternate way to construct a harmonic throw on a straight line. If $P_1$ is the regular euclidean midpoint between $P_0$ and $P_2$ then this point for $\mu=\infty$ would indeed be at infinity, and you get a regular constant speed parametrization of the line.
I've created a blog post to illustrate this approach. That may help you decide whether it satisfies your requirements or not. If you want to do some computations yourself, here is a formula which is the result of a quick Sage computation:
Here is how I came up with that formula. I concentrated on cross ratios, with the circle itself playing only a minor role. Along a line, the cross ratio $(P_0,P_2;P_1,Q)$ is $\infty$ for $Q=P_0$, $0$ for $Q=P_2$ and $1$ for $Q=P_1$. To make this fit in with your values of $0,\frac12,1$, you'd apply a (real) Möbius transformation to $\mu$ to map it to $\frac{\mu}{1-\mu}$. The cross ratio of four points on a given conic is the same as the cross ratio of these points seen from a fifth point. The ideal circle points $I=[1:i:0]$ and $J=[1:-i:0]$ lie on every circle. So we can characterize $Q$ by
$$(P_0,P_2;P_1,Q_\mu)_I=(P_0,P_2;P_1,Q_\mu)_J=\frac{\mu}{1-\mu}$$
Plugging in the equation for a cross ratio you'd get
$$\frac{[I,P_0,P_1][I,P_2,Q_\mu]}{[I,P_2,P_1][I,P_0,Q_\mu]}=\frac{\mu}{1-\mu}$$
where the square brackets denote determinants of homogeneous coordinates. Cross multiplication turns this into
$$(1-\mu)[I,P_0,P_1][I,P_2,Q_\mu]-\mu[I,P_2,P_1][I,P_0,Q_\mu]=0$$
This restricts $Q_\mu$ to a line. The homogeneous coordinates of that line can be computed by using $[I,P_2,Q_\mu]=\langle I\times P_2,Q_\mu\rangle$ and so on.
$$(1-\mu)[I,P_0,P_1](I\times P_2)-\mu[I,P_2,P_1](I\times P_0)$$
Doing the same for $J$ instead of $I$, i.e. applying a complex conjugation to the above, will lead to the description of a second line. Intersecting these two lines will give homogeneous coordinates of $Q_\mu$.