[ Pobierz całość w formacie PDF ]
.The curve consists of n - 1 segments and the twoauxiliary control points of each segment are calculated automatically.Such a curve is usually pleasing to the eye and rarely needs to be edited.However,if it is not satisfactory, it can be modified by moving the auxiliary control points.Thereare 2(n - 1) of them, which allows for flexible control.A good program should displaythe auxiliary points and should make it easy for the user to grab and move any of them.The well-known drawing program Adobe Illustrator [Adobe 04] uses a similar ap-proach.The user specifies points with the mouse.At each point Pi, the user presses themouse button to fix Pi, then drags the mouse before releasing the button, which definestwo symmetrical points, X (following Pi) and Y (preceding it).Releasing the button isa signal to the program to draw the segment from Pi-1 to Pi (Figure 6.17).releaseXipressdragPiYi-1Xi-1Bezier segmentPi-1Figure 6.17: Construction of Xi and Yi by Click and Drag.Example: We apply this method to the six points P0 =(1/2, 0), P1 =(1/2, 1/2),P2 =(0, 1), P3 =(1, 3/2), P4 =(3/2, 1), and P5 =(1, 1/2).The six points yield three214 6.Bzier Approximationcurve segments and the main step is to calculate the two intermediate points for eachof the three segments.This is trivial and it results in:X1 = P1 +(P2 - P0)/6 =(5/12, 2/3), Y1 =P2 - (P3 - P1)/6 =(-1/12, 5/6),X2 = P2 +(P3 - P1)/6 =(1/12, 7/6), Y2 =P3 - (P4 - P2)/6 =(3/4, 3/2),X3 = P3 +(P4 - P2)/6 =(5/4, 3/2), Y3 =P4 - (P5 - P3)/6 =(3/2, 7/6).Once the points are available, the three segments can easily be calculated.Each is acubic Bzier segment based on a group of four points.The groups are[P1, X1, Y1, P2], [P2, X2, Y2, P3], [P3, X3, Y3, P4],and the three curve segments areP1(t) =(1 - t)3P1 +3t(1 - t)2X1 +3t2(1 - t)Y1 + t3P2= (2 - t - 5t2 +4t3)/4, (1 + t)/2 ,P2(t) =(1 - t)3P2 +3t(1 - t)2X2 +3t2(1 - t)Y2 + t3P3= (t +7t2 - 4t3)/4, (2 + t + t2 - t3)/2 ,P3(t) =(1 - t)3P3 +3t(1 - t)2X3 +3t2(1 - t)Y3 + t3P4= (4 + 3t - t3)/4, (3 - 2t2 + t3)/2.The 12 points and the three segments are shown in Figure 6.18 (where the segmentshave been separated intentionally), as well as the code for the entire example.6.13 An Interpolating Bzier Curve: IIThe approach outlined in this section calculates an interpolating Bzier curve by solvingequations.Given a set of n+1 data points Q0, Q1,., Qn, we select n+1 values ti suchthat P(ti) =Qi.We require that whenever t reaches one of the values ti, the curve willpass through a point Qi.The values ti don t have to be equally spaced, which providescontrol over the speed of the curve.All that s needed to calculate the curve is tocompute the right set of n+1 control points Pi.This is done by setting and solving theset of n + 1 linear equations P(t0) =Q0, P(t1) =Q1,., P(tn) =Qn that s expressedin matrix notation as follows:# # # # # #Bn,0(t0) Bn,1(t0).Bn,n(t0)P0 Q0Bn,0(t1) Bn,1(t1).Bn,n(t1)P1 Q1# # # # # ## # # # # #=.(6.28).# # # # # #.Pn QnBn,0(tn) Bn,1(tn).Bn,n(tn)This set of equations can be expressed as MP = Q and it is easily solved by invertingM numerically.The solution is P = M-1Q.If we select t0 = 0, the top row ofEquation (6.28) yields P0 = Q0.Similarly, if we select tn = 1, the bottom row of6.13 An Interpolating Bzier Curve: II 215Y2XP 331.4P (t)3P (t)2X21.2Y3P1 4P2Y10.8P (t)1X10.6P1P50.40.2P0.25 0.5 0.75 1 1.25 1.5(* Interpolating Bezier Curve: I *)Clear[p0,p1,p2,p3,p4,p5,x1,x2,x3,y1,y2,y3,c1,c2,c3,g1,g2,g3,g4];p0={1/2,0}; p1={1/2,1/2}; p2={0,1};p3={1,3/2}; p4={3/2,1}; p5={1,1/2};x1=p1+(p2-p0)/6;x2=p2+(p3-p1)/6;x3=p3+(p4-p2)/6;y1=p2-(p3-p1)/6;y2=p3-(p4-p2)/6;y3=p4-(p5-p3)/6;c1[t_]:=Simplify[(1-t)^3 p1+3t(1-t)^2 x1+3t^2(1-t) y1+t^3 p2]c2[t_]:=Simplify[(1-t)^3 p2+3t(1-t)^2 x2+3t^2(1-t) y2+t^3 p3]c3[t_]:=Simplify[(1-t)^3 p3+3t(1-t)^2 x3+3t^2(1-t) y3+t^3 p4]g1=ListPlot[{p0,p1,p2,p3,p4,p5,x1,x2,x3,y1,y2,y3},Prolog->AbsolutePointSize[4], PlotRange->All,AspectRatio->Automatic, DisplayFunction->Identity]g2=ParametricPlot[c1[t], {t,0,.9}, DisplayFunction->Identity]g3=ParametricPlot[c2[t], {t,0.1,.9}, DisplayFunction->Identity]g4=ParametricPlot[c3[t], {t,0.1,1}, DisplayFunction->Identity]Show[g1,g2,g3,g4, DisplayFunction->$DisplayFunction]Figure 6.18: An Interpolating Bzier Curve.216 6.Bzier ApproximationEquation (6.28) yields Pn = Qn.This decreases the number of equations from n +1 ton - 1.The disadvantage of this approach is that any changes in the ti s require a recalcu-lation of M and, consequently, of M-1.If controlling the speed of the curve is not important, we can select the n +1equally-spaced values ti = i/n.Equation (6.28) can now be written# # # # # #Bn,0(0/n) Bn,1(0/n).Bn,n(0/n)P0 Q0Bn,0(1/n) Bn,1(1/n).Bn,n(1/n)P1 Q1# # # # # ## # # # # #=.(6.29).# # # # # #.Pn QnBn,0(n/n) Bn,1(n/n).Bn,n(n/n)Now, if the data points Qi are moved, matrix M (or, rather, M-1) doesn t have to berecalculated.If we number the rows and columns of M 0 through n, then a generalelement of M is given byn n!(n - i)n-jijMij = Bn,j(i/n) = (i/n)j(1 - i/n)n-j =.j j!(n - j)!nnSuch elements can be calculated, if desired, as exact rational integers, instead of (ap-proximate) floating-point numbers.Example: We use Equation (6.29) to compute the interpolating Bzier curve thatpasses through the four points Q0 =(0, 0), Q1 =(1, 1), Q2 =(2, 1), and Q3 =(3, 0).Since the curve has to pass through the first and last point, we get P0 = Q0 =(0, 0)and P3 = Q3 =(3, 0).Since the four given points are equally spaced, it makes senseto assume that P(1/3) = Q1 and P(2/3) = Q2.We therefore end up with the twoequations3(1/3)(1 - 1/3)2P1 + 3(1/3)2(1 - 1/3)P2 +(1/3)3(3, 0) =(1, 1),3(2/3)(1 - 2/3)2P1 + 3(2/3)2(1 - 2/3)P2 +(2/3)3(3, 0) =(2, 1),that are solved to yield P1 =(1, 3/2) and P2 =(2, 3/2).The curve isP(t) =(1 - t)3(0, 0) + 3t(1 - t)2(1, 3/2) + 3t2(1 - t)(2, 3/2) + t3(3, 0).Exercise 6.20: Plot the curve and the eight points.6.14 Nonparametric Bzier Curves 2176.14 Nonparametric Bzier CurvesThe explicit representation of a curve (Section 1.3) has the familiar form y = f(x) [ Pobierz całość w formacie PDF ]
zanotowane.pl doc.pisz.pl pdf.pisz.pl centka.pev.pl
.The curve consists of n - 1 segments and the twoauxiliary control points of each segment are calculated automatically.Such a curve is usually pleasing to the eye and rarely needs to be edited.However,if it is not satisfactory, it can be modified by moving the auxiliary control points.Thereare 2(n - 1) of them, which allows for flexible control.A good program should displaythe auxiliary points and should make it easy for the user to grab and move any of them.The well-known drawing program Adobe Illustrator [Adobe 04] uses a similar ap-proach.The user specifies points with the mouse.At each point Pi, the user presses themouse button to fix Pi, then drags the mouse before releasing the button, which definestwo symmetrical points, X (following Pi) and Y (preceding it).Releasing the button isa signal to the program to draw the segment from Pi-1 to Pi (Figure 6.17).releaseXipressdragPiYi-1Xi-1Bezier segmentPi-1Figure 6.17: Construction of Xi and Yi by Click and Drag.Example: We apply this method to the six points P0 =(1/2, 0), P1 =(1/2, 1/2),P2 =(0, 1), P3 =(1, 3/2), P4 =(3/2, 1), and P5 =(1, 1/2).The six points yield three214 6.Bzier Approximationcurve segments and the main step is to calculate the two intermediate points for eachof the three segments.This is trivial and it results in:X1 = P1 +(P2 - P0)/6 =(5/12, 2/3), Y1 =P2 - (P3 - P1)/6 =(-1/12, 5/6),X2 = P2 +(P3 - P1)/6 =(1/12, 7/6), Y2 =P3 - (P4 - P2)/6 =(3/4, 3/2),X3 = P3 +(P4 - P2)/6 =(5/4, 3/2), Y3 =P4 - (P5 - P3)/6 =(3/2, 7/6).Once the points are available, the three segments can easily be calculated.Each is acubic Bzier segment based on a group of four points.The groups are[P1, X1, Y1, P2], [P2, X2, Y2, P3], [P3, X3, Y3, P4],and the three curve segments areP1(t) =(1 - t)3P1 +3t(1 - t)2X1 +3t2(1 - t)Y1 + t3P2= (2 - t - 5t2 +4t3)/4, (1 + t)/2 ,P2(t) =(1 - t)3P2 +3t(1 - t)2X2 +3t2(1 - t)Y2 + t3P3= (t +7t2 - 4t3)/4, (2 + t + t2 - t3)/2 ,P3(t) =(1 - t)3P3 +3t(1 - t)2X3 +3t2(1 - t)Y3 + t3P4= (4 + 3t - t3)/4, (3 - 2t2 + t3)/2.The 12 points and the three segments are shown in Figure 6.18 (where the segmentshave been separated intentionally), as well as the code for the entire example.6.13 An Interpolating Bzier Curve: IIThe approach outlined in this section calculates an interpolating Bzier curve by solvingequations.Given a set of n+1 data points Q0, Q1,., Qn, we select n+1 values ti suchthat P(ti) =Qi.We require that whenever t reaches one of the values ti, the curve willpass through a point Qi.The values ti don t have to be equally spaced, which providescontrol over the speed of the curve.All that s needed to calculate the curve is tocompute the right set of n+1 control points Pi.This is done by setting and solving theset of n + 1 linear equations P(t0) =Q0, P(t1) =Q1,., P(tn) =Qn that s expressedin matrix notation as follows:# # # # # #Bn,0(t0) Bn,1(t0).Bn,n(t0)P0 Q0Bn,0(t1) Bn,1(t1).Bn,n(t1)P1 Q1# # # # # ## # # # # #=.(6.28).# # # # # #.Pn QnBn,0(tn) Bn,1(tn).Bn,n(tn)This set of equations can be expressed as MP = Q and it is easily solved by invertingM numerically.The solution is P = M-1Q.If we select t0 = 0, the top row ofEquation (6.28) yields P0 = Q0.Similarly, if we select tn = 1, the bottom row of6.13 An Interpolating Bzier Curve: II 215Y2XP 331.4P (t)3P (t)2X21.2Y3P1 4P2Y10.8P (t)1X10.6P1P50.40.2P0.25 0.5 0.75 1 1.25 1.5(* Interpolating Bezier Curve: I *)Clear[p0,p1,p2,p3,p4,p5,x1,x2,x3,y1,y2,y3,c1,c2,c3,g1,g2,g3,g4];p0={1/2,0}; p1={1/2,1/2}; p2={0,1};p3={1,3/2}; p4={3/2,1}; p5={1,1/2};x1=p1+(p2-p0)/6;x2=p2+(p3-p1)/6;x3=p3+(p4-p2)/6;y1=p2-(p3-p1)/6;y2=p3-(p4-p2)/6;y3=p4-(p5-p3)/6;c1[t_]:=Simplify[(1-t)^3 p1+3t(1-t)^2 x1+3t^2(1-t) y1+t^3 p2]c2[t_]:=Simplify[(1-t)^3 p2+3t(1-t)^2 x2+3t^2(1-t) y2+t^3 p3]c3[t_]:=Simplify[(1-t)^3 p3+3t(1-t)^2 x3+3t^2(1-t) y3+t^3 p4]g1=ListPlot[{p0,p1,p2,p3,p4,p5,x1,x2,x3,y1,y2,y3},Prolog->AbsolutePointSize[4], PlotRange->All,AspectRatio->Automatic, DisplayFunction->Identity]g2=ParametricPlot[c1[t], {t,0,.9}, DisplayFunction->Identity]g3=ParametricPlot[c2[t], {t,0.1,.9}, DisplayFunction->Identity]g4=ParametricPlot[c3[t], {t,0.1,1}, DisplayFunction->Identity]Show[g1,g2,g3,g4, DisplayFunction->$DisplayFunction]Figure 6.18: An Interpolating Bzier Curve.216 6.Bzier ApproximationEquation (6.28) yields Pn = Qn.This decreases the number of equations from n +1 ton - 1.The disadvantage of this approach is that any changes in the ti s require a recalcu-lation of M and, consequently, of M-1.If controlling the speed of the curve is not important, we can select the n +1equally-spaced values ti = i/n.Equation (6.28) can now be written# # # # # #Bn,0(0/n) Bn,1(0/n).Bn,n(0/n)P0 Q0Bn,0(1/n) Bn,1(1/n).Bn,n(1/n)P1 Q1# # # # # ## # # # # #=.(6.29).# # # # # #.Pn QnBn,0(n/n) Bn,1(n/n).Bn,n(n/n)Now, if the data points Qi are moved, matrix M (or, rather, M-1) doesn t have to berecalculated.If we number the rows and columns of M 0 through n, then a generalelement of M is given byn n!(n - i)n-jijMij = Bn,j(i/n) = (i/n)j(1 - i/n)n-j =.j j!(n - j)!nnSuch elements can be calculated, if desired, as exact rational integers, instead of (ap-proximate) floating-point numbers.Example: We use Equation (6.29) to compute the interpolating Bzier curve thatpasses through the four points Q0 =(0, 0), Q1 =(1, 1), Q2 =(2, 1), and Q3 =(3, 0).Since the curve has to pass through the first and last point, we get P0 = Q0 =(0, 0)and P3 = Q3 =(3, 0).Since the four given points are equally spaced, it makes senseto assume that P(1/3) = Q1 and P(2/3) = Q2.We therefore end up with the twoequations3(1/3)(1 - 1/3)2P1 + 3(1/3)2(1 - 1/3)P2 +(1/3)3(3, 0) =(1, 1),3(2/3)(1 - 2/3)2P1 + 3(2/3)2(1 - 2/3)P2 +(2/3)3(3, 0) =(2, 1),that are solved to yield P1 =(1, 3/2) and P2 =(2, 3/2).The curve isP(t) =(1 - t)3(0, 0) + 3t(1 - t)2(1, 3/2) + 3t2(1 - t)(2, 3/2) + t3(3, 0).Exercise 6.20: Plot the curve and the eight points.6.14 Nonparametric Bzier Curves 2176.14 Nonparametric Bzier CurvesThe explicit representation of a curve (Section 1.3) has the familiar form y = f(x) [ Pobierz całość w formacie PDF ]