CH-01 (523167), страница 6
Текст из файла (страница 6)
If the rotationis by an angle x or y, then {P'} = [Rx]{P} or {P'} = [Ry]{P} where [Rx] = [Tx]Tand [Ry] = [Ty]T.Having discussed about transformations and rotations of coordinate systems,we are ready to utilize the derived formulas to demonstrate the concept of animation. Motion can be simulated by first generating a series of rotated views ofa three-dimensional object, and showing them one at a time. By erasing eachdisplayed view and then showing the next one at an adequate speed, a smoothmotion of the object is achievable to produce the desired animation.
ProgramAnimate1.m is developed to demonstrate this concept of animation by using a4 2 3 brick and rotating it about the x-axis by an angle of 25° and thenrotating about the y-axis as many revolutions as desired. The front side of theblock (x-y plane) is marked with a character F, and the right side (y-z plane) ismarked with a character R, and the top side (x-z plane) is marked with a characterT for helping the viewer to have a better three-dimensional perspective of therotated brick (Figure 4).
The x-rotation prior to y-rotation is needed to tilt the topside of the brick toward the front. The speed of animation is controlled by aparameter Damping. This parameter and the desired number of y-revolutions,Ncycle, are both to be interactively specified by the viewer (Figure 5).© 2001 by CRC Press LLCFIGURE 4.
The characters F, R, and T help the viewer to have a better three-dimensionalperspective of the rotated brick.FIGURE 5. The speed of animation is controlled by a parameter Damping. This parameter andthe desired number of y-revolutions, Ncycle, are both to be interactively specified by the viewer.© 2001 by CRC Press LLCFUNCTION ANIMATE1(NCYCLE,DAMPING)Notice that the coordinates for the corners of the brick are defined in arrays xb,yb, and zb. The coordinates of the points to be connected by linear segments fordrawing the characters F, R, ant T are defined in arrays xf, yf, and zf, and xr, yr,and zr, and xt, yt, and zt, respectively.The equations in deriving [Rx] ( = [Tx]T) and [Ry] ( = [Ty]T) are applied for xand y- rotations in the above program.
Angle increments of 5 and 10° are arrangedfor the x- and y-rotations, respectively. The rotated views are plotted using the newcoordinates of the points, (xbn,ybn,zbn), (xfn,yfn,zfn), etc. Not all of these newarrays but only those needed in subsequent plot are calculated in this m file.MATLAB command clg is used to erase the graphic window before a newrotated view the brick is displayed. The speed of animation is retarded by the “hold”loops in both x- and y-rotations involving the interactively entered value of theparameter Damping. The MATLAB command pause enables Figure 4 to be readand requires the viewer to press any key on the keyboard to commence the animation.Notice that a statement begins with a % character making that a comment statement,and that % can also be utilized for spacing purpose.The xs and ys arrays allow the graphic window to be scaled by plotting themand then held (by command hold) so that all subsequent plots are using the same© 2001 by CRC Press LLCFIGURE 6.
Animation of a rotating brick.scales in both x- and y-directions. The values in xs and ys arrays also control whereto properly place the texts in Figure 4 as indicated in the text statements.QUICKBASIC VERSIONA QuickBASIC version of the program Animate1.m called Animate1.QB alsois provided. It uses commands GET and PUT to animate the rotation of the 4 3 2 brick. More features have been added to show the three principal views of thebrick and also the rotated view at the northeast corner of screen, as illustrated inFigure 6.The window-viewport transformation of the rotated brick for displaying on thescreen is implemented through the functions FNTX and FNTY. The actual rangesof the x and y measurements of the points used for drawing the brick are describedby the values of V1 and V2, and V3 and V4, respectively.
These ranges are mappedonto the screen matching the ranges of W1 and W2, and W4 and W3, respectively.The rotated views of the brick are stored in arrays S1 through S10 using theGET command. Animation retrieves these views by application of the PUT command. Presently, animation is set for 10 y-swings (Ncycle = 10 in the programAnimate1.m, arranged in Line 600). The parameter Damping described in theprogram Animate1.m here is set equal to 1500 (in Line 695).© 2001 by CRC Press LLC© 2001 by CRC Press LLC1.6 PROBLEMSMATRIX ALGEBRA1.
Calculate the product [A][B][C] by (1) finding [T] = [A][B] and then[T][C], and (2) finding [T] = [B][C] and then [A][T] where:1[A] = 425366[B] = 42531 −1−3[C ] = −2 −42. Calculate [A][B] of the two matrices given above and then take thetranspose of product matrix. Is it equal to the product of [B]T[A]T?3. Are ([A][B][C])T and the product [C]T[B]T[A]T identical to each other?© 2001 by CRC Press LLC4. Apply the QuickBASIC and FORTRAN versions of the program MatxAlgb to verify the results of Problems 1, 2, and 3.5.
Repeat Problem 4 but use MATLAB.6. Apply the program MatxInvD to find [C]–1 of the matrix [C] given inProblem 1 and also to ([C]T)–1. Is ([C]–1)T equal to ([C]T)–1?7. Repeat Problem 6 but use MATLAB.8. For statistical analysis of a set of N given data X1, X2, …, XN, it is oftennecessary to calculate the mean, m, and standard deviation, 5, by use ofthe formulas:m=1(X + X2 + … + X N )N 1and[]2221σ = ( X1 − m ) + ( X 2 − m ) + … + ( X N − m ) N0.5Use indicial notation to express the above two equations and then developa subroutine meanSD(X,N,RM,SD) for taking the N values of X tocompute the real value of mean, RM, and standard deviation, SD.9.
Express the ith term in the following series in indicial notation and thenwrite an interactive program SinePgrm allowing input of the x value tocalculate sin(x) by terminating the series when additional term contributesless than 0.001% of the partial sum of series in magnitude:Sin x =x1 x3 x 5− + −…1! 3! 5!Notice that Sin(x) is an odd function so the series contains only terms ofodd powers of x and the series carries alternating signs. Compare theresult of the program SinePgrm with those obtained by application of thelibrary function Sin available in FORTRAN and QuickBASIC.10. Same as Problem 9, but for the cosine series:Cos x = 1 −x2 x 4 x6+−+…2! 4! 6!Notice that Cos(x) is an even function so the series contains only termsof even powers of x and the series also carries alternating signs.11.
Repeat Problem 4 but use Mathematica.12. Repeat Problem 6 but use Mathematica.© 2001 by CRC Press LLCGAUSS1. Run the program GAUSS to solve the problem:14 72583 x1 2 6 x 2 = 8 10 x3 142. Run the program GAUSS to solve the problem:04 72583 x1 −1 6 x 2 = 8 9 x3 14 What kind of problem do you encounter? “Divided by zero” is the message! This happens because the coefficient associated with x1 in the firstequation is equal to zero and the normalization in the program GAUSScannot be implemented.
In this case, the order of the given equationsneeds to be interchanged. That is to put the second equation on top orfind below the first equation an equation which has a coefficient associatedwith x1 not equal to zero and is to be interchanged with the first equation.This procedure is called “pivoting.” Subroutine GauJor has such a featureincorporated, apply it for solving the given matrix equation.3. Modify the program GAUSS by following the Gauss-Jordan eliminationprocedure and excluding the back-substitution steps. Name this new program GauJor and test it by solving the matrix equations given in Problems1 and 2.4.
Show all details of the normalization, elimination, and backward substitution steps involved in solving the following equations by application ofGaussian Elimination method:4x1 + 2x2 – 3x3 = 85x1 – 3x2 + 7x3 = 26–x1 + 9x2 – 8x3 = –105. Present every normalization and elimination steps involved in solving thefollowing system of linear algebraic equations by the Gaussian Elimination Method:5x1 – 2x2 + 2x3 = 9, –2x1 + 7x2 – 2x3 = 9, and 2x1 – 2x2 + 9x3 = 41© 2001 by CRC Press LLC6.