1 \documentclass{article
}
5 \newcommand{\sign}{\operatorname{sign
}}
9 \section{B\'ezier curves with prescribed tangent directions and curvatures at the endpoints
}
12 Parameterization of the B\'ezier curve, for $x(t)$ and $y(t)$ equivalently,
15 x(t) &= x_0(
1-t)^
3 +
3x_1t(
1-t)^
2 +
3x_2t^
2(
1-t) + x_3 t^
3\\
16 \dot x(t) &=
3(x_1-x_0)(
1-t)^
2 +
3(x_3-x_2)t^
2 +
6(x_2-x_1)t(
1-t) \\
17 \ddot x(t) &=
6(x_0 -
2x_1 + x_2)(
1-t) +
6(x_1-
2x_2+x_3) t \\
18 \dddot x(t) &=
6(x_3-x_0) +
18(x_1-x_2)
23 \kappa(t) =
\frac{\dot x
\ddot y -
\ddot x
\dot y
}{[\dot x^
2 +
\dot y^
2]^
{3/
2}}
30 \sign\kappa &>
0 \quad\text{for left bendings
}\\
31 \sign\kappa &<
0 \quad\text{for right bendings.
}
35 At the endpoints we can summarize:
38 \dot x(
0) &=
3(x_1 - x_0) \\
39 \dot x(
1) &=
3(x_3 - x_2) \\
40 \ddot x(
0) &=
6(x_0 -
2x_1 + x_2) = -
4\dot x(
0) -
2\dot x(
1) +
6(x_3 - x_0) \\
41 \ddot x(
1) &=
6(x_1 -
2x_2 + x_3) = +
4\dot x(
1) +
2\dot x(
0) -
6(x_3 - x_0)
44 and the same for the $y$ coordinates.
45 The equations for the $
\ddot x$ contain a convenient parameterization for this
46 problem, with given endpoints and tangent directions. We now introduce two
47 parameters for the distances between the first and the last pair of control
53 \left(
\begin{array
}{cc
}
57 \left(
\begin{array
}{cc
}
58 \dot x(
0) \\
\dot y(
0)
61 \left(
\begin{array
}{cc
}
64 \left(
\begin{array
}{cc
}
68 \left(
\begin{array
}{cc
}
69 \dot x(
1) \\
\dot y(
1)
72 \left(
\begin{array
}{cc
}
74 \end{array
}\right)
\qquad
78 Here, the externally prescribed tangent vectors are expected to be parallel to
79 the tangent vectors of the parameterization and normalized to
1. This implies
80 $
\alpha>
0$ and $
\beta>
0$ are the distances between the endpoints and their
81 corresponding control points.
83 The problem to now to find proper parameters $
\alpha>
0$ and $
\beta>
0$ for a given set of
84 endpoints $(x_0,y_0)$, $(x_3, y_3)$,
85 normalized tangent vectors $
\mathbf{t
}(
0)$, $
\mathbf{t
}(
1)$ and of
86 curvatures $
\kappa(
0),
\kappa(
1)$.
87 The rest of the control points is then given by
90 x_1 = x_0 +
\alpha t_x(
0)
\quad\text{and
}\quad
91 x_2 = x_3 -
\beta t_x(
1).
94 For the curvatures at the endpoints we get a nonlinear equation,
97 \kappa(
0) (
\dot x^
2(
0) +
\dot y^
2(
0))^
{3/
2}
98 &=
\dot x(
0)
\ddot y(
0) -
\ddot x(
0)
\dot y(
0) \\
99 =
27 \kappa(
0) |
\alpha|^
3
100 &=
\begin{aligned
}[t
]
101 &+
\dot x(
0)
\bigl[-
4\dot y(
0) -
2\dot y(
1) +
6(y_3-y_0)
\bigr] \\
102 &-
\dot y(
0)
\bigl[-
4\dot x(
0) -
2\dot x(
1) +
6(x_3-x_0)
\bigr]
104 &=
\begin{aligned
}[t
]
105 &-
2 \bigl[\dot x(
0)
\dot y(
1) -
\dot y(
0)
\dot x(
1)
\bigr] \\
106 &+
6 \bigl[\dot x(
0) (y_3-y_0) -
\dot y(
0) (x_3-x_0)
\bigr]
108 &=
\begin{aligned
}[t
]
109 &-
18 \alpha\beta \bigl[t_x(
0)t_y(
1) - t_y(
0)t_x(
1)
\bigr] \\
110 &+
18 \alpha \bigl[t_x(
0) (y_3-y_0) - t_y(
0) (x_3-x_0)
\bigr]
117 0 =
\frac{3}{2}\kappa(
0)
\alpha^
2 \sign(
\alpha)
118 +
\beta \bigl[t_x(
0)t_y(
1) - t_y(
0)t_x(
1)
\bigr]
119 -
\bigl[t_x(
0) (y_3-y_0) - t_y(
0) (x_3-x_0)
\bigr]
122 A similar calculation can be done for the end curvature,
125 \kappa(
1) (
\dot x^
2(
1) +
\dot y^
2(
1))^
{3/
2}
126 &=
\dot x(
1)
\ddot y(
1) -
\ddot x(
1)
\dot y(
1) \\
127 =
27 \kappa(
1) |
\beta|^
3
128 &=
\begin{aligned
}[t
]
129 &+
\dot x(
1)
\bigl[ 4\dot y(
1) +
2\dot y(
0) -
6(y_3-y_0)
\bigr] \\
130 &-
\dot y(
1)
\bigl[ 4\dot x(
1) +
2\dot x(
0) -
6(x_3-x_0)
\bigr]
132 &=
\begin{aligned
}[t
]
133 &-
2 \bigl[\dot x(
0)
\dot y(
1) -
\dot y(
0)
\dot x(
1)
\bigr] \\
134 &-
6 \bigl[\dot x(
1) (y_3-y_0) -
\dot y(
1) (x_3-x_0)
\bigr]
136 &=
\begin{aligned
}[t
]
137 &-
18 \alpha\beta \bigl[t_x(
0)t_y(
1) - t_y(
0)t_x(
1)
\bigr] \\
138 &-
18 \beta \bigl[t_x(
1) (y_3-y_0) - t_y(
1) (x_3-x_0)
\bigr]
142 0 =
\frac{3}{2}\kappa(
1)
\beta^
2 \sign(
\beta)
143 +
\alpha \bigl[t_x(
0)t_y(
1) - t_y(
0)t_x(
1)
\bigr]
144 +
\bigl[t_x(
1) (y_3-y_0) - t_y(
1) (x_3-x_0)
\bigr]
147 Alltogether, we find the system of equations that is to be solved.
151 0 &=
\frac{3}{2} \kappa(
0)
\alpha^
2 \sign(
\alpha) +
\beta T - D \\
152 0 &=
\frac{3}{2} \kappa(
1)
\beta^
2 \sign(
\beta) +
\alpha T - E
153 \end{aligned
}\\
[\medskipamount]
155 T &:= t_x(
0)t_y(
1) - t_y(
0)t_x(
1) \\
156 D &:=
\bigl[t_x(
0) (y_3-y_0) - t_y(
0) (x_3-x_0)
\bigr]\\
157 E &:=
\bigl[t_x(
1) (y_0-y_3) - t_y(
1) (x_0-x_3)
\bigr]
161 Decoupling the two equations causes problems with the absolute values,
164 \alpha =
\frac{1}{T
}\left(E -
\frac{3}{2}\kappa(
1)
\beta |
\beta |
\right)
\quad\text{and
}\quad
165 \beta =
\frac{1}{T
}\left(D -
\frac{3}{2}\kappa(
0)
\alpha|
\alpha|
\right)
168 Thus, for $
\alpha>
0$ and $
\beta>
0$ we need also
171 \frac{1}{T
}\left(E -
\frac{3}{2}\kappa(
1)
\beta |
\beta |
\right) >
0\quad\text{and
}\quad
172 \frac{1}{T
}\left(D -
\frac{3}{2}\kappa(
0)
\alpha|
\alpha|
\right) >
0
175 which is not always guaranteed. E.g. the combination
178 T>
0,
\quad E<
0\quad\text{and
}\quad \kappa(
1)>
0
181 is not compatible with a positive value of $
\beta$. Under what circumstances do
182 we get such geometrically invalid results? Tests show that even allowing
183 arbitrary signs of the curvatures $
\kappa(
0)$~and $
\kappa(
1)$ does not help in
186 The decoupled equations can be constructed by inserting $
\alpha$~and $
\beta$
187 into the equations for the curvatures. This reads
189 0 &=
\frac{3}{2}\kappa(
0)
\sign(
\alpha)
190 \left(E -
\frac{3}{2}\kappa(
1)
\beta |
\beta |
\right)^
2
191 +
\beta T^
3 - D T^
2 \\
192 &=
\begin{aligned
}[t
]
193 \frac{27}{8} \kappa(
0)
\kappa^
2(
1)
\sign(
\alpha)
\beta^
4
194 -
\frac{9}{2} E
\kappa(
0)
\kappa(
1)
\sign(
\alpha)
\sign(
\beta)
\beta^
2
196 {}+
\frac{3}{2} \kappa(
0)
\sign(
\alpha) E^
2 - D T^
2
198 0 &=
\begin{aligned
}[t
]
199 \frac{27}{8} \kappa^
2(
0)
\kappa(
1)
\sign(
\beta)
\alpha^
4
200 -
\frac{9}{2} D
\kappa(
0)
\kappa(
1)
\sign(
\alpha)
\sign(
\beta)
\alpha^
2
202 {}+
\frac{3}{2} \kappa(
1)
\sign(
\beta) D^
2 - E T^
2
208 \section{Bounding boxes for B\'ezier curves
}
211 The bounding box is defined by the minimal and maximal values of a
212 curve. Hence the problem decouples for the two coordintes $x$ and $y$.
213 We can search for the minima and maxima within the valid range for the
214 parameter $t$ together with taking into account the values at the
215 boundaries at $t=
0$ and $t=
1$.
217 For the $x$ coordinate we have:
219 x(t) & = x_0(
1-t)^
3 +
3x_1t(
1-t)^
2 +
3x_2t^
2(
1-t) + x_3 t^
3\\
220 & = (x_3-
3x_2+
3x_1-x_0)t^
3 + (
3x_0-
6x_1+
3x_2)t^
2 + (
3x_1-
3x_0)t + x_0\\
221 & = a\,t^
3 +
\frac{3}{2}\,b\,t^
2 +
3\,c\,t + x_0
224 The constants $a$, $b$, and $c$ are
227 a & = x_3-
3x_2+
3x_1-x_0 \\
228 b & =
2x_0-
4x_1+
2x_2 \\
235 \dot x(t) =
3\left[\,a\,t^
2 + b\,t + c\,
\right]
238 For a numerically stable calculation of the roots of the function, we
242 q = -
\frac{1}{2}\left[\,b+
\mathrm{sgn
}(b)
\sqrt{b^
2-
4ac
}\right]\, .
245 In case the square root is negative, we only need to take into account
246 the values at the boundaries. Otherwise we need to take into account
250 t_1 =
\frac{q
}{a
} \quad\text{and
}\quad t_2 =
\frac{c
}{q
}
253 Again, for numerical failures (divisions by zero), we just need to skip
254 the particular solution. The minima and maxima for $x(t)$ can now
255 occur at $t=
0$, $t=t_1$, $t=t_2$ and $t=
1$.
259 \section{Replacing B\'ezier curves by straight lines
}
263 \centerline{\includegraphics{beziertoline
}}
264 \caption{Example for a replacement of a B\'ezier curve by a straight
266 \label{fig:beziertoline
}
269 To solve certain geometrical tasks like measuring the length of a
270 path or finding intersection points between paths, B\'ezier curves
271 are recusively reduced to smaller B\'ezier curves by splitting the
272 curves at the parameter value
0.5 until the parts become almost
273 straight. Using the notation shown in fig.~
\ref{fig:beziertoline
} the
274 straightness is expressed by a length measurement summing up the
275 distances $
\overline{AB
}=l_1$, $
\overline{BC
}=l_2$ and
276 $
\overline{CD
}=l_3$ and comparing this to the direct connection
277 $
\overline{AD
}$. When the difference becomes smaller than a threshold
278 $
\epsilon$, the curve is adequately expressed by a straight line
279 either because the curve is almost straight or it is very short.
281 However, although the geometric changes are limited to distances of
282 $
\epsilon$, the parametrization $t$ of the B\'ezier curve might be
283 mistakenly represented by the straight line on a much larger scale.
284 In the shown example, the point $X$ on the B\'ezier curve and $Y$ on
285 the straight line are both taken at the parameter value $t=
0.5$, but
286 clearly are more separated from each other than one would expect from
287 the geometric distance of the two paths. While the parametrization on
288 a line is proportional to the arc length, a non-linear behaviour is
289 found on a B\'ezier curve. This non-linearity is originated in
290 considerably different lengths $l_1$, $l_2$ and $l_3$ and the mapping
291 of the non-linear parameter to a linear parametrization (in terms of
292 the arc length) can be reduced to a one-dimensional problem upon an
296 x_0(
1-t')+x_3t' = x_0(
1-t)^
3 +
3x_1t(
1-t)^
2 +
3x_2t^
2(
1-t) + x_3 t^
3\,.
299 In this one-dimensional approximation the parameter $t'$ performs a
300 linear mapping as for any straight line while $t$ represents the usual
301 B\'ezier curve parametrization. It now becomes a matter of expressing
302 $t$ by $t'$. The polynomial in $t$ to be solved is:
311 a & = x_3-
3x_2+
3x_1-x_0 = l_1-
2l_
2+l_3 \\
312 b & =
3x_0-
6x_1+
3x_2 = -
3l_
1+
3l_
2 \\
313 c & =
3x_1-
3x_0 =
3l_
1 \\
314 d & = t'(x_0-x_3) = -t'(l_1+l_2+l_3)\,.
317 For $
0\le t'
\le1$ there will be at least one solution $
0\le t
\le1$.
318 Several solutions are possible as well, although they should be close
319 to each other since otherwise the straight line approximation would
323 \section{Relative coordinates
}
326 A B\'ezier curve is given by
328 \vec b(t) = (
1-t)^
3\vec p_0 +
3t(
1-t)^
2\vec p_1 +
3t^
2(
1-t)
\vec p_2 + t^
3\vec p_3
330 where $
\vec p_0 = (x_0, y_0)$, $
\vec p_1 = (x_1, y_1)$, $
\vec p_2 =
331 (x_2, y_2)$, and $
\vec p_3 = (x_3, y_3)$ are the control points.
333 When $
\vec p_0$ differs from $
\vec p_3$ we can express the B\'ezier
334 curve in relative coordinates $r(t)$ and $s(t)$ by
336 \vec b(t) =
\vec q + r(t)
\vec r + s(t)
\vec s
340 \vec q & =
\vec p_0\\
341 \vec r & =
\vec p_3 -
\vec p_0 =
\left(
\begin{array
}{c
} x_3 - x_0 \\ y_3 - y_0
\end{array
}\right)\\
342 \vec s & =
\left(
\begin{array
}{c
} y_3 - y_0 \\ x_0 - x_3
\end{array
}\right)
347 \vec r
\cdot\vec r =
\vec s
\cdot\vec s := l^
2
349 where $l$ is the distance between $
\vec p_0$ and $
\vec p_3$.
351 In addition $
\vec r$ and $
\vec s$ are perpendicular:
353 \vec r
\cdot\vec s =
0
356 We can express the control points in the new coordinates:
358 \vec p_0 & =
\vec q\\
359 \vec p_1 & =
\vec q + r_1
\vec r + s_1
\vec s\\
360 \vec p_2 & =
\vec q + r_2
\vec r + s_2
\vec s\\
361 \vec p_3 & =
\vec q +
\vec r
364 The coefficients $r_1$, $r_2$, $s_1$, $s_2$ are given by scalar
365 products due to the properties of $
\vec r$ and $
\vec s$ given above:
367 r_1 l^
2 & = (
\vec p_1 -
\vec p_0)
\cdot\vec r\\
368 r_2 l^
2 & = (
\vec p_2 -
\vec p_0)
\cdot\vec r\\
369 s_1 l^
2 & = (
\vec p_1 -
\vec p_0)
\cdot\vec s\\
370 s_2 l^
2 & = (
\vec p_2 -
\vec p_0)
\cdot\vec s
373 The parametric functions $r(t)$ and $s(t)$ become
375 r(t) & =
3t(
1-t)^
2 r_1 +
3t^
2(
1-t) r_2 + t^
3\\
376 s(t) & =
3t(
1-t)^
2 s_1 +
3t^
2(
1-t) s_2
379 \emph{Note:
} Originally the idea was to use relative coordinates to
380 remove unstabilities in B\'ezier curves (especially cusps) considering
381 all points with $
\dot r(t)$ being zero or extremal. This idea works
382 very well in general, and could, for example, also remove
383 self-intersections. (You can get rid of any backwards directed curve
384 sections, i.e. where $
\dot r(t)<
0$.) However, the whole idea has been
385 discarded as $
\dot r(t)$ could be close to zero for $t=
0$ and $t=
1$.
386 The pre-removal of such problems would introduce major defects to the
387 B\'ezier curve (like changing the direction of the tangential vector
388 at the beginning and the end point).
391 \section{Invalid parametrisation
}
394 If the derivative of the parametrisation vanishes (both coordinates) at a
395 parameter~$t
\in[0,
1]$, the parametrisation is considered to be invalid at this
396 point. Under which circumstances can this occur? We search for solutions~$t$ for
397 the quadratic equations
402 0 = x(t)/
3 &= t^
2\bigl[(x_3-x_0) -
3(x_2-x_1)
\bigr] +
2t
\bigl[(x_2-x_1)-(x_1-x_0)
\bigr] + (x_1-x_0) \\
403 0 = y(t)/
3 &= t^
2\bigl[(y_3-y_0) -
3(y_2-y_1)
\bigr] +
2t
\bigl[(y_2-y_1)-(y_1-y_0)
\bigr] + (y_1-y_0)
407 Using the usual formula for a quadratic equation $
0=at^
2 + bt + c$, we get the
408 same parameter for $x$- and $y$-coordinates, and the two inequalities from
413 t_
{1,
2} =
\frac{1}{2a_x
} \Bigl(-b_x
\pm^
1 \sqrt{b_x^
2 -
4a_xc_x
}\Bigr)
414 =
\frac{1}{2a_y
} \Bigl(-b_y
\pm^
2 \sqrt{b_y^
2 -
4a_yc_y
}\Bigr)
417 The two sign choices are independent of each other.
419 For the moment, we put aside the special cases $p_3=p_0$ and $p_1=p_0$. As
420 affine transformations cannot change the degeneracy of the parametrisation, we
421 can fix three points without loss of generality:
425 (x_0, y_0) = (
0,
0),
\quad
426 (x_1, y_1) = (
0,
1),
\quad
431 Thus, the only remaining true parameters are $(x_2, y_2)$. We will use $
\Delta x
432 = x_2$ and $
\Delta y = y_2 -
1$. Equation~
\eqref{samet
} now becomes
435 % a_y \Bigl(-b_x/2 \pm^1 \sqrt{(b_x/2)^2 - a_xc_x}\Bigr)
436 % = a_x \Bigl(-b_y/2 \pm^2 \sqrt{(b_y/2)^2 - a_yc_y}\Bigr)
438 % ( -3\Delta y) \Bigl(-(\Delta x ) \pm^1 \sqrt{(\Delta x )^2 }\Bigr)
439 % = (1-3\Delta x) \Bigl(-(\Delta y-1) \pm^2 \sqrt{(\Delta y-1)^2 + 3\Delta y}\Bigr)
442 ( -
3\Delta y)
\Bigl(-
\Delta x
\pm^
1 \sqrt{(
\Delta x )^
2 }\Bigr)
443 = (
1-
3\Delta x)
\Bigl(
1-
\Delta y
\pm^
2 \sqrt{1 +
\Delta y +
\Delta y^
2}\Bigr)
446 Special care has to be taken if $a_x=
0$ or $a_y=
0$. For the inequalities, we
447 have to consider the signs of $a_x$ and $a_y$ explicitly:
452 0 \leq -
\Delta x
\pm^
1 \sqrt{\Delta x^
2} \leq 1-
3\Delta x &
\quad\text{if $
\Delta x <
1/
3$ (or $a_x >
0$)
} \\
453 0 \leq \Delta x
\mp^
1 \sqrt{\Delta x^
2} \leq 3\Delta x-
1 &
\quad\text{if $
1/
3 <
\Delta x$ (or $a_x <
0$)
}
457 which can be reduced to
462 \text{no constraint
} &
\quad\text{if $
\Delta x
\leq 0$
} \\
463 \text{only the upper sign of $
\pm^
1$ is allowed
} &
\quad\text{if $
0 <
\Delta x <
1$
} \\
464 \text{no constraint
} &
\quad\text{if $
\Delta x
\geq 1$
}
468 Between $
0$ and $
1$ the upper sign makes the inequality to be trivially
469 satisfied, because $-
\Delta x + |
\Delta x| =
0$.
471 The inequality constraint can equivalently be formulated for $
\Delta y$,
475 0 \leq 1-
\Delta y
\pm^
2 \sqrt{1+
\Delta y+
\Delta y^
2} \leq -
3\Delta y &
\quad\text{if $
\Delta y <
0$ (or $a_y >
0$)
} \\
476 0 \leq \Delta y-
1 \mp^
2 \sqrt{1+
\Delta y+
\Delta y^
2} \leq 3\Delta y &
\quad\text{if $
\Delta y >
0$ (or $a_y <
0$)
}
480 In the first line, the comparison with~$
0$ is always true. In the right
481 comparison, the lower sign is always possible and does not yield a constraint,
482 whereas the upper sign is only possible for $
\Delta y
\leq -
1$. In the second
483 line, the upper sign is incompatible with the left comparison, and the lower
484 sign is always possible. We can reduce the conditions to
489 \text{no constraint
} &
\quad\text{if $
\Delta y
\leq -
1$
} \\
490 \text{only the lower sign of $
\pm^
2$ is allowed
} &
\quad\text{if $
\Delta y > -
1$
} \\
495 Equation~
\eqref{samet2
} with the two constraints
\eqref{constr1
} and
496 \eqref{constr2
} is the system of equations that gives us the values $
\Delta x,
497 \Delta y$ for which the parametrisation could be invalid.
499 First, let us check that the classic case for a cusp is well described. It has
500 $
\Delta x=-
1,
\Delta y=
0$. We have no constraint on $x$, and we have to take the
501 lower sign on $y$. Indeed, the left-hand side of eq.~
\eqref{samet2
} vanishes due
502 for the lower sign, and the right one vanishes also for the lower sign. This
503 case is shown among the examples in figure~
\ref{fig:invalid3
}.
508 \includegraphics{invalid2
}%
509 \caption{Absolute value of the difference between left- and right-hand side of
510 eq.~
\eqref{samet2
}. The dotted lines are given by eqs.~
\eqref{leftcurve
} and
511 \eqref{rightcurve
}.
}%
512 \label{fig:invalid2
}%
517 \includegraphics{invalid3
}%
518 \caption{Some examples of invalid parametrisations from the general
519 (non-degenerate) case described by eqs.~
\eqref{samet2
},
\eqref{constr1
},
521 \label{fig:invalid3
}%
524 Figure~
\ref{fig:invalid2
} shows the difference between left- and right-hand side
525 of Eq.~
\eqref{samet2
} for all valid signs, respecting the constraints. The
526 horizontal and vertical lines are those special cases where $a_x=
0$ or $a_y=
0$
527 and need further considerations. The zero-level curve at $
\Delta x <
0$ (dotted
528 curve in the figure) is well described by the equation
532 \Delta x =
\frac{1}{3}\Bigl(-
1-
2\Delta y -
\sqrt{(
2\Delta y+
1)^
2 +
3}\Bigr)
535 which is obtained by taking the upper sign of $
\pm^
1$ in eq.~
\eqref{samet2
}:
536 With negative values of $
\Delta x$ the left-hand side becomes $
6\Delta x
\Delta
537 y$. Isolating the square-root and then taking the square leads to a quadratic
538 equation for $
\Delta x$, of which eq.~
\eqref{leftcurve
} is the negative
539 solution. A numerical check shows that this solution corresponds to the lower
540 sign of $
\pm^
2$ and has thus no restriction in $
\Delta y$. The second solution
541 (dotted curve in the figure for $
\Delta x>
0$) of the mentioned quadratic
546 \Delta x =
\frac{1}{3}\Bigl(-
1-
2\Delta y +
\sqrt{(
2\Delta y+
1)^
2 +
3}\Bigr)
549 corresponds to the upper sign of $
\pm^
2$ and is thus subject to the constraint
550 \hbox{$
\Delta y
\leq -
1$
}.
552 Apart from the general cases on the two curves, we must treat some special cases
556 \item $a_y=
0$: This appears as a zero-level line in figure~
\ref{fig:invalid2
},
557 but this is an artefact coming from both sides of eq.~
\eqref{samet2
} being
558 zero. We have to go back to the original set of
559 equations~
\eqref{zeroderiv
}: We have in the lower line $
\Delta y=
0$, thus
560 $t=
1/
2$. Going back to the upper line with this value, we obtain $
\Delta
561 x=-
1$. This parameter point is already covered by the general treatment.
562 \item $a_x=
0$: This implies $
\Delta x=
1/
3$, and the upper line gives $t=
0$.
563 This, however, contradicts the lower line. We do not get an invalid
564 parametrisation point from $a_x=
0$.
565 \item $p_1=p_0$: This is either an even more degenerate case (see below), or it
566 can be mapped to the reverse situation of $
\Delta x=
1,
\Delta y=-
1$ which
568 \item $p_1=p_0$ and $p_2=p_3$: This is a line.
569 \item $p_3=p_0$: There are invalid parametrisation points if all four
570 $p_0,p_1,p_2,p_3$ are collinear. Depending on the sign of
571 $(p_1-p_0)
\cdot(p_3-p_2)$ there are one or two invalid points.
572 \item $p_1=p_0=p_2=p_3$: This is a point.
577 \section{Self-intersections
}
580 In order to determine the control points which lead to self-intersections, we
581 could analyse the set of equations
584 x(t_1) = x(t_2)
\quad\text{and
}\quad
585 y(t_1) = y(t_2)
\quad\text{for
}\quad t_1
\neq t_2.
588 To solve the problem, we could express the solutions $t(
\Delta x,
\bar x)$ of
589 the cubic equation $
\bar x = x(t)$, test their number via Cardano's equation,
590 and, if they are more than one, use a pair of them in the $y$-equation to see
591 whether we get two times the same $y$-value. This would be a formidable task.
593 We here take a different route. As for the invalid parametrisation above, we
594 exclude some degenerate cases and use affine transformations, such that only the
595 parameters $
\Delta x=x_2$ and $
\Delta y=y_2-
1$ are left. It is geometrically
596 evident that a little left and right of the two relevant curves in
597 figure~
\ref{fig:invalid2
} we must have different situations as far as
598 self-intersections are concerned. Either we find one a little left or a little
599 right of the curves, and none on the respective other side. Further, a
600 self-intersection can clear away when parameters change such that the curve
601 passes through one of its endpoints. These two conditions boil down to the phase
602 diagram in figure~
\ref{fig:selfinter2
}. In the gray shaded areas,
603 self-intersections are possible.
606 \includegraphics{selfinter2
}%
607 \caption{Self-intersections are possible in the gray-shaded areas. The black,
608 red, green, blue curves are from eqs.~
\eqref{leftcurve
},
\eqref{rightcurve
},
609 \eqref{pass00
},
\eqref{pass10
}, respectively.
}%
610 \label{fig:selfinter2
}%
614 We first calculate the parameters $
0<t<t$ for which the curve passes through
615 $(
0,
0)$. The $x$-coordinate leads to $t=
3\Delta x/(
3\Delta x -
1)$, and the
616 $y$-coordinate to $t=-
1/
\Delta y$. From the latter we know that again $
\Delta
617 y
\leq 1$. Setting both parameters equal allows to express $
\Delta x(
\Delta y)$
622 \Delta x &=
\frac{1}{3(
\Delta y+
1)
} \\
623 \Delta y &=
\frac{1-
3\Delta x
}{3\Delta x
}
627 The calculation for passing through $(
1,
0)$ is a little more complicated, since
628 the cubic equation for $x$ (which had a double root at $t=
0$ before) now reads
629 $
0 =
3\Delta xt^
2(
1-t) + t^
3 -
1$. The equation for~$y$ has not changed and
630 leads to the same solution with the same constraint. Using $t=-
1/
\Delta y$ in
631 the cubic equation for $x$ leads us to
635 \Delta x &=
\frac{1+
\Delta y^
3}{3(
\Delta y+
1)
}.
640 \section{Removing cusps
}
642 A cusp is a point on a B\'ezier curve $
\vec b(t)$, where
643 $
\mathrm{d
}\vec b(t)/
\mathrm{d
}t=
\dot{\vec b
}(t)$ vanishs.
644 For stability we don't want it to be almost zero either.
645 For comparison, a straight line
646 $
\vec l(t)=
\vec p_0 + (
\vec p_3-
\vec p_0)t$ has the constant derivative
647 $
\mathrm{d
}\vec l(t)/
\mathrm{d
}t =
\dot{\vec l
}(t) =
\vec p_3-
\vec p_0$.
648 As lines shorter than $
\epsilon$ are forbidden, we have
649 $|
\dot{\vec l
}(t)|
\ge \epsilon$. We want to enforce
650 this limit to B\'ezier curves as well,
\emph{i.e.
}
651 $|
\dot{\vec b
}(t)|
\ge \epsilon$.
653 First we have to take into account the beginning ($t=
0$) and end point
654 ($t=
1$) of the B\'ezier curve. Here, the derivates are given by
655 $
\dot{\vec b
}(
0) =
3(
\vec p_1-
\vec p_0)$ and
656 $
\dot{\vec b
}(
1) =
3(
\vec p_3-
\vec p_2)$. In case the absolute value
657 of the derivatives are smaller than $
\epsilon$, we need to shift
658 $
\vec p_1$ and $
\vec p_2$, respectively. For $
\vec p_1$ a new value is
659 choosen in the direction of $
\vec p_2$ with respect to $
\vec p_0$ if
660 $
\vec p_2$ is more distant than $
\epsilon/
3$, otherwise the direction
661 of $
\vec p_3$ is used. The distance of the new point is choosen such
662 that the absolute value of the derivate becomes $
\epsilon$. $
\vec p_2$
663 is shifted similarly using the unshifted position for $
\vec p_1$.
665 Once the derivatives at the boundary fulfil the requirement, we need
666 to search for minimal values of the absolute value (or the square) of
667 the derivate within the valid parameter range. If the absolute value
668 is smaller at an extrema, the curve is split at that point.
671 % vim:foldmethod=marker:foldmarker=<<<,>>>