Chapter 28: Computer-Aided Geometric Design

The simplicity of this formula is striking; in former days, involved papers were written on this ...... then the above quadratic equation may have complex solutions.
1MB taille 2 téléchargements 280 vues
28 Computer-Aided Geometric Design

Gerald Farin

28.1 28.2 28.3 28.4 28.5 28.6 28.7 28.8 28.9

History Basic Principles Bézier Curves Cubic Hermite Curves B-Splines Cubic Interpolation and Approximation Bézier Patches Composite Surfaces Rational Curves and Surfaces — NURBS

28.1 History CAGD (computer-aided geometric design) dates back to Paris in 1959, when Citroën hired Paul de Faget de Casteljau to develop some mathematical tools. Citroën already had numerically controlled milling machines; but in order to fully utilize them, a link had to be created between the standard blueprints and the milling machines. This link would have to translate the blueprints into formulas that could be evaluated by a program, thus creating the coordinates to drive the milling machine. De Casteljau invented what he called “Courbes à Poles,” and what we now know, ironically, as Bézier curves. We will use them throughout this chapter. Pierre Bézier worked at Rénault, also in Paris, and learned about Citroën’s (very secretive) efforts. He was able to create a system with the same functionality himself, and Rénault allowed him to publicize it widely. Thus Bézier curves started to dominate CAGD. Another development was the introduction of splines — this one being an American contribution. In the late 1950s, J. Ferguson at Boeing developed a package based on interpolating piecewise cubic curves, on C2 cubic splines, as we would say today. Splines were already known among mathematicians following the discovery of B-splines by I. Schoenberg in 1946. It was most notably C. de Boor who advanced the theory of these curves, based upon practical experience at General Motors. Based on de Boor’s work, Gordon and Risenfeld realized in 1972 that B-splines could be used in much the same way as could Bézier curves. They showed how Bézier curves were just a special case of B-spline curves, thus making possible a unification of systems based on splines (typically American) and those based on Bézier curves (typically French). One of the most influential American researchers in the field of CAGD was S. Coons, who developed surfaces named after him in the late 1950s. These surfaces have given way to B-spline-based systems now, but another development, also initiated by Coons, has further unified all of CAGD. This is the concept of NURBS, a generalization of piecewise polynomial curves to piecewise rational polynomial curves. Coons’ student K. Vesprille laid down the basic theory of rational B-splines in 1975.

©1999 CRC Press LLC

It was quickly realized that they allowed a unified representation of splines and conics. This was important when data were to be transferred between different design systems — spline and Bézier curves were widely used, but conic prevailed in several aircraft design systems, owing to Liming’s work. There have been several instances where CAGD interacted with finite element research, the most notable one being S. Coons’ work. Coons patches (including several generalizations) were in use for many years in automotive design. But they also found their way into grid generation for finite elements, where they became known as “transfinite interpolation.” Another example is the finite element developed by Clough and Tocher; it was not known in the CAGD community until it was translated into Bernstein-Bézier form. Today, the main use of CAGD in the context of finite element methods is in grid generation. The geometry of any object is nowadays expressed in the forms of surfaces from some CAD/CAM system, typically using the B-spline or NURBS representation. Grids will have to be created on and around the object. How can we incorporate the CAGD description of the object into the desired grid? In what follows, we will outline the central CAGD techniques to the extent that they will be of use for this problem. Several books exist on the topic of CAGD, and they should be consulted for more details: Farin [6], Faux and Pratt [8], Hoschek and Lasser [13], Yamaguchi [19]. When we describe results without explicit references, then these texts should be consulted. Another source for up-to-date information is the home page of the journal CAGD : http://www.elsevier.nl/locate/comaid.

28.2 Basic Principles Geometric computation takes place in two- or three-dimensional Euclidean (or affine) space. The objects of the computation are points, denoted by boldface letters: a, x, etc. We may obtain points from other points by mapping such as affine maps. These are of the form

Φx = Ax + v, where A is a square matrix and v is a translation vector. All affine maps may be thought of as a concatenation of rotations, scalings, shears, and translations. Affine maps leave barycentric combinations unchanged: these are linear combinations where the coefficients sum to one. Thus if

x = ∑ α ix i ;

∑ α = 1, i

i

i

and Φ is an affine map, then also

Φx = ∑ α i Φx i . i

Thus, for example, the midpoint of two points is mapped to the midpoint of the two image points. Any time we have a relationship between points such as

x = ∑α i xi , i

it is mandatory that the α i sum to one:* otherwise a simple translation would destroy this relationship. If all α i are between 0 and 1, then we speak of a convex combination. These are known for their inherent numerical stability. It is possible that the α i sum to zero; then we have defined a vector. Another basic operation on points is that of linear interpolation:

*This is also phrased as “they form a partition of unity.”

©1999 CRC Press LLC

x(t ) = (1 − t )a + tb.

(28.1)

Almost all geometric computations may be traced to this simple building block! The above is a computational definition; a geometric one would say that x(t ) is obtained by the affine map Φ that maps [0, 1] to ab . Note that it is not necessary that t ∈ [0, 1]; in those cases, we speak of extrapolation. The bivariate analog of linear interpolation is given as follows: given three points a, b, c in IE3, compute points on the plane through them. We think of a, b, c as the image of three 2D points p, q, IR2. Any point u in 2D may be written as u = u p + vq + wIR2 where u + v + w = 1. The numbers u, v, w are called barycentric coordinates of u with respect to p, q, IR2. Now the image x of u will be a point on the plane through a, b, c given by

