A Computational Method with Maple for Finding the Maximum Curvature of a Bézier-Spline Curve

: In this paper, we propose two Maple procedures and some related utilities to determine the maximum curvature of a cubic Bézier-spline curve that interpolates an ordered set of points in R 2 or R 3 . The procedures are designed from closed-form formulas for such open and closed curves


Introduction
We recall here the definition of curvature of a smooth curve.This is a fundamental concept in differential geometry that has been studied deeply in applied mathematics, engineering, and computer graphics.The problem of finding the curvature extremum has been investigated by many authors.We can point out some of their results on establishing necessary and sufficient conditions for the regularity of offset curves or tubular surfaces, designing various types of aesthetic curves from constrained conditions, representing and modifying curves to adapt principles of interpolation and animation, etc.In the following, we give a short description of the method for solving this problem and its limitations.
If r : [a, b] −→ R 3 is the position vector of a smooth curve L , then the point r(t) of L at t ∈ [a, b] is written as a 3-tuple (x(t), y(t), z(t)), or a column vector x(t), y(t), z(t) = (x(t), y(t), z(t)) T when used in a matrix expression; hence r(t) T is the row matrix x(t) y(t) z (t) .The image of r or the map r itself is called a parametrization of L .Along L , we consider the coordinates of the Frenet frame { T, N, B} whose origin is located at points of L .From differential geometry and calculus (see [1,2]), we know that where v(t) = r (t) = (x (t), y (t), z (t)) T and a(t) = r (t) = (x (t), y (t), z (t)) T are usually called the velocity vector and the acceleration vector of L at t (or at r(t)).
Let r = r(t) = (x(t), y(t), z(t)) T be a parametrization of a smooth space curve L with a = r ∈ C([a, b]).Then, the curvature of L at t is given by where v = v(t) = r (t), a = a(t) = r (t), and v = v(t) .Under this assumption, we usually find the maximum value of κ(t) on [a, b] by choosing the largest value of κ at the points where κ (t) = 0.However, how to solve the equation κ (t) = 0 exactly or approximately?In general, we cannot do it.Moreover, apart from this, the expression for κ (t) is complicated!Let us take K = κ 2 and write it out in the components of v × a.This gives K = (y z − z y ) 2 + (z x − x z ) 2 + (x y − y x ) 2 [(x ) 2 + (y ) 2 + (z ) 2 ] 3 .
On the other hand, if r = r(s) is the parametrization of L by the arc length s, then from the relation T (s) = κ(s) N(s) we obtain T (s) = κ (s) N(s) + κ(s) N (s).
This gives a simple expression for κ (s): However, we again encounter another hard problem: how to convert a parametrization of a smooth space curve L by a general parameter t into the parametrization by the arc length s.In general, this is impossible.
To overcome those obstacles, many researchers restricted their attention to the class of Bézier curves and their variants.Recently, the papers related to maximizing or minimizing the curvature of these curves provided a lot of theoretical results and useful algorithms, as well as practical tools.We highlight some representative papers with a brief note.Ref. [3] presents a unique design on a piecewise quadratic Bézier curve that interpolates its local maximum curvature points that are also its control points.Ref. [4], adopted from [3], proposes new methods to modify local curvature at the interpolation points by taking basis functions of higher degree.Ref. [5] provides conditions for the curvature of a quadratic rational Bézier curve to be monotone or to have a local minimum and maximum.Ref. [6] establishes conditions for Bézier plane curves generated by a matrix to have monotone curvature.Ref. [7] also establishes conditions for Bézier curves to have monotone curvature, based on control points of the position vector of the curve and its derivatives.Ref.
[8] treats typical Bézier plane curves with one curvature extremum that can be easily calculated, which can help to divide the curve into two typical curves with monotone curvature.
Traditionally, the papers noted above and many others paid much attention to control points and polygons.Actually, these objects have direct effects on the shape of the curves, so they have been modified in order to obtain a curve with properties needed in design applications.However, we have some changes in mind when relating this widespread trend to our result in [9].The formula in [9] (Theorem 3.1) can be seen as a way of approximation by interpolation with Bézier-spline curves.Therefore, we prefer to place emphasis on interpolated points.These points can be chosen in a way to design curves in R 2 or R 3 with desired shapes or can be taken from special partitions of the parameter interval of a smooth curve with given parametrization to approximate its curvature extremum.Now, we go back to our main purpose: making a Maple procedure to compute the maximum value κ max of the curvature.We restrict our attention to Bézier-spline curves.This objective is based on the power of Maple on symbolic computation and on solving polynomial equations of high degree and on the explicit piecewise cubic parametrization of these special curves.
The present paper is organized as follows.In Section 2, we construct the Maple procedures to represent Bézier-spline space curves for both open and closed curves.In Section 3, we propose a pseudo-algorithm for computing κ max , then we provide the full code of the procedures corresponding to the algorithm.In Section 4, we discuss some modifications to obtain procedures to represent Bézier-spline plane curves and to compute their maximum curvature.In Section 5, we give some concluding remarks.

