# Calculate control points of cubic bezier curve approximating a part of a circle

I'm not mathematically inclined, so please be patient with my question.

Given

• $(x_0, y_0)$ and $(x_1, y_1)$ as the endpoints of a cubic Bezier curve.

• $(c_x, c_y)$ and r as the centerpoint and the radius of a circle.

• $(x_0, y_0)$ and $(x_1, y_1)$ are on the circle.

• if it makes the calculation simpler, it's safe to assume the arc is less than or equal to $\frac{\pi}{2}$.

How do I calculate the two control points of the Bezier curve that best fits the arc of the circle from $(x_0, y_0)$ to $(x_1, y_1)$?

Let $(x,y)^R=(-y,x)$ represent rotation by $\pi/2$ counterclockwise and $$\gamma(t)=(1-t)^3p_0+3t(1-t)^2p_1+3t^2(1-t)p_2+t^3p_3$$ define a cubic bezier with control points $\{p_0,p_1,p_2,p_3\}$.

Suppose $p_0=(x_0,y_0)$, $p_3=(x_1,y_1)$, and $c=(c_x,c_y)$ are given so that $|p_0-c|=|p_3-c|=r$ ($p_3$ is counterclockwise from $p_0$). Then $p_1=p_0+\alpha(p_0-c)^R$ and $p_2=p_3-\alpha(p_3-c)^R$ where $$\alpha=\frac43\tan\left(\frac14\cos^{-1}\left(\frac{(p_0-c)\cdot(p_3-c)}{r^2}\right)\right)$$ For a quarter of a circle, $\alpha=\frac43(\sqrt2-1)$, and $\gamma$ is no more than $0.00027$ of the radius of the circle off.

Here is a plot of $\gamma$ in red over the quarter circle in black. We really don't see the circle since it is no more than $0.1$ pixels off from $\gamma$ when the radius is $400$ pixels.

$\hspace{3.5cm}$

Computation of $\boldsymbol{\alpha}$

Looking at an arc with an angle of $\theta=\cos^{-1}\left(\frac{(p_0-c)\cdot(p_3-c)}{r^2}\right)$

$\hspace{1.5cm}$

we see that the distance from $c$ to the middle of the arc is $$r\cos(\theta/2)+\frac34\alpha r\sin(\theta/2)$$ we wish to choose $\alpha$ so that this is equal to $r$. Solving for $\alpha$ gives \begin{align} \alpha &=\frac43\frac{1-\cos(\theta/2)}{\sin(\theta/2)}\\ &=\frac43\tan(\theta/4) \end{align}

A Slight Improvement

Using a circle of radius $1$, the maximum error in radius produced using $\alpha=\frac43\tan(\theta/4)$ is approximately $$0.0741\cos^4(\theta/4)\tan^6(\theta/4)$$ and the error is always positive; that is, the cubic spline never passes inside the circle. Reducing $\alpha$ reduces the midpoint distance by $\frac34\sin(\theta/2)=\frac32\tan(\theta/4)\cos^2(\theta/4)$ times as much, so to distribute the error evenly between the positive and negative, a first guess, assuming that the amplitude of the radius is unchanged, would be to reduce $\alpha$ by $0.0247\cos^2(\theta/4)\tan^5(\theta/4)$.

A bit of investigation shows that, when equalizing the positive and negative swings of the radius, the amplitude increases and that $$\alpha=\frac43\tan(\theta/4)-0.03552442\cos^2(\theta/4)\tan^5(\theta/4)$$ gives pretty even distribution of the error between positive and negative for $\theta\le\pi/2$. The maximum error, both positive and negative, is approximately $$0.0533\cos^4(\theta/4)\tan^6(\theta/4)$$ When $\theta=\pi/2$, this agrees with the article mentioned by bubba in comments.

Note however, that in minimizing the radial error from the circle, the actual variation in radius is increased. Using the simple formula for $\alpha$, which puts the cubic bezier outside the circle, the radius varies by $0.0741\cos^4(\theta/4)\tan^6(\theta/4)$. However, when we minimize the error, the radial variation increases to $0.1066\cos^4(\theta/4)\tan^6(\theta/4)$.

• This is a very good approximation of a circular arc, and it's the one that's most often used. However, it produces a curve that is everywhere outside the true circular arc. You can get a slightly better approximation by reducing the length of $\alpha$. In fact, the error for a unit radius quarter circle is reduced from 0.00027 to 0.00019. The details are here: spencermortensen.com/articles/bezier-circle – bubba Jul 22 '14 at 6:09
• @bubba: the image in that article is 72 pixels in radius. Using the $\alpha=\frac43(\sqrt2-1)$ would yield a maximum error of $\frac1{500}$ of a pixel, so I don't think the error from either approximation would be noticeable. – robjohn Jul 22 '14 at 17:29
• Would the downvoter care to comment? – robjohn Jul 22 '14 at 19:15
• @bubba: I have added a section in which I adjust $\alpha$ so that the positive and negative errors are equalized. – robjohn Jul 23 '14 at 0:03
• Nice. I agree that the accuracy of the original approximation would be fine for almost all applications. To get better approximations, you can apply the same sort of equi-oscillatory construction with higher degree polynomials (though it gets much harder). The accepted answer to this question has the details: math.stackexchange.com/questions/271319/… – bubba Jul 23 '14 at 11:03