x = ua + vb + wc. The barycentric coordinates of u are defined as follows: u=

area(u, q, r) area(p, u, r) area(p, q, u) , v= , w= . area(p, q, r) area(p, q, r) area(p, q, r)

(28.2)

More information on this basic geometry can be found in many texts.*

28.3 Bézier Curves Any polynomial curve in 2- or 3-space may be expressed as

 x ( t ) n  y(t ) = x(t ) = c F (t ), ∑ i i   i=0  z(t )  where the F i are a set of basis functions for all polynomials of degree n, and the ci are the coefficients defining x(t ). The most common choice is to set F i(t ) = t i, i.e., to select the monomial basis. “Most common” strictly refers to calculus classes; in numerical and geometric applications, this basis is very unsuitable: the ci are almost completely devoid of geometric meaning, and worse, they are extremely sensitive to the slightest round off. The latter observation is due to Farouki and Rajan [7], who demonstrated that a different basis is close to optimal in the sense of numerical stability: this is the Bernstein basis. Using it, any curve may be written as n

x(t ) = ∑ bi Bin (t ),

(28.3)

i=0

where the B ni (t ), the Bernstein polynomials, are given by

 n n −i Bin (t ) =   t i (1 − t ) .  i

(28.4)

They are set to zero for i ∉{0, …, n }. Using Bernstein polynomials, one considers curves over the interval [0, 1], although any other interval could be used equally well. Polynomial curves that are expressed in the Bernstein basis are called Bézier curves. Figure 28.1 gives two examples. *For a website, see http://www.eros.cagd.eas.asu.edu/~farin/gbook/gbook_home.html.

©1999 CRC Press LLC

FIGURE 28.1

Bézier curves: top, n = 3, bottom, n = 5.

In order for Eq. 28.3 to be independent of a particular coordinate system, the basis functions must sum to one, i.e., they must form a partition of unity. We thus have n

∑ B (t ) ≡ 1. n j

(28.5)

j =0

Bernstein polynomials also satisfy the recursion

Bin (t ) = (1 − t ) Bin −1 (t ) + tBin−−11 (t ).

(28.6)

It leads directly to the de Casteljau algorithm for the evaluation of Bézier curves: de Casteljau algorithm: Given: b0, b1, …, bn ∈ IE3 and t ∈ IR, set

r = 1,..., n bir (t ) = (1 − t )bir −1 (t ) + tbir+−11 (t )  i = 0,..., n − r

(28.7)

and b0i (t ) = bi. Then bn0 (t ) is the point with parameter value t on the Bézier curve bn. The polygon P formed by b0, …, bn is called the Bézier polygon or control polygon of the curve bn. Similarly, the polygon vertices bi are called control points or Bézier points. The intermediate coefficients bri (t ) are conveniently written into a triangular array of points, the de Casteljau scheme. We give the example of the cubic case: b0 b1 b10 b 2 b11 b 20 b3 b12 b12 b30 . ©1999 CRC Press LLC

(28.8)

FIGURE 28.2

Several steps of the de Casteljau algorithm.

This triangular array of points seems to suggest the use of a two-dimensional array in writing code for the de Casteljau algorithm. That would be a waste of storage; however, it is sufficient to use the left column only and to overwrite it appropriately. While the de Casteljau algorithm needs O (n 2) operations for a degree n Bézier curve, its use is still encouraged because of its stability — and if an optimizing compiler is available, it is surprisingly fast! Figure 28.2 illustrates this important algorithm: A Bézier curve is evaluated at several parameter values, and all intermediate points b ri are connected. Because of their central role in all of CAGD, we list some of the most important properties of Bézier curves: Invariance under affine parameter transformations: Algebraically, this property reads n u − a n b B t = bi Bin  . ( ) ∑ ∑ i i  b − a i=0 i=0 n

(28.9)

It states that we may define a curve over [a, b] as well as over [0, 1]. Convex hull property: Any point on a Bézier curve, as long as its parameter value is between 0 and 1, is in the convex hull of the control polygon. This follows, since for t ∈ [0, 1], the Bernstein polynomials are nonnegative and they sum to one as shown in Eq. 28.4. This property allows for very cheap interference checks, using the minmax box of the control polygon. Linear precision: The identity n

j

∑ n B (t ) = t , n j

(28.10)

j =0

has the following application: suppose the polygon vertices bj are uniformly distributed on a straight line joining two points p and q:

©1999 CRC Press LLC

j j b j = 1 −  p + q; j = 0,..., n.   n n The curve that is generated by this polygon is the straight line between p and q, i.e., the initial straight line is reproduced. The derivative of a Bézier curve is given by n −1 d n b (t ) = n∑ ∆b j Bjn −1 (t ); ∆b j ∈ IR3 . dt j =0

here, ∆ denotes the forward difference operator ∆bj = bj+1 – bj. Higher derivatives are given by

dr n n! n − r r n − r = ∆ b j Bj (t ); ∆r b j ∈ IR3 . b t ( ) ∑ r dt (n − r )! j = 0 Bézier curves may be pieced together, thus forming composite curves. Let b0, …, bn define one curve and co, …, cn a second one. Both curves form one continuous curve if bn = c0. They form one smooth curve (no tangent discontinuities) if in addition bn–1, co , c1 are collinear. In order to say when they form one C1 curve, we must define over which intervals they are defined. So let the curve b0, …, bn be defined over [a, b] and let c0, …, cn be defined over [b, c]. They are C1 if

