# ANIMATION ROUTINES # MATH 2270 SECTION 3 # Treibergs # This file contains the routines for studying various linear transfolrmations. They will enable # you to see movies of linear transformations being repeatedly applied to a figure. They were # taken from J. Carlson and J. Johnson's text Multivariable Mathematics with Maple. # Copy this file to your home directory. Execute "XMAPLE file_name" to run these routines. It # might be necessary for you to recombine single line instructions which were split into # multiple lines by downloading. To do this, go the EDIT menu and use the JOIN command. To # complete your laboratory assignment, make appropriate modifications to these routines and add # descriptive and explanatory text. Label the diagrams illustrating the transformations. > with(linalg):# Load the linear algebra routines. > with(plots):# Load ther plotting routines. # # The routine "film" takes the list of figures generated by "iter" and outputs # a list of plot structures. The routine "iter" takes a vector function "f", a list of points "s" and a # number "n" and outputs a list of listl of points which consiasts of the list of points s, the list of # points after f is applied to s, the list of points of f applied to f(s), and so on up to n # iterations. # > film := proc(d) local r,s,t,ii , n, F; n:= nops(d); F := array(1..n); r:=rand()/10^12:s:=rand()/10^12:t:=rand()/10^12: for ii from 1 to n do F[ii]:= plot( d[ii],scaling=constrained, color=COLOR(RGB,r,s,t)); od; convert(F,list); end: iter := proc(f,s,n) local d, i , iq; d := array(0..n); d[0]:= s; for i from 1 to n do d[i] := map( f, d[i-1]); od; convert(d, list); end: # # The data structure being used is a "list", an ordered set of objects. A list is written with # brackets "[ obj1, pobj2, obj3,...]". Another data structure is a set, in which repetition and # order are ignored. For example, the set "{1,2,2,3}={3,1,2}" whereas the list "[1,2,2,3]" is # not the same as the list "[1,2,3]" nor the list "[3,2,2,1]". A point is a list of coordinate # numbers. A shape is represente by a list of points, for example the following list traces the # edge of a letter. You may wish to use your own figure. Be careful that that your figure doesn't # don't have unwanted symmetries! > letter:=[[1,1],[1,6],[2,6],[2,2],[4,2],[4,1],[1,1]]; # # Here is one way to plot the figure. Among other things, "plot" draws lines from point to point of # your figure. "scaling=constrained" indicates that the vertical and horizontal scale of the # drawing should be the same. "x=-1..9,y=-1..9" tells plot the edge coordintes of the drawing. > plot(letter,x=0..9,y=0..9,scaling=constrained,color=navy); # # Try it without the options. > plot(letter); # Here is another way to plot the figure: > polygonplot(letter,scaling=constrained,color=cyan); # # # TRANSLATIONS # Here is how to describe the translation transformation. Translation is not a linear # transformation(why?) We begin with the translation vector. > b:=vector([0.4,0.2]); # # Here is a way to describe functions. The function takes as input the vector x and gives as # output the translation of x in the b direction. > trans:= x -> evalm(x+b); # # "map" applies the function "trans" to each item in the list of points in "letter." > Tletter:=map(trans,letter); > plot(Tletter,x=0..9,y=0..9,scaling=constrained,color=magenta); # # It is hard to see the effect of translation side by side. In order to superimpose different plots, # we store the plots as plot data structures. Try it with ";" in place of the ":" if you dare! > P1:=plot(letter,x=-1..9,y=-1..9,color=navy): > P2:=plot(Tletter,x=-1..9,y=-1..9,color=magenta): > display({P1,P2},scaling=constrained); # # To get a feeling for transformations, Carlson and Johnson had the bright idea to animate the # effect by repeatedly applying the transformation to the figure. This routine applies "trans" to # "letter" three times. The output is a list of three letters (a list of lists of points.) > iter(trans,letter,3); # # Store the coordinates in a list of letters. # > letters:=iter(trans,letter,13): # # Then "film(letters)" plots the letters in a list of drawings. "display" with "insequence=true" # displays the drawings one after the other as a movie. > display(film(letters),insequence=true); # Since you can't hand in a movie, the next best thing is to hand in a picture with the various # frames superimposed. Be sure to label your starting figure and the sequencing of pictures. > display(film(letters)); # # DILATIONS -- CONTRACTIONS # Scalar multiplying each vertex of the figure by a factor c enlarges of shrinks the figure. > c:=0.9; > dilat:= x-> scalarmul(x,c); > letters:=iter(dilat,letter,9): > display(film(letters),insequence=true); # # ROTATIONS # We define the rotations matrix as a function of the angle. > R:=theta->matrix([[cos(theta),-sin(theta)],[sin(theta),cos(theta)]]); # Then define the transformation which rotates points Pi/6 radians. > rot:=x->multiply(R(Pi/6),x); > letters:=iter(rot,letter,12): > display(film(letters),insequence=true); # # REFLECTIONS # We describe reflection across any line. Choose a vector which is perpendicular to the mirror # line. # > u:=vector([4,3]); # # Normalize it to unit length. > u:=scalarmul(u,1/sqrt(innerprod(u,u))); > refl:=x->evalm(x-scalarmul(u,2*innerprod(u,x))); > P1:=plot(letter,x=-1..9,y=-1..9,color=red): # "implicitplot" plots an equation, in this case, the points perpendicular to u. > Pmirror:=implicitplot(innerprod(u,vector([x,y]))=0, x=-9..9,y=-9..9,color=blue): > Rletter:=map(refl,letter): > P2:=plot(Rletter,x=-9..9,y=-9..9,color=maroon): > display({P1,P2,Pmirror},scaling=constrained); # # N-GON -- ANOTHER FIGURE # This is created by "seq" which creates a sequence of objects for the indicated values of i. # In this case, the objects are the vertices of a regular n-gon. > > ngon:= n -> [seq([ cos(2*Pi*i/n), sin(2*Pi*i/n) ], i = 0..n)]: # # For example, to see the list of vertices of an equilateral triangle > ngon(3); # # SHEARS # This time we introduce the matrix which skews a figure. We illustrate on a hexagon > She:=k->matrix([[1,k],[0,1]]); > shear:=x-> multiply(She(0.2),x); > ngons:=iter(shear,ngon(6),10): > display(film(ngons),insequence=true);