scieee AI-readable full text Open interactive document viewer

Accurate evaluation of Bézier curves and surfaces and the Bernstein-Fourier algorithm

Delgado, J.; Peña, J.M.

Abstract

The Bernstein-Fourier algorithm for the evaluation of polynomial curves is extended for the evaluation of polynomial tensor product surfaces. Under a natural hypothesis, accurate evaluation of Bézier curves and surfaces through several algorithms is discussed. Numerical experiments comparing the accuracy of the corresponding Horner, de Casteljau, VS and Bernstein-Fourier algorithms are presented. Delgado, J.; Peña, J.M.

Full text

Accurate evaluation of B´ezier curves and surfaces and the Bernstein-Fourier algorithm Jorge Delgado bJ. M. Pe˜na a aDepartamento de Matem´atica Aplicada, Universidad de Zaragoza, Spain bDepartamento de Matem´atica Aplicada, Universidad de Zaragoza, Spain Email address: [email protected]; Phone number: +34978618174 Abstract The Bernstein-Fourier algorithm for the evaluation of polynomial curves is extended for the evaluation of polynomial tensor product surfaces. Under a natural hypothesis, accurate evaluation of B´ezier curves and surfaces through several algorithms is discussed. Numerical experiments comparing the accuracy of the corresponding Horner, de Casteljau, VS and Bernstein-Fourier algorithms are presented. Key words: B´ezier curves and surfaces; Bernstein-Fourier algorithm; polynomial evaluation 1 Introduction In [2] L. H. Bezerra introduced a new method to evaluate B´ezier polynomials, that is, polynomials of the form p(t) = k X i=0 cibk i(t), t ∈[0,1],(1) where the polynomials bk i(s) = k isi(1 −s)k−iare known as Bernstein basis polynomials of degree k(k≥0). The new method is based on using a so-called Bernstein-Fourier representation. So, from now on, we will call Bernstein- Fourier algorithm to the new algorithm. The author also carried out numerical experiments in order to check the performance of the new method with respect to computational cost and accuracy. In addition, a comparison of these two aspects, in particular the computational cost, of the new method with respect to the usual de Casteljau and VS algorithms for the evaluation of B´ezier curves was also performed. Assuming positive control points, the numerical experiments with the three algorithms were accurate. Preprint submitted to Elsevier 27 July 2015 In [4] and [7] some of the most usual algorithms for the evaluation of polynomial curves were compared from the point of view of accuracy. In this paper we complete the numerical experiments in [2], [4] and [7] comparing the de Casteljau algorithm, the VS, the Horner and the Bernstein-Fourier algorithms. We also explain the theoretical reasons for expecting accuracy for the numerical experiments of [2] when using VS and de Casteljau algorithms. In addition, we will carry out the generalization of the Bernstein-Fourier algorithm for the evaluation of B´ezier tensor product surfaces and then we will compare it numerically with the corresponding versions for tensor products of the de Casteljau, the VS and the Horner algorithms. In Section 2, de Casteljau and VS algorithms are recalled. It is also justified why many algorithms in Computer Aided Design evaluate polynomial curves to high relative accuracy under the natural hypothesis (in this field) of starting with positive control points. In Section 3, we consider ill-conditioned polynomials to compare univariate Horner, de Casteljau, VS and Bernstein-Fourier algorithms. In Section 4, evaluation algorithms for polynomial tensor product surfaces are derived and their high relative accuracy is discussed. We particularize the cases of Bernstein-Fourier, de Casteljau and VS algorithms. Section 5 presents numerical examples in order to compare the algorithms. 2 Accuracy in C.A.G.D. In [2] L. H. Bezerra performed the numerical experiments assuming that all control points are positive. This assumption avoided ill-conditioned polynomials. In this section, we shall show that this is a natural assumption in Computer Aided Geometric Design (from now on, C.A.G.D.) and that it permits to assure high relative precision for the evaluation through a large family of representations in C.A.G.D. We say that we know a quantity with high relative accuracy if its relative error is bounded by O(ε), where εis the machine precision. Given an algebraic expression defined by additions, subtractions, multiplications and divisions and assuming that each initial real datum is known to high relative accuracy, then it is well known that the algebraic expression can be computed accurately if it is defined by sums of numbers of the same sign, products and quotients (cf. p. 52 of [8]). In other words, the only forbidden operation is true subtraction, due to possible cancellation in leading digits. Moreover, in a (well-implemented) floating point arithmetic high relative accuracy is also preserved even when we perform true subtractions when the operands are original (and so, exact) data (cf. p. 53 of [8]). Let us recall that the VS algorithm evaluates polynomials of degree nrepre- 2 sented in the form p(t) = n X i=0 citi(1 −t)n−i, t ∈[0,1],(2) with a computational cost of 2n−1 products, 2n−1 additions and 1 quotient. This algorithm has a nested nature like Horner and was introduced for bivariate triangular polynomials in [10]. In fact, taking into account that p(t) = n X i=0 citi(1 −t)n−i=tn n X i=0 ci1−t tn−i = (1 −t)n n X i=0 cit 1−tn−i , VS algorithm computes p(t) applying Horner algorithm at points 1−t t(if t≥ 1/2) or t 1−t(if t < 1/2), and then multiplying the obtained result by tnor (1 −t)n, respectively. For more details in the algorithm see for example [7]. Observe that Horner algorithm and VS algorithm can be computed accurately when the control points are positive. The same conclusion holds for the de Casteljau algorithm and, more generally, for corner cutting algorithms as we shall show in the following paragraphs. In C.A.G.D., given a system of functions (u0, . . . , un) defined on a compact interval I= [a, b], and points P0, . . . , Pn∈Rs, a parametric curve γis defined by: γ(t) = n X i=0 ui(t)Pi.(3) The points are called control points of γ, and the polygon P0· · · Pnis called control polygon of γ. We now recall an important family of systems in C.A.G.D. called corner cutting systems in [5]. Let us denote by Λi(t) the bidiagonal matrix           1−λ(i) 0(t)λ(i) 0(t) ...... ...... 1−λ(i) i−1(t)λ(i) i−1(t)           (4) for all i∈ {1, . . . , n}, where λ(i) j: [a, b]→[0,1] for 0 ≤j < i ≤n. We say that Λ1(t)· · · Λn(t) is a corner cutting representation on [a, b] of the system of functions (u0, . . . , un) defined on [a, b] if (u0(t), . . . , un(t)) = Λ1(t)· · · Λn(t),(5) where the matrices Λi(t) are given by (4) for all i∈ {1, . . . , n}and the functions λ(i) j: [a, b]→[0,1] are continuous and increasing for all 0 ≤j < i ≤n (and are called cutting functions). A system of functions admitting a corner cutting representation on [a, b] will be called a corner cutting system on [a, b]. 3 By (5), any function f(t) = n X i=0 ciui(t) (6) can be evaluated by the corner cutting algorithm provided by Λ1(t)· · · Λn(t)(c0, . . . , cn)T=f(t).(7) In fact, the evaluation of the curve given in (3) can be reduced, componentwise, to sevaluations as in (6). Let us also denote by (Rs)+the set of points of Rssuch that all their components are positive (for instance, if s= 3, then (Rs)+is the positive octant). Observe that, for design purposes, in order to draw any curve, we can take all control points belonging to (Rs)+. So, if we can calculate accurately λ(i) j(t) and 1 −λ(i) j(t) for all i, j, then we also can perform accurately the evaluation of each component of the parametric curve γ(3) through the corner cutting algorithm given by (7) because we are always multiplying nonnegative numbers and summing nonnegative numbers. Due to the arguments of the previous paragraphs, we deduce that the following evaluation algorithms of polynomial curves (of degree n) can be performed with high relative accuracy when all control points belong to (Rs)+. Observe that all satisfy that the cutting functions λ(i) j(t) are either a nonnegative constant or the given parameter t(and so each 1 −λ(i) j(t) can also be computed accurately because it is a subtraction of two exact data): •The de Casteljau algorithm, which uses λ(i) j(t) = tfor all i, j. It is associated to the Bernstein basis and is the most usual algorithm for the evaluation of B´ezier curves. It evaluates a polynomial B´ezier curve of degree kwith a computational cost of O(k2) elementary operations. The best well known evaluation algorithm is the Horner algorithm, which evaluates a kdegree polynomial with a computational cost of O(k) elementary operations in contrast to the O(k2) computational cost of de Casteljau. So in the last years two more efficient alternatives to the de Casteljau algorithm have been researched in the literature. These alternatives are VS algorithm and Bernstein-Fourier algorithm. •The evaluation algorithm of the Wang-Ball basis, which uses (cf. [11]) λ(i) j(t) = 0,for j∈0, . . . , i−3 2,(8) λ(i) j(t) = t , for j∈i−1 2,i 2,(9) λ(i) j(t) = 1,for j∈i 2+ 1, . . . , i −1,(10) where [r] denotes the greatest positive integer less than or equal to r. •The evaluation algorithm of the basis introduced in [3] and called DP basis (cf. [9]), which uses 4 λ(i) 0(t) = λ(i) i−1(t) = t , (11) λ(i) j(t) = 1, j = 1, . . . , i 2−1,(12) λ(i) j(t) = 0, j =i+ 1 2, . . . , i −2,(13) and, in addition, if i≥3 is odd, λ(i) i−1 2 (t) = 1 2. •The evaluation algorithm of the pruned curves (see [1]), which also use λ(i) j(t) = tor λ(i) j(t) = 1 or λ(i) j(t) = 0. The extension of the evaluation algorithms for B´ezier curves to the evaluation algorithms considered in Section 4 for B´ezier surfaces inherits the accuracy under positive control points. Therefore, from now on, we shall focus on numerical examples with ill-condioned polynomials and whose coefficients are not necessarily positive, in the univariate as well as in the bivariate case. 3 Numerical examples with ill-conditioned univariate polynomials First we shall compare the Bernstein-Fourier algorithm of [2] (see the tensor product version in Section 4) for the evaluation of polynomial curves with the de Casteljau, the VS and the Horner algorithms. In [12] and [13] Wilkinson considered the following two ill-conditioned polynomials: f(t) = 20 Y i=1 t−i 20and g(t) = 20 Y i=1 t−2 2i. We have computed, using Mathematica with infinite precision, the exact coefficients of both polynomials with respect to the Bernstein basis and the monomial basis. Then we have evaluated both polynomials f(t) and g(t) by using the four algorithms with the standard IEEE 754 double precision arithmetic at the points of the sequences given by U:= {1 72 +i 36 }35 i=0 and V={i 39 }38 i=1, respectively. Finally, we have obtained the exact values of both polynomials at the points of the two meshes by symbolic computation, and the corresponding relative and absolute errors for the four algorithms. The relative errors when evaluating fand gare shown in Figure 1 (a) and (b), respectively. On the other hand, the absoute errors are shown in Figure 2 (a) and (b). As we can see the absolute errors for the four algorithms are low but, since the values of the Wilkinson polynomials in [0,1] are small numbers, not all algorithms yield low relative errors. In particular, we can observe that the Horner algorithm has less accuracy than the other algorithms for the polynomial f(t) and that the Bernstein-Fourier algorithm has less accuracy than the other algorithms for the polynomial g(t). 5 Finally, for comparing the four algorithms for the evaluation of polynomials we have considered the following ill-conditioned polynomial: h(t) = t−1 220 . We have repeated the same process than for polynomials fand g, but now at the points of the mesh n4i 100 o24 i=1. We have obtained the relative errors and the absolute errors shown in Figures 3 and 4, respectively. We can observe that, in this case, the algorithm with a good behaviour everywhere is the de Casteljau algorithm. 4 Evaluation of tensor product surfaces Let us consider a sequence (Pij)0≤j≤n 0≤i≤mof points in the space. Then a tensor product B´ezier surface is defined as F(x, y) = m X i=0 n X j=0 Pijbm i(x)bn j(y).(14) Since F(x, y) = m X i=0 n X j=0 Pijbm i(x)bn j(y) = m X i=0 ( n X j=0 Pijbn j(y))bm i(x) and denoting fi(y) := Pn j=0 Pijbn j(y), for i= 0,1, . . . , m, we have F(x, y) = m X i=0 fi(y)bm i(x).(15) Hence, taking into account the previous reasoning we can evaluate the tensor product surface (14) at a point (x, y)∈[0,1] ×[0,1] by evaluating the m+ 1 B´ezier polynomial curves fi(y), i= 0,1, . . . , m, of degree nat point y, and then evaluating the polynomial B´ezier curve of mdegree represented in the Bernstein basis polynomial of the same degree with control points f0(y), f1(y), . . . , fm(y) (15) at point x. Observe that, if the control points Pij are positive, then the high relative accuracy of the algorithm is assured when the corresponding curve evaluation algorithms satisfy the same property. Using the previous approach we can extend the univariate algorithms to the tensor product case. 6 4.1 The Bernstein-Fourier algorithm The Bernstein matrix of order k+ 1, Bk(s), is the lower triangular matrix whose (i, j) entry is given by bi−1 j−1(s) for each k≥i≥j≥1, that is, Bk(s) =               1 0 0 · · · 0 1−s1 1s0· · · 0 (1 −s)22 1(1 −s)s2 2s2· · · 0 . . .. . .. . ....0 (1 −s)kk 1(1 −s)k−1sk 2(1 −s)k−2s2· · · k ksk               Let us consider the B´ezier polynomial of degree kgiven by p(s) = Pk i=0 cibk i(s) with ci∈Rfor all i∈ {0,1, . . . , n}. The previous polynomial can be expressed as p(s) = eT k+1Bk(s)c,(16) where ek+1 = (0, . . . , 0,1)T∈Rk+1 and c= (c0, c1, . . . , ck)T. Given wk=e−2π i k+1 we consider the (k+ 1) ×(k+ 1) Fourier matrix Wk=               1 1 1 · · · 1 1wk(wk)2· · · (wk)k 1 (wk)2(wk)4· · · (wk)2k . . .. . .. . ..... . . 1 (wk)k(wk)2k· · · (wk)k2               , which is a particular case of Vandermonde matrix. From (16), since Wkis an invertible matrix, we have p(s) = eT k+1Bk(s)Wk((Wk)−1c). Denoting u:= (Wk)−1c= (u0, u1, . . . , uk) and taking into account that eT k+1Bk(s)Wk= ((1 −s+s)k,(1 −s+wks)k, . . . , (1 −s+ (wk)ks)k) we have p(s) = k X i=0 ui(1 + s((wk)i−1))k. According to the previous formula and taking into account that ucan be computed applying the inverse fast Fourier transform to cand the previous discussion in this section about the evaluation of a B´ezier tensor product surface F(x, y), we provide the following pseudo-code for its evaluation: 7 Algorithm 1 BerFourEVAL algorithm for the evaluation of a polynomial by the Bernstein-Fourier algorithm Require: (Pij)0≤j≤n 0≤i≤m, (x, y)∈[0,1] ×[0,1] Ensure: F(x, y) = Pm i=0 Pn j=0 Pijbm i(x)bn j(y) for i= 0 to mdo Pi= (Pi0, Pi1, . . . , Pin)T Ui=ifft(Pi) fi(y) = Pn j=0(Ui)j(1 + y((wn)j−1))n end for f= (f0(y), f1(y), . . . , fm(y)) V=ifft(f) F(x, y) = Pm i=0 Vi(1 + x((wm)i−1))m The previous algorithm requires a computational cost of O(nlog n) elementary operations (see [2] for more details in the univariate case). 4.2 The de Casteljau algorithm The de Casteljau algorithm evaluates polynomials of degree nrepresented in the form (1), with a computational cost of n(n−1) sums and 2n(n−1) products. Taking into account the discussion at the beginning of the current section we can obtain a de Casteljau algorithm for the evaluation of the corresponding tensor product functions (see also [6]). So, the computational cost of the corresponding tensor product algorithm is of (m+1)n(n−1)+m(m−1) sums and 2(m+ 1)n(n−1) + 2m(m−1) products. 4.3 The VS algorithm The VS algorithm evaluates polynomials of degree nrepresented in the form (2). Taking into account the discussion at the beginning of the current section, we can obtain a VS algorithm for the evaluation of the corresponding tensor product polynomials. From the computational cost of the univariate VS algorithm seen in Section 2, we can conclude that the computational cost for the corresponding tensor product VS algorithm is of (2n−1)(m+ 1) + (2m−1) sums, (2n−1)(m+ 1) + (2m−1) products and m+ 2 quotients. 8 5 Bivariate numerical experiments Now we shall compare the adaptation of the de Casteljau, the VS, the Horner and the Bernstein-Fourier algorithms for the evaluation of tensor product surfaces, which have been implemented according to the approach discussed in Section 4. In order to compare the algorithms and see the accuracy at ill conditioned problems we have considered two bivariate polynomials defined on [0,1] ×[0,1], which are generalizations of the two univariate polynomials considered by Wilkinson in [12] and [13], in the sense that the first tensor product polynomial has all its roots uniformly distributed on [0,1]×[0,1] and the second one has the most of its roots localized very close to the point (0,0). The particular functions are the following: F(x, y) = 12 Y i=1 x−i 1212 Y j=1 y−j 12and G(x, y) = 12 Y i=1 x−2 2i12 Y j=1 y−2 2j So we have two tensor product polynomials that present stability problems when evaluating at points close to its roots. First we have evaluated the function F(x, y) at 1296 points uniformly distributed on [0,1] ×[0,1] with the four algorithms considered in IEEE754 double precision. Figure 5 shows the corresponding relative errors and Figure 6 the corresponding absolute errors, where the exact values for the polynomials have been obtained by symbolic computation. We can observe that the four algorithms behave in a very similar way respect to accuracy than its univarite versions with f(t). Then we have evaluated the function G(x, y) at 1444 points uniformly distributed on [0,1] ×[0,1] with the four algorithms considered in IEEE754 double precision. Figure 7 shows the corresponding relative errors and Figure 8 shows the corresponding absolute errors. We can observe that the four algorithms behave in a very similar way respect to accuracy than its univarite versions with g(t). In order to see in detail the difference in the relative errors when evaluating G(x, y) we have computed the mean of the relative errors at the mesh of points for each of the algortihms. For the de Casteljau algorithm the average relative error is 3.37e−13, for the VS algorithm is 1.61e−13, for the Horner algorithm 7.87e+ 01 and for the Bernstein-Fourier 1.03e−2. Finally, we have considered the tensor product polynomial H(x, y) = (x−1/2)12(y−1/2)12, which is a very ill-conditioned polynomial because of its roots. Then we 9