c0 =

(c − b)bn −1 + (b − a)c1 c-a

.

If at each level r of the de Casteljau algorithm, we use a different argument t i instead of t, we obtain a function of n arguments: b[t 1, …, t n]. This is called the blossom of a Bézier curve after L. Ramshaw [17]. It is clear from the definition of a blossom that

[ ]

bnn (t ) = b t < n > , where t denotes n–fold repetition of the argument t. One of the most useful properties of blossoms is the following: suppose we wish to redefine our Bézier curve, so that now it is defined over an interval [a, b] instead over [0, 1]. It will then be defined by a different control polygon c0, …, cn. The ci are simply calculated as

[

]

c i = b a < n −i > , b ;

i = 0,..., n.

(28.11)

If [a, b] = [0, 1/2], then the above is called subdivision. It is important for many numerical techniques that need successive control net refinement. An example is root finding, or, more generally, finding the intersection(s) of a straight line with a curve. A very simple and robust algorithm is the following: find the minmax box that contains the curve. Using the convex hull property, this is done by finding the maximal and minimal coordinate values of the control polygon. Then test if the straight line intersects that box. If not, then there is no intersection. If it does, subdivide the curve at t = 1/2 and repeat the above for both halves. The algorithm will terminate if the size of a minmax box is below a given tolerance. While extremely robust, the method is also slow. We close this section with a collection of formulas.

©1999 CRC Press LLC

Power basis {t i} and the Bernstein basis {B ni} conversion:

() = ∑ B (t ) () j i n j =1 i n

t

i

n j

and n j − i  n  j  Bin (t ) = ∑ ( −1)     t j .  j  i  j =1

Recursion:

Bin (t ) = (1 − t ) Bin −1 (t ) + tBin−−11 (t ). Subdivision: n

Bin (ct ) = ∑ Bij (c) Bjn (t ). j =0

Derivative:

[

]

Bin ( x )dx =

1 n +1 n +1 ∑ Bj (t ), n + 1 j =i +1

1

1

d n Bi (t ) = n Bin−−11 (t ) − Bin −1 (t ) . dt Integral:



t

0

∫ B ( x )dx = n + 1. 0

n i

Three degree elevation formulas:

n + 1 − i n +1 Bi (t ), n +1 i + 1 n +1 tBin (t ) = Bi +1 (t ), n +1 n + 1 − i n +1 i + 1 n +1 Bin (t ) = Bi (t ) + Bi +1 (t ). n +1 n +1

(1 − t ) Bin (t ) =

Product:

( )( ) B B (u ) B (u ) = ( ) m

m i

©1999 CRC Press LLC

n j

n

i j m+n i+ j

m+n i+ j

(u).

28.4 Cubic Hermite Curves Suppose one is given two p0, p1 and two tangent vectors m0, m1. The objective is to find a cubic polynomial curve p that interpolates to these data:

p(0) = p0 , p˙ (0) = m 0 , p˙ (1) = m1 , p(1) = p1 , where the dot denotes differentiation. The interpolant can be written as

p(t ) = p0 H03 (t ) + m 0 H13 (t ) + m1 H23 (t ) + p1 H33 (t ),

(28.12)

where

H03 (t ) = B03 (t ) + B13 (t ), 1 H13 (t ) = B13 (t ), 3 1 H23 (t ) = − B23 (t ), 3 3 3 H3 (t ) = B2 (t ) + B33 (t ).

(28.13)

The H 3i are called cubic Hermite polynomials.

28.5 B-Splines If continuity higher than C1 is desired, joining Bézier curves becomes cumbersome, and the B-spline approach is far easier. A B-spline curve consists of several polynomial pieces, or segments, that are connected with a prescribed smoothness. Typically, degree n B-splines have smoothness Cn–1. Our development here is similar to that of [6], but is “leaner” because of a change in notation. We are given a nondecreasing knot sequence u 0, …, u K and the degree n of a (to be defined) B-spline curve. The curve will be defined by a control polygon

P = d 0 d1 ...d p , with p = K – n. Thus there are as many control points as there are successive n–tuples of knots. Successive knots do not have to be distinct; but no more than n successive knots may coincide. If r successive knots coincide, we speak of a knot of multiplicity r. Take all spans of n subsequent intervals and map them to the control polygon legs by affine maps:

[ui , ui +n ] → didi +1. This way, each control polygon leg is “engraved” with a span of the knot sequence. Note that, since no knot is allowed to have multiplicity higher than n, none of these spans will be empty.

©1999 CRC Press LLC

Now let L be one of the intervals defined by two successive and different knots. It is part of n spans, and will thus be engraved on n polygon legs. We call the corresponding control polygon PL and its control points dLi :

P L = d 0L ,..., d nL . There is a restriction on L: if it is “too close” to u 0 or to u K, then there are fewer than n spans L ni containing it — such intervals will not be considered. The admissible intervals will be called domain intervals. They are u n–1, …, uK–n+1. Note that we can now write the whole control polygon P as

P = Pl P L Pr , with suitably defined left and right subpolygons Pl and Pr. There are n spans containing L. We denote them by L ni, i = 1, …, n. Each of these spans is mapped to a control polygon leg by an affine map Φni .

Φ in : Lni → diL−1d L Li ,

i = 1,..., n.

Let u ∈ L. Then each of the affine maps Φni takes u to a point on a control polygon leg, and we define

d1i (u) = Φ in (u);

i = 1,..., n.

(28.14)