Bézier-Spline Space Curves with Maple Parametrization
In this section, we consider a Bézier-spline curve, which is obtained from a closed-form solution to the inverse problem, which interpolates an ordered set of points s 0 , s 1 , . . ., s n , given in [9].Such a plane curve can be obviously extended to a space curve C given by a piecewise cubic function f of C 2 ([0, n]).According to the construction of such curves in [9], we present here a more convenient way to derive their parametrization.
First, f(t) is composed of the cubic functions f k given by where k = 1, . . ., n and t ∈ [0, 1], and f k is the parametrization of the cubic Bézier curve C k with the control points s k−1 , p k−1 , q k , and s k .These points satisfy the known relations and On the other hand, from [9] (Theorem 3.1), the points b k , s k , k = 0, . . ., n, are now in R 3 with b 0 = s 0 and b n = s n , and for k = 1, . . ., n − 1, we have where β k (k = 0, . . ., n − 1) is evaluated by the formula Finally, we can give a simple process to obtain a so-called relaxed, uniform B-spline space curve C that interpolates an ordered set of points s 0 , s 1 , . . ., s n (see [10]).The parametrization f of C is a piecewise cubic function on [0, n] whose components f k , k = 1, . . ., n, derived from ( 2) and (3), can be now given by where the curvatures of C at t = 0 and t = n are both zero and we call C a relaxed Bézier-spline space curve.
We are interested in the implementation of the above parametrization by a Maple procedure.We list here some Maple commands that will appear in our procedures.They are all very important and frequently used in graphic and computation programming: args, nargs, op, nops, ERROR, RETURN, convert, evalf, diff, expand, floor, for, fsolve, map, max, min, piecewise, plot, plot3d, proc, seq, solve, unapply, and while; in addition, LinearAlgebra and plots are the great packages containing many procedures for specific purposes.A declaration to create a function, e.g., f, such as f:=x->F(x) or f:=unapply(F(x),x) (sub-procedures in F(x) are evaluated first), where F(x) is an expression or a list of expressions in x, is a very useful and convenient tool.In addition, the conditional structures if-then-else and if-then-elif-else are indispensable in branch programming, whereas the type "list" is a flexible ordered arrangement of operands (or components, elements) inside the square brackets [, ].See [11,12] and Maple help pages in each session to know more details about meaning, syntax, and usage of these commands, structures, and types.The implementation of some specific task by calling a procedure name together with appropriate arguments is usually said to be a calling sequence.As a convention, we choose type list for elements of R 2 or R 3 .Now, let us make a procedure to compute f(t) on [0, n] from ( 5)-( 7), with b 0 = s 0 and b n = s n .It takes S = {s 0 , s 1 , . . ., s n } as its input and gives f(t) as its output in the form of [F(t), G(t), H(t)] such that F, G, H are the piecewise functions in t on [0, n].This procedure is called BScurve3d and its full code is given in the following.
If we have an ordered set of (n + 1) distinct points in R 3 that are declared in Maple as a list of lists then we can obtain the position vector of the Bézier-spline curve C that interpolates these points by calling f:=BScurve3d(S).The plot of C can be made by the procedure spacecurve in the plots package with the command plots[spacecurve](f(t),t=0..n,opts); The 'opts' means plotting options.To implement these steps, for instance, we set and f := BScurve3d(L).Then, the plot of the Bézier-spline curve C that interpolates L is given by the calling sequence plots[spacecurve](f(t),t = 0..7,opts); Figure 1 shows the curve C and the points of L. We take one more example of interpolating an ordered set of points on a given space curve to see how well a Bézier-spline curve fits this curve.Let L 1 be a curve whose parametrization is r(t) = (t cos t, 0.8t sin t, t cos t − sin t) T , t ∈ [−2.4,5], with the declaration r := t->[t*cos(t),(0.8)*t*sin(t),t*cos(t)-sin(t)]: Consider a partition of [−2.4,5] by the points t 0 := −2.4,t 1 := −1.2, t 2 := 0.0, t 3 := 1.4, t 4 := 2.7, t 5 := 3.8, t 6 := 5.0, and set L 1 := [r(t 0 ),r(t 1 ),...,r(t 6 )]: The curve L 1 and its approximation by a Bézier-spline curve C 1 are also given in Figure 1.The Bézierspline curve C 1 (in red) interpolates the data points r(t 0 ), r(t 1 ), . . ., r(t 6 ) on the curve L 1 (in cyan).opts: axes=boxed, numpoints=2000, thickness=2, scaling=constrained.
We will make some changes to obtain a so-called closed, uniform B-spline space curve C that interpolates an ordered set of points s 0 , s 1 , . . ., s n , with s n = s 0 (see [10]).We call such a curve a closed Bézier-spline space curve.In this case, we choose appropriate settings to have again the relations (3) and (4) at the common point.The first setting should be b n = b 0 .Then, C is still composed of the cubic Bézier curves C k , k = 1, . . ., n, as above.Specifically, at the interpolated point s n = s 0 , (4) becomes where we have from (3) that Now, from (8) and ( 9), we get the last setting It is easy to have another Maple procedure, say BScurve3dC, for representing a closed Bézier-spline space curve C from the dataset {s 0 , s 1 , . . ., s n } with s n = s 0 , and the settings (10) and b n = b 0 .From the above discussion, the parametrization f of C has the components f k given by ( 7), and we can check that Therefore, f is in C 2 ([0, n]) again and C 1 , C n have the same curvature at their common point.
Let us take some examples on using BScurve3dC.As the steps to display closed Bézierspline space curves are the same as for BScurve3d, we just give the graphical results of these examples.Note that the initial and terminal points of the input list for BScurve3dC have to be the same.Let L be the list The display of the closed Bézier-spline curve C L that interpolates L is given in Figure 2. Let r be the parametrization of a closed space curve L called a trefoil knot (see [1]  In Figure 2, we also give the display of L together with its approximation C T that interpolates T.

Computation of the Maximum Curvature of a Bézier-Spline Curve
Let C be a Bézier-spline curve that interpolates an ordered set T of points s 0 , s 1 , . . ., s n in R 3 .Then r(t), the position vector of C , is a piecewise cubic function of C 2 ([0, n]), given by its components f k (t) in (7).
Avoiding the square root function, we have from (1): 3  .
Then, we have that 4  .
As κ attains its maximum value on [0, n] only at solutions of the equation K = 0 or in the intervals (i − 1, i) and at their endpoints i − 1, i, with i = 1, . . ., n, we can find κ max on [0, n] by the procedure MaxCurvature3d.However, at first, we present the procedure in the form of a pseudo-code algorithm.It would be easy to translate statements in such algorithms into Maple codes or other programming languages.Moreover, our discussion on how to use appropriate commands for a specific purpose will give a clear description of our procedures.In addition, we sometimes use built-in Maple procedures in those algorithms with their most simple form for convenience and simplicity.Note that the left-hand side of ( 11) is a polynomial of degree at most 7. Letting Q be such a polynomial (in one variable, say, t), we will use a powerful tool of Maple to find numerically all the zeros of Q in a given interval.That is the procedure fsolve and it has been called in Algorithm 1 by the command: fsolve(Q,t,α..β).The output of this calling is a sequence of all real zeros of Q in [α, β].Moreover, the expressions of dot and cross products are given by the great package of Maple: LinearAlgebra.We also select points in [0, n] at which κ attains its maximum value.Thus, the output of Algorithm 1 consists of κ max and the set κ −1 (κ max ) in [0, n].Now, for relaxed Bézier-spline curves, we give the full code of MaxCurvature3d at the end of this section.
We use MaxCurvature3d to determine κ max in the examples whose graphical results are given in Figure 1.From the lists L and L 1 in these examples, the calling sequences MaxCurvature3d(L) and MaxCurvature3d(L 1 ) result in 11.87724489, {2.913967861} and 3.135008280, {2}, The new version of MaxCurvature3d for closed Bézier-spline curves, say, MaxCurva-ture3dC, can be derived easily from Algorithm 1 with the modification "f i from BScurve3dC".Then, we use MaxCurvature3dC to find κ max of C L displayed in Figure 2 and we obtain the result 1.652746390, {1.979287163}.To avoid a comparison error between fractions and decimal numbers, we may use the decimal point '.' for at least one component of the points in the list argument of MaxCurvature3d.Note that the result of fsolve only contains decimal numbers, so it will give us '2.', for instance, if it contains the integer '2'.To cover this case, we add a condition such as 'A − B = 0.' in the definition of MaxCurvature3d, and it should be sometimes '|A − B| < 10 −m ' with some positive integer m when we need to obtain an expected result.

Remarks on the Two-Dimensional Case
For a relaxed Bézier-spline plane curve L that interpolates a dataset M of points s 0 , s 1 , . . . ,s n in R 2 , we have already a procedure to obtain its position vector f(t).That is just removing the lines H:=t->• • • and modifying the lines RETURN(t->[F(t),G(t),H(t)]) to RETURN(t->[F(t),G(t)]) in BScurve3d, and the remaining part is for BScurve2d, the Maple parametrization of L .Maple provides the plot procedure to display plane curves with their parametrization [x(t), y(t)], t ∈ [a, b], by the declaration plot([x(t),y(t),t = a..b],opts); Accordingly, we first set f := BScurve2d(M), then we call plot([op(f(t)),t = 0..n],opts); or plot([f(t)[],t = 0..n],opts); to display L .Similarly, we get BScurve2dC, the new version of BScurve2d for closed Bézier-spline plane curves, from BScurve3dC.
MaxCurvature3d can be modified to use only sets of points in R 2 and we call its new version MaxCurvature2d.Let L be a smooth plane curve with parametrization r.From the formula κ(s) = T (s) • N(s) with arc length parameter s, we can write for a general parameter t, where We also consider 3 and derive the following equation from This equation has the same role as (11), so we can make a new version of MaxCurvature3d, say, MaxCurvature2d, following the steps in Algorithm 1 with some modification: there is no cross product in this version.The expression of the local variable Q in the definition of MaxCurvature2d is given by the left-hand side of (12).Note that the function F i in the pseudo-code algorithm of MaxCurvature2d is now In the definition of MaxCurvature2d, the matrix J is declared at right above Sp:={} by J:=Matrix(2,2,[0,-1,1,0]): and, then, we set U:=J.V inside the for loop at right below.
We give two more examples on getting the maximum curvature of a relaxed Bézierspline plane curve and its maximum curvature points.Let M be the list and C be the Bézier-spline curve that interpolates M.Then, we obtain the parametrization of C by setting f := BScurve2d(M).
The curves C A and C B that interpolate A and B, respectively, are given in Figure 5.The shapes of C A and C B can already be seen if we first display the interpolated points on the plane.In the last two examples, we compute the maximum curvature of two closed Bézierspline curves and show the maximum curvature points on these curves.The results are given in Figure 6.The interpolated points (on the right) in Figure 6 are chosen on the ellipse x 2 /9 + y 2 /4 = 1 (depicted in cyan).We sometimes want to compute the curvature of a Bézier-spline curve at a p ∈ [0, n], so we should have a tool to do that.Algorithm 2 can be used to make such a tool.Algorithm 2 Finding the curvature of a Bézier-spline curve at its given point Input: a set T of (n + 1) points in R 2 , a point p ∈ [0, n]; Output: The curvature κ at p of the Bézier-spline curve interpolating T; 1: if p = n then 2: i := n; 3: else 4: i := p + 1; 5: end if 6: v := f i (t), a := f i (t) // f i from BScurve2d or BScurve2dC; It is easy to derive the Maple procedure from Algorithm 2 that we call Curvature2d or Curvature2dC, depending on whether f i is from BScurve2d or from BScurve2dC.Similarly, the extension of this procedure for the three-dimensional case can be obtained with the curvature function from Algorithm 1.

Conclusions
Our procedures may also be convenient tools for non-Maple users to estimate the maximum curvature of parametric smooth curves and to approximate a curve from its interpolated points by a Bézier-spline curve, as similarly done in [13][14][15][16].They could be used for doing calculations to establish conditions for non-singularity of tubular surfaces and offset curves associated to a Bézier-spline curve, according to the issues profoundly presented in [17,18].Moreover, our parametrization derived from the closed-form solution to a linear system for the interpolation problem would be better than those derived from the existing direct or iterative methods to solve the system, as noted in [19,20].

Figure 2 .
Figure 2. On the (left): The closed Bézier-spline curve C L interpolates the list L. On the (right): The closed Bézier-spline curve C T (in red) interpolates the set T of points on the curve L (in cyan).
Let g be the parametrization of C L .The point g(1.979287163)= [−2.02583824,−0.094336298, −4.99371046] is given in Figure 3 and this maximum point of curvature of C L is very close to the interpolated point [−2, 0, −5].

Figure 3 .
Figure 3.The value of κ max = 1.652746390 is attained at the blue point on C L .

Figure 4 .
Figure 4. On the (left): The Bézier-spline curve C interpolates the dataset M. On the (right): The Bézier-spline curve C 1 (in red) interpolates the set N of points on L (in cyan).The red points A and B are the points of maximum curvature of C and C 1 , respectively.