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
325 % vim:foldmethod=marker:foldmarker=<<<,>>>