We have augmented the knot sequence by one knot u, and we have augmented the control polygon PL to a new polygon

P L [u] = d 0 d11 (u)d12 (u)...d1n (u)d n . We call this process knot insertion, after W. Boehm [1]. We utilize affine maps to describe knot insertion. Needless to say that we might have used linear interpolation as well: then we would write

d1i (u) = (1 − ti1 )di −1 + ti1di , where t 1i is the local parameter in the span L ni .

ti1 =

u − li1

.

Lni

Here, l 1i denotes the left endpoint of L ni, and |L ni | denotes the length of L ni . The process of knot insertion may be repeated. However, after n steps, the process terminates, resulting in a point on the curve. This process is known as the de Boor algorithm, first described in [2]. If u is not already one of the knots, the intermediate de Boor points are found by

dir (u)Φ in − r +1 (u); r = 1,..., n; i = r,..., n. Here, we have set defined the affine maps Φn–r+1 (u) by i

Φ in − r +1 (u) : Lni − r +1 → dir−1dir ©1999 CRC Press LLC

(28.15)

FIGURE 28.3 A cubic B-spline curve, its B-spline polygon (square marks), and the corresponding piecewise cubic Bézier polygon (circular marks).

and d nn is the desired result, i.e., the point on the curve. Writing the involved affine maps as linear interpolants, we obtain

dir (u) = (1 − tir )dir−−11 + tir dir −1 ,

(28.16)

where t ri is the local parameter in the span L n–r+1 i :

tir =

u − lir . Lri

r r Here, l ri denotes the left endpoint of L n–r+1 i , and |L i | denotes the length of L i. If at each level r of the de Boor algorithm, we use a different argument vr instead of u, we obtain a function of n arguments: dL[v1, …, vn]. This is called the blossom of a B-spline curve after L. Ramshaw [17]. It is clear from the definition of a blossom that

[ ]

d nn (u) = d L u < n> . We have already encountered the spans L ri . Let us denote the set of r + 1 knots in L ri by {L ri }. The blossom dL is well-defined for arguments outside of L. Thus expressions of the form dL[{Ln–1i }] formally make sense. In fact, they allow us to write the control points of a B-spline curve as blossom values:

[

]

diL = d L {Lni −1} ; i = 0,..., n.

(28.17)

The blossom dL may also be used to find the Bézier points bi of the curve segment corresponding to the segment L. Setting L = [u –, u +], we get

[

]

bi = d L u−< n −i > , u+ ; i = 0,..., n.

(28.18)

The simplicity of this formula is striking; in former days, involved papers were written on this conversion problem! That is not to say, however, that Eq. 28.18 is the most efficient way to solve the problem. But it does produce very readable code, which is equally important. A B-spline blossom routine can be obtained via anonymous ftp from enws102.cagd.eas.asu.edu in the directory pub/farin/floppy. Figure 28.3 gives an example of a cubic B-spline curve. While our definition of a B-spline curve was recursive, an explicit one also exists. It uses the B-spline basis functions N ni (u), which are themselves defined recursively:

Nin (u) = (1 − ti +1 ) Nin+−11 (u) + ti Nin −1 (u). Here, u ∈ L ni and t i is the local parameter in L ni . The recursion starts with

©1999 CRC Press LLC

(28.19)

if ui −1 ≤ u < ui

1 Ni0 (u) =  0

else

.

Using these basis functions, a B-spline curve may be written as p

d (u) = ∑ di Nin (u). n

(28.20)

i=0

The derivative of a B-spline curve is given by

x˙ (u) =

n n −1 (dn (u) − dnn−−11(u)). L

Using blossom notation, this becomes

r x˙ (u) = nd L 1, u < n −1> ,

[

]

r where 1 denotes the unit vector on the real line. Written in terms of the B-spline basis, this is n

x˙ (u) = n∑ i =1

∆di −1 n −1 Ni (u), Lni

where the N n–1 i (u) are numbered relative to the interval L. Higher derivatives are expressed (and computed!) more easily using just the blossom form:

x ( r ) (u ) =

r n! d L 1r , u < n − r > . (n − r )!

[

]

An implementation remark: the above development only uses knots up to multiplicity n. The most common data format, IGES (initial graphics exchange specification), uses knots of multiplicity n + 1 at the domain endpoints. This is not necessary, but it may be important to be aware of. Also, IGES enters multiple knots into the knot sequence as often as their multiplicity implies. It is cleaner programming style to list all knots only once and to keep track of their multiplicities in a separate array. For a particular operation, the knot sequence can then be “expanded.”

28.6 Cubic Interpolation and Approximation An important application of B-spline curves is for interpolation of data points; the cubic case is most often encountered. Here, we are given L data points xi and corresponding parameter values u i. We wish to find a cubic control polygon d0, …, dL+2 such that the corresponding B-spline curve passes through the data: L +1

x i = ∑ d j N 3j (ui ); i = 0,..., L. j =0

©1999 CRC Press LLC

These are L + 1 equations for the L + 3 unknowns dj. The common approach is to add two more equations, corresponding to derivative information at the endpoints. The coefficient matrix is obtained by evaluating the B-spline basis functions at the given knots. Since each N 3i is nonzero for only three subsequent knots, the matrix is tridiagonal. If we prescribe the two end derivatives, this amounts to selecting the Bézier points b1 and b3L–1. We then obtain a linear system of the form

1 α  1     

β1

 d1  r0   d  r   2   1   M   = M     γ L −1  d L  rL −1      1   d L +1  rL 

