Fitting a modified Bézier curve

81 Views Asked by At

I am connecting various vectors with a Bézier curve, using the De Casteljau algorithm. These vectors have a variety of lengths and directions, and when they are equal and orthogonal the curve (purple) is not a quadrant of a circle (blue), as Fig. 1 shows, and I would like it to be.

If I replace the middle control point with two more, at the midpoints of the first two vectors, the (recursively drawn) curve is flatter as Fig. 2 shows, but is now a bit too shallow.

To get an exact fit as seen in Fig. 3, I used a ratio of $229 / 512 = 0.447265625$ which I found by trial and error.

Can anyone please show the precise value mathematically? You might ask why I don't just draw a quadrant arc: I want to apply the same algorithm to all the other pairs of vectors.

enter image description here

2

There are 2 best solutions below

6
On BEST ANSWER

Suppose you want a quarter of a concave, circular arc from $(0,1)$ to $(1,0)$. Then you can impose the following constraints on the Bézier $b:[0,1]\to\Bbb R^2$:

  1. $b(0) = (0,1)$ and $b(1) = (1,0)$
  2. $b'(0) ~\|~ (0,-1)$ and $b'(1) ~\|~ (1,0)$ where $\|$ means parallel and oriented in the same direction.
  3. $b(1/2) = (1-1/\sqrt2, 1-1/\sqrt2)$

A cubic Bézier is determined by 8 values, namely 4 control points of dimension 2. Constraint 1 yields the 2 control points $P_0$ and $P_3$ at the end of the Bézier. Constraint 2 yields 2 conditions for the control points in the middle, and constraint 3 yields another 2 conditions, so that the Bézier is uniquely determined.

In particular, constraint 2 states that $P_1 = (0,u)$ and $P_2 = (v,0)$, and constraint 3 yields $u$ and $v$ (where we know that $u=v$ due to symmetry).

Doing the numerics, which I leave as an exercise, you will find $$ u=v=\frac13(7-4\sqrt2) \approx 0.4477 \tag 1 $$

FYI, here is a Desmos plot of a cubic Bézier adjusted to these values.


So here is the general approach:

Suppose we want to fit a 2-dimensional curve $f$

$$\begin{align} f: [t_0, t_1] &\;\to\; \Bbb R^2 \\ t &\;\mapsto\; (x(t),\,y(t)) \\\tag 2 \end{align}$$

by means of a cubic Bézier $b=b_{[P_0,P_1,P_2,P_3]}$:

$$\begin{align} b(t) &= (1-t)^3 P_0 + 3(1-t)^2t P_1 + 3(1-t)t^2 P_2 + t^3 P_3 \\ &= P_0 + 3(P_1-P_0)t + 3(P_2-2P_1+P_0)t^2 + (P_3-3P_2+3P_1-P_0)t^3\\ &= P_3 + 3(P_2-P_3)(1-t) + 3(P_1-2P_2+P_3)(1-t)^2 + (P_0-3P_1+3P_2-P_3)(1-t)^3 \\ \tag 3 \end{align}$$

From the two last representations we see immediately the value of the derivatives of $b$ in the end points. We want the first derivative in the end points to point in the same direction like the derivatives of $f$ do. Thus

$$\begin{align} P_0 &= f_0\\ P_1 &= f_0 + \alpha \cdot \dot f_{\!0}\\ P_2 &= f_1 - \beta \cdot \dot f_{\!1}\\ P_3 &= f_1\\ \tag 4 \end{align}$$ with abbreviations like $\dot f_{\!0} = f'(t_0)$ etc.

The system aboves leaves two degrees of freedom, so we can impose that some point $Q$ is incident on the Bézier, i.e. $b(t)=(x_t,y_t)\stackrel!=Q$. This gives a linear system that determines $\alpha$ and $\beta$:

$$ \binom{x_t-x_0}{y_t-y_0} + (2t^3-3t^2)\binom{x_1-x_0}{y_1-y_0} ~=~ 3t(1-t)\binom{(1-t) \dot x_0 \quad -t \dot x_1}{(1-t) \dot y_0 \quad -t \dot y_1}\binom \alpha\beta \tag 5 $$

For the special case $t=1/2$, and when resolved for $\alpha$ and $\beta$, the system $(5)$ above becomes:

$$ \binom \alpha\beta = \frac 43\, \frac{1}{\dot x_1\dot y_0 - \dot x_0\dot y_1} \binom{\dot y_1 \quad -\dot x_1}{\dot y_0 \quad -\dot x_0} \binom{x_0+x_1-2x_{1/2}}{y_0+y_1-2y_{1/2}} \\ \tag 6 $$

So all what remains is to drop in values for a concave circular arc, like e.g. $x_0=y_1=0$, $~y_0=x_1=1$, $~x_{1/2} = y_{1/2} = 1-1/\sqrt2$, etc. to arrive at $(1)$.

0
On

I used geometry to come up with this expression for a pair of equal length vectors which subtend an angle of $2 \theta$ where $ 2 \theta ≠ \pi$

$k$ is the ratio of the side from the common vertex where the additional 2 points will be that replace it, to make a curve from 4 control points instead of 3.

$$ k = [ \, 4 \times (\frac{1}{\cos^{2}\theta} - \frac{\tan\theta}{\cos\theta}) - 1 \, ] \, / \, 3 $$

$2\theta$ 90 75 60 45 30 15
$k$ 0.447715 0.495462 0.555556 0.630975 0.725860 0.846058

The Bézier curve is in purple, the circular arc in blue.

enter image description here