# Get a curve through three points whose samples are evenly distributed

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?

• Of course you need a smooth curve, right? If not, two consecutive segments would be a simple solution. And I also suppose you wouldn't like a piecewise defined curve, but you should state that explicitly. Is a Bézier curve mandatory? Commented Dec 22, 2016 at 7:36
• but what if the midpoint is not on the curve ? Commented Dec 22, 2016 at 9:20
• @Ben Andersen You need to define halfway. Is it " approximately in between" ? Commented Dec 22, 2016 at 10:58
• I'm not sure if this belongs in the original question. I'm using this to calculate curved motion blur based on the acceleration of a point through XYZ space. If I have a point starting at (1,0,0) rotating around Y 90 degrees per frame, I would expect mu=.75 on Frame 1 to match exactly with mu=.25 on Frame 2, since the curves should have the same acceleration and the mid points of the two curve segments should match. @Aretino - I do need a smooth curve, yeah. I don't mind calculating the two curves separately as long as the curve is continuous through P1. Commented Dec 23, 2016 at 0:36
• Also you allow any smooth curve pass through the given points, Right? Commented Dec 24, 2016 at 16:42

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:

x = ((x0^2*x1 + y0^2*x1 - 2*x0*x1^2 - 2*x0*y1^2 - 2*x0^2*x2 - 2*y0^2*x2 + 6*x0*x1*x2 - 2*x1^2*x2 + 4*y0*y1*x2 - 2*y1^2*x2 - 2*x0*x2^2 + x1*x2^2 - 2*y0*x1*y2 + 4*x0*y1*y2 - 2*x0*y2^2 + x1*y2^2)*mu^2 + (-x0^2*x1 - y0^2*x1 + 3*x0*x1^2 + 3*x0*y1^2 + x0^2*x2 + y0^2*x2 - 6*x0*x1*x2 + x1^2*x2 - 2*y0*y1*x2 + y1^2*x2 + 3*x0*x2^2 - x1*x2^2 + 2*y0*x1*y2 - 6*x0*y1*y2 + 3*x0*y2^2 - x1*y2^2)*mu - x0*x1^2 - x0*y1^2 + 2*x0*x1*x2 - x0*x2^2 + 2*x0*y1*y2 - x0*y2^2)/((-x0^2 - y0^2 + 4*x0*x1 - 4*x1^2 + 4*y0*y1 - 4*y1^2 - 2*x0*x2 + 4*x1*x2 - x2^2 - 2*y0*y2 + 4*y1*y2 - y2^2)*mu^2 + (-2*x0*x1 + 4*x1^2 - 2*y0*y1 + 4*y1^2 + 2*x0*x2 - 6*x1*x2 + 2*x2^2 + 2*y0*y2 - 6*y1*y2 + 2*y2^2)*mu - x1^2 - y1^2 + 2*x1*x2 - x2^2 + 2*y1*y2 - y2^2)
y = ((-2*y0*x1^2 + x0^2*y1 + y0^2*y1 - 2*y0*y1^2 + 4*y0*x1*x2 - 2*x0*y1*x2 - 2*y0*x2^2 + y1*x2^2 - 2*x0^2*y2 - 2*y0^2*y2 + 4*x0*x1*y2 - 2*x1^2*y2 + 6*y0*y1*y2 - 2*y1^2*y2 - 2*y0*y2^2 + y1*y2^2)*mu^2 + (3*y0*x1^2 - x0^2*y1 - y0^2*y1 + 3*y0*y1^2 - 6*y0*x1*x2 + 2*x0*y1*x2 + 3*y0*x2^2 - y1*x2^2 + x0^2*y2 + y0^2*y2 - 2*x0*x1*y2 + x1^2*y2 - 6*y0*y1*y2 + y1^2*y2 + 3*y0*y2^2 - y1*y2^2)*mu - y0*x1^2 - y0*y1^2 + 2*y0*x1*x2 - y0*x2^2 + 2*y0*y1*y2 - y0*y2^2)/((-x0^2 - y0^2 + 4*x0*x1 - 4*x1^2 + 4*y0*y1 - 4*y1^2 - 2*x0*x2 + 4*x1*x2 - x2^2 - 2*y0*y2 + 4*y1*y2 - y2^2)*mu^2 + (-2*x0*x1 + 4*x1^2 - 2*y0*y1 + 4*y1^2 + 2*x0*x2 - 6*x1*x2 + 2*x2^2 + 2*y0*y2 - 6*y1*y2 + 2*y2^2)*mu - x1^2 - y1^2 + 2*x1*x2 - x2^2 + 2*y1*y2 - y2^2)


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$.

• Great, thanks, I'll take a look at graphing a circle between the points, then I should be able to use polar coordinates to pick different mu values, right? I have a hard time figuring out how to convert some of the explanations I see on the internet to python. Like this: klein.math.okstate.edu/~wrightd/INDRA/MobiusonCircles/… Commented Dec 23, 2016 at 1:00
• @BenAndersen: Personally I'd not use polar coordinates, but stereographic projection. With polar coordinates, you again have to decide what to do in case $P_1$ is not in the middle between $P_0$ and $P_2$. If you use the point for $\mu=\infty$ as center of a stereographic projection, the projected points will have $P_1$ centered between $P_0$ and $P_2$.
– MvG
Commented Dec 23, 2016 at 11:08
• @BenAndersen: As a Christmas present I've worked out some formula for you. Explanation can come later, but this might help you use my idea.
– MvG
Commented Dec 23, 2016 at 15:35
• @BenAndersen I've just created a blog post illustrating my approach, to give you something to toy with.
– MvG
Commented Dec 30, 2016 at 13:10
• Wow, this is really helpful! That algorithm works really well. There's no way I'd have gotten that on my own. I made a mistake earlier when I said that P1 would be equidistant between P0 and P2, since it usually won't be. mu=.5 should still result in P1 though. I do notice that if P1 is not equidistant between P0 and P2, that mu=.25 and mu=.75 aren't equidistant between P0/P1 or P1/P2. I think that means there would be a break point at P1 for unit speed though, which is okay. Commented Jan 9, 2017 at 2:55