γ1 O

α L -1 β L -1

(28.21)

Here we set

r0 = b1 , ri = ( ∆ i −1 + ∆ i )x i , rL = b3 L −1 . The first and last polygon vertices do not cause much of a problem:

d0 = x 0 ,

d L+2 = x L .

This linear system can be made symmetric: we can multiply each equation by a common factor. In particular, we can divide the ith equation through by ∆2i–1 ∆2i. Also, we would have to delete the first and last rows and columns from the system, and update the right-hand side accordingly. The resulting new matrix will now be symmetric; its entries will satisfy α i+1 = γ i. If more data points are given than the expected number of spline segments, then spline approximation is called for. The most common form is least squares approximation, and it is described now. We are given data points pi with i = 0, …, P. We wish to find an approximating B-spline curve p(u) of degree n with L domain knots, i.e., with a knot sequence u0, …, u L+2n–2. We want the curve to be close to the data points in the following sense. Suppose the data point pi is associated with a data parameter value wi*. Then we would like the distance ||pi – p(wi)|| to be small. Attempting to minimize all such distances then amounts to P

minimize

∑ p − p(w ) i

2

(28.22)

i

i=0

The squared distances are introduced to simplify our subsequent computations. We shall minimize Eq. 28.22 by finding suitable B-spline control vertices dj :

(

)

P

minimize f d 0,..., d L + n −1 = ∑ pi −

*Note that wi does not have to be one of the knots.

©1999 CRC Press LLC

i=0

L + n −1



j =0

d j N nj

2

( wi )

(28.23)

Thus f is a quadratic form with L + n independent variables dj . Such functions only have one minimum, and at its location, the partials with respect to the dj must vanish: ∂ƒ/∂dk = 0*. Thus: P  L + n −1  0 = ∑ pi − ∑ d j N jn (wi )Nkn (wi ); k = 0,..., L + n − 1 i=0  j =0 

or L + n −1

∑ j =0

P

P

i=0

i=0

d j ∑ N jn (wi ) Nkn (wi ) = ∑ pi Nkn (wi ); k = 0,..., L + n − 1

(28.24)

This is a linear system of L + n equations for the unknowns dk, with a coefficient matrix M whose elements m j,k are given by P

m j ,k = ∑ N jn (wi ) Nkn (wi ); 0 ≤ j, k ≤ L + n. i=0

These equations are usually called normal equations. The symmetric matrix M, although containing many zero entries, is often ill-conditioned — special equation solvers, such as a Cholesky decomposition, should be employed. For more details on the numerical treatment of least squares problems, see [11] or [14]. The matrix M is nonsingular in all “standard” cases. It is obviously singular if the number of data points P + 1 is less than the number of domain knots L + n + 1. It is also singular if there is a span [u j–1, u j+n] that contains no wi. In that case, the basis function N nj would evaluate to zero for all wi , resulting in a row of zeroes for M. We have so far assumed much more than would be available in a practical situation. First, what should the degree n be? In most cases, n = 3 is a reasonable choice. The knot sequence poses a more serious problem. Recall that the data points are typically given without assigned data parameter values wi . The centripetal parametrization [15] will give reasonable estimates, provided that there is not too much noise in the data. But how many knots uj shall we use, and what values should they receive? A universal answer to this question does not exist — it will invariably depend on the application at hand. For example, if the data points come from a lesser digitizer, there will be vastly more data points pi than knots u i. After the curve p(u) has been computed, we will find that many distance vectors pi – p(wi) are not perpendicular to p˙ (wi ). This means that the point p(wi ) on the curve is not the closest point to pi , and thus ||pi – p(wi )|| does not measure the distance of pi to the curve. This indicates that we could have chosen a better data parameter value wi corresponding to pi. We may improve our estimate for wi by finding the closest point to pi on the computed curve and assigning its parameter value wˆ i to pi . We do ˆ i. This process typically converges this for all i and then recompute the least squares curve with the new w after three or four iterations. It was named parameter correction by J. Hoschek [12]. ˆ i is found using a Newton iteration. We project pi onto the tangent at The new parameter value w p(wi ), yielding a point q i . Then the ratio of the lengths ||q i – pi||/|| p˙ (wi )|| is a measure for the adjustment of wi . The actual Newton iteration step looks like this:

[

] p˙ ((w )) ∆su .

wˆ i = wi + pi − p(wi )

p˙ wi i

*This is shorthand for taking the partials for each of dk’s components.

©1999 CRC Press LLC

k

k

(28.25)

FIGURE 28.4

A rectangular Bézier patch with m = n – 3.

In this equation, sk denotes the arc length of the segment that wi is in, i.e., u k < wi < u k+1. This length can safely (and cheaply) be overestimated by the length of the Bézier polygon of the kth segment.* We finally note that Eq. 28.25 should not be used to compute the point on a curve closest to an arbitrary point pi . It only works if pi is already close to the curve, and if a good estimate wi is known for the closest point on the curve.

28.7 Bézier Patches There are two kinds of Bézier patches: rectangular and triangular. A rectangular Bézier patch is defined by a rectangular array of control points bi,j ; 0 ≤ i ≤ m, 0 ≤ j ≤ n. For the case m = 3, n = 3, it would look like

b0 ,0 b1,0 b2 ,0 b3,0

b0,1 b1,1 b2 ,1 b3,1

b0 ,2 b1,2 b2 ,2 b3,2

b 0 ,3 b1,3 b 2 ,3 b3,3

Figure 28.4 gives an example. A point bm,n(u, v) on such a surface is given by m

n

bm,n (u, v) = ∑ ∑ bi, j Bim (u) Bjn (v).

(28.26)

i=0 j =0

This surface is a map of the domain 0 ≤ u, v ≤ 1. Its actual degree is m + n, since the highest powers in u and v appear in the term u mvn.

*Hoschek’s original development uses uL+n–1 – un–1 instead of ∆uk and the length of the total curve instead of sk. Our formula is cheaper.

©1999 CRC Press LLC

FIGURE 28.5

A triangular Bézier patch with n = 3.

The control points of a triangular patch are usually given three subscripts, in the example of a quartic patch, this would look like

b040 b031b130 b022 b121b220 b013b112 b211b310 b004b103b202 b301b400 Figure 28.5 gives an example. A point bn(u) on the patch is defined by b n (u) = b n0 (u) =

∑ b j Bjn (u)

(28.27)

j =n

where Bjn (u) =

n! i j k uv w . i! j! k!

Here, u = (u, v, w) are barycentric coordinates in a domain triangle, implying that u + v + w = 1. The actual shape of this domain triangle is immaterial as barycentric coordinates are preserved under affine maps. See Section 28.2 for details. A de Casteljau algorithm is also defined for this patch type; it is given by 1 1 1 b ir (u) = ub ir+−e1 (u) + vb ir+−e2 (u) + wb ir+−e3 (u),

(28.28)

where*

r = 1,..., n and

i =n−r

*We use the abbreviations e1 = (1, 0, 0), e2 = (0, 1, 0), e3 = (0, 0, 1), and |i| = i + j + k. When we say |i| = n, we mean i + j + k = n, always assuming i, j, k ≥ 0.

©1999 CRC Press LLC

And b0i (u) = bi. Then bn0 (u) is the point on the triangular patch with parameter value u. For a rectangular patch, the u–partial is given by n m −1 ∂ m,n b (u, v) = m ∑ ∑ ∆1,0 bi, j Bim −1 (u) Bjn (v), ∂u j =0 i=0

where ∆1,0bi,j = bi+1,j – bi,j. Higher derivatives are found by repeated application of this formula:

∂ r m,n m! n m − r r , = ∆1,0 bi, j Bim − r (u) Bjn (v), b u v ( ) ∑ ∂u r (m − r )! ∑ j =0 i=0 For derivatives of triangular patches the notion of partials is not useful; instead, one uses directional derivatives. These are taken along a direction d defined by the difference of two points in barycentric coordinates: d = u1 – u2. We obtain Dd b(u) = n

∑ b1i (d) Bin −1 (u),

i = n −1

where the b1i (d) are computed according to Eq. 28.28. Higher derivatives are then given by Ddr b(u) =

i (n − r )! i =∑ n−r

n!

b r (d) Bin − r (u),

28.8 Composite Surfaces As for curves, a single patch is not flexible enough to describe complex shapes. For curves, the B-spline approach works best; it is not very different in the surface case. Just as a rectangular Bézier patch is the tensor product of univariate schemes, a B-spline surface can be written as a tensor product:

x(u, v) = ∑ ∑ dij Nim (u) N jn (v), i

(28.29)

j

where the subscripts run according to the curve case. An important application is that of bicubic spline int erpolation. Here, m = n = 3, and the problem is as follows: Suppose we have (K + 1) × (L + 1) data points xIJ and two knot sequences u0, …, uK and v0, …, vL. For each row of data points, we prescribe two end conditions (e.g., by specifying tangent vectors or Bézier points) and solve the univariate B-spline interpolation problem as described above. As all these interpolation problems use the same tridiagonal coefficient matrix, an L – U decomposition should be performed before the row-by-row loop is entered. We thus produce the elements of an intermediate matrix D. We now take every column of D and perform univariate B-spline interpolation on it, again by prescribing end conditions such as clamped end tangents or Bessel tangents. The resulting control points constitute the desired B-spline control net. The final B-spline control net has two more rows and columns than X.* This is due to the end conditions; to resolve the apparent discrepancy, we can think of X as having two additional rows and columns that constitute the end condition data.

*This is inherited from the curve case: there one gets L + 2 control points for L data points.

©1999 CRC Press LLC

If the data points are not organized in this way, the above approach is not applicable. In case of many points p0, …, pL without any structure, one can resort to tensor product least squares approximation. We assume that we are given knot sequences u 0, …, u P and v0, …, vQ.* We also assume that each data point pi is assigned a parameter value (si , ti). Then every data point pi is associated with a surface point x(si , ti ). Our objective is to minimize all distance squares L

∑ p − x( s , t ) i

i

2

i

i=0

or 2

L

∑ p − ∑∑d i

i=0

c

cd

N (si ) N (ti ) . m c

n d

d

We use the same approach as we did for curves: interpret the above as a multivariate function of the unknowns dc,d , take partials with respect to each of them, and equate to zero. This leads to L

L

∑ pi ∑ ∑ Ncm (si ) Ndn (ti ) =∑ ∑ ∑ dcd ∑ ∑ Ncm (si ) Ndn (ti ) Nem (si ) N nf (ti ); c = 0,..., P − m, i=0

c

i=0

d

c

d

e

f

We have R = (P – m)(Q – n) equations in the same number of unknowns. Yet the structure of a linear system is not clearly discernible. We achieve this by linearizing: instead of using two subscripts for counting in our rectangular arrays, we will just use one. Thus c(ρ ) and d (ρ ) will give the row and column values (c, d) for array element with number ρ and e(σ ) and f(σ ) will give the row and column values (e, f ) for array element with number σ. We now obtain L

R

L

i=0

ρ =0

i=0

∑ pi Ncm( ρ ) (si ) Ndn( ρ ) (ti ) = ∑ dρ ∑ Ncm( ρ ) (si )Ndn( ρ ) (ti ) Nem(σ ) (si ) N nf (σ ) (ti );σ = ..., R. This has the form of a linear system; the coefficient matrix has elements L

α ρ ,σ = ∑ Ncm( ρ ) (si ) Ndn( ρ ) (ti ) Nem(σ ) (si ) N nf (σ ) (ti ). i=0

Figure 28.6 gives an example.

28.9 Rational Curves and Surfaces — NURBS Some of the most basic curves in this context are the conic sections. Comprising the familiar ellipses, parabolas, and hyperbolas, they are all defined by five points in the plane. If the points have coordinates (x 1, y1), …, (x 5, y5) the implicit form of the conic through them is given by

*In practice, some heuristic is typically necessary to find these.

©1999 CRC Press LLC

FIGURE 28.6 B-spline approximation: the given data points are marked by square boxes; the control net is superimposed in light gray.

x2 2 1

x f ( x, y) =

x

2 2

x

2 3

xy x1 y1

y2

x

y

1

2 1

x1 y1 1

2 2

x2 y2 1

2 3

x3 y3 1

y

x2 y2 y x3 y3 y

x 42

x 4 y4 y42

x 4 y4 1

2 5

x5 y5 y52

x5 y5 1

x

= 0.

The implicit form is important when dealing with the IGES data specification. In that data format, a conic is given by its implicit form f(x, y) = 0 and two points on it, implying a start and end point b0 and b2 of a conic arc. Many applications, however, need the rational quadratic form. Now a conic looks like this:

x (t ) =

w0 b0 B02 (t ) + w1b1 B12 (t ) + w2 b2 B22 (t ) ; w0 B02 (t ) + w1 B12 (t ) + w2 B22 (t )

x(t ), bi ∈ IE 3 .

(28.30)

We call the wi weights and the bi the control polygon. Without loss of generality, we can assume w0 = w2 = 1; this is called standard form of a conic. To convert the implicit IGES format to this form, we have to determine b1 and its weight w1. First, we find tangents at b0 and b2: we know that the gradient of f is a vector that is perpendicular to the conic. The gradient at b0 is given by f ’s partials: ∇f(b0) = [fx(b0), fy(b0)]T. The tangent is perpendicular to the ⊥ gradient and thus has direction ∇ f(b0) = [–fy(b0), fx(b0)]T. Thus our tangents are given by

t 0 (t )

= b0 + t∇ ⊥ f (b0 )

t 2 (s) = b2 + s∇ ⊥ f (b2 ).

©1999 CRC Press LLC

and

Their intersection determines b1. Next, we compute the midpoint m of b0 and b2. Then the line mb 1 will intersect our conic in the shoulder point s. This requires the solution of a quadratic equation,* and we find out desired weight w1 from the relationship

w1 = ratio(m, s, b1 ). If the input is not well defined — imagine b0 and b2 being on two different branches of a hyperbola! — then the above quadratic equation may have complex solutions. An error flag would be appropriate here. If the arc between b0 and b2 subtends an angle larger than, say, 120°, it should be subdivided. For more details, see [18]. If the control polygon of a conic forms an isosceles triangle, and the weights are given by w0, w1, w2 = 1, cosα , 1, where the angle alpha is given by α = ∠ b2b0b1, then that conic is a circular arc. Note that cosα ≤ 1. In general, if the weights of a conic are 1, w, 1, with w > 0, then for w < 1 the conic is an ellipse, for w = 1 it is a parabola, and for w > 1 it is a hyperbola. References for this topic: [3], [4], [5], [9], [16]. A rational Bézier curve is defined by

x (t ) =

w0 b0 B0n (t ) + L + wn bn Bnn (t ) ; x(t ), bi ∈ IE 3 . w0 B0n (t ) + L + wn Bnn (t )

(28.31)

The wi are called weights; the bi form the control polygon. It is the projection of the 4D control polygon [wi bi wi]T of a nonrational 4D curve. If all weights equal one, we obtain the standard nonrational Bézier curve, since the denominator is identically equal to one.** If some wi are negative, singularities may occur; we will therefore deal only with nonnegative wi. For the first derivative of a rational Bézier curve, we obtain

x˙ (t ) =

1 [p˙ (t ) − w˙ (t )x(t )], w(t )

(28.32)

where we have set

p(t ) = w(t )x(t ); p(t ), x(t ) ∈ IE 3 . At the endpoint t = 0, we find

x˙ (0) =

nw1 ∆b 0 . w0

For higher derivatives, some computation yields

x ( r ) (t ) =

1  (r ) r  r ( j ) (r− j )  p − ∑   w (t )x (t ). w(t )  j =1  j  

(28.33)

* The quadratic equation will in general have two solutions. We take the one insider the triangle b0, b1, b2. **This is also true if the weights are not unity, but are equal to each other — a common factor does not matter.

©1999 CRC Press LLC

This is a recursive formula for the r th derivative of a rational Bézier curve. It only involves taking derivatives of polynomial curves. The first derivative can also be obtained as a byproduct of the de Casteljau algorithm, as described by Floater [10]:

x˙ (0) = n

w0n −1w1n −1

[ ]

2

w0n

[b

n −1 1

]

− b0n −1 .

(28.34)

If B-spline curves are made rational, they are called NURBS for nonuniform rational B-splines.* A NURB curve s is defined by

∑ s(u) = ∑ p

j =0 p

wi di Nin (u)

j =0

wi Nin (u)

(28.35)

.

A rational B-spline curve is given by its knot sequence, its 3D control polygon, and its weight sequence. The control vertices di are the projections of the 4D control vertices [wi di wi]T. To evaluate a rational B-spline curve at a parameter value u, we may apply the de Boor algorithm to both numerator and denominator of Eq. 28.35 and finally divide through. This corresponds to the evaluation of the 4D nonrational curve with control vertices [wi di wi]T and to projecting the result into IE3. Rational surfaces are defined in the same way. The most widely used type, a NURB surface, is defined by s(u, v) =

∑ ∑ w d N (u ) N ( v ) . ∑ ∑ w N (u ) N ( v ) i

i, j

j

i

j

m i

i, j

i, j

n j

m i

n j

(28.36)

It is one of the most general data formats available. NURB surfaces encompass Bézier patches, both rational and nonrational; quadrics, including spheres; surfaces of revolutions, including tori; and more. As an example, we show how to produce a surface of revolution. These are given by

r(v) cos u   x(u, v) = r(v) sin u .  z( v )    For fixed v, an isoparametric line v = const. traces out a circle of radius r(v), called a meridian. Since a circle may be exactly represented by rational quadratic arcs, we may find an exact rational representation of a surface of revolution provided we can represent r(v), z(v) in rational form. Figure 28.7 gives an example. The most convenient way to define a surface of revolution is to prescribe the (planar) generating curve, or generatrix, given by

g(v) = [r(v), 0, z(v)]

T

and by the axis of revolution, in the same plane as g. Suppose g is given by its control polygon, knot sequence, and weight sequence. We can construct a surface of revolution such that each meridian consists *A misnomer, since B-splines are defined over a nonuniform knot sequence to begin with.

©1999 CRC Press LLC

FIGURE 28.7

A NURBS representation of a surface of revolution.

of four rational quadratic arcs. The resulting four control nets then form three concentric squares in the projection into the z = 0 plane. The control points at the squares’ midpoints are copies of the generatrix control points; their weights are those of the generatrix. The remaining weights, corresponding to the squares’ corners, are multiplied by cos (45°) = ( 2 ) ⁄ 2 . Note that although the generatrix can be defined over a knot sequence {vj } with only simple knots, this is not possible for the knots of the meridian circles; we have to use double knots, thereby essentially reducing it to the piecewise Bézier form.

References 1. Boehm, W., Inserting new knots into B-Spline curves, Computer Aided Design. 1980, 12, 4, pp. 199–201. 2. de Boor, C., On calculating with B-splines, J. Approx. Theory. 1972, 6, 1, pp. 50–62. 3. Farin, G., (Ed.), NURBS for Curve and Surface Design. SIAM, Philadelphia, 1991. 4. Farin, G., From conics to NURBS: a tutorial and survey, IEEE Computer Graphics and Applications. 1992, 12, 5, pp. 78–86. 5. Farin, G., NURB Curves and Surfaces. Peters, A.K., Boston, 1995. 6. Farin, G., Curves and Surfaces for Computer Aided Geometric Design, Fourth Edition. Academic Press, 1996. 7. Farouki, R. and Rajan, V., On the numerical condition of polynomials in Bernstein form. Computer Aided Geometric Design. 1987, 4, 3, pp. 191–216. 8. Faux, I. and Pratt, M., Computational Geometry for Design and Manufacture. Ellis Horwood, 1979. 9. Fiorot, J. and Jeannin, P., Rational Curves and Surfaces. Wiley, Chicester, 1992. Translated from the French by Harrison, M. 10. Floater, M., Derivatives of rational Bézier curves. Computer Aided Geometric Design. 1993, 10. 11. Hayes, J. and Holladay, J., The least-squares fitting of cubic splines to general data sets. J. Inst. Maths. Applics. 1974, 14, pp. 89–103. 12. Hoschek, J., Intrinsic parametrization for approximation, Computer Aided Geometric Design. 1988, 5, pp. 27–31. 13. Hoschek, J. and Lasser, D., Grundlagen der Geometrischen Datenverarbeitung. Teubner, B.G., Stuttgart, 1989. English translation: Fundamentals of Computer Aided Geometric Design . Peters, A.K., 1993. ©1999 CRC Press LLC

14. Lawson, C. and Hanson, G., Solving Least Squares Problems. SIAM, 1995. 15. Lee, E., Choosing nodes in parametric curve interpolation, Computer Aided Design. 21, 6, 1989. Presented at the SIAM Applied Geometry meeting, Albany, NY, 1987. 16. Piegl, L. and Tiller, W., The Book of NURBS. Springer Verlag, 1995. 17. Ramshaw, L., Blossoming: a connect-the-dots approach to splines, technical report, Digital Systems Research Center, Palo Alto, CA, 1987. 18. Worsey, A. and Farin, G., Contouring a bivariate quadratic polynomial over a triangle, Computer Aided Geometric Design. 1990, 7(1–4), pp. 337–352. 19. Yamaguchi, F., Curves and Surfaces in Computer Aided Geometric Design. Springer, 1988.

©1999 CRC Press LLC