next up previous contents
Next: Architecture and the Up: Maple V Release Previous: Numerical Computation

Plotting



> with(plots):  with(plottools):
> head  := ellipse( [0,0.5], 0.7, 0.9, color=black ):
> eyes  := disk(  [0.4,0.4],0.1, color=blue ),
>          disk( [-0.4,0.4],0.1, color=blue ):
> mouth := arc(  [0,0.1], 0.35, 5/4*Pi..7/4*Pi,
>          color=red, thickness=7 ):
> nose  := line( [0,0.35], [0,-0.1], color=black, thickness=5 ):
> display( {head, eyes, nose, mouth},
>   scaling=constrained, axes=none ); # happy face

A spectrum of arrows in different HUE colors is created below.

> a[0] := display( arrow( [0,0], [1,0], 0.1, 0.4, 0.2 ),
>   color=COLOR(HUE,0), axes=none, scaling=constrained ): 
> for i to 15 do
>   a[i] := subs( COLOR(HUE,0) = COLOR(HUE,i/16), 
>   translate( scale( 
>       rotate( a[0], i*Pi/8 ), 
>     (16-i)/16, (16-i)/16 ), 
>   i/16*cos(Pi*i/8), i/16*sin(Pi*i/8) ) )
> od: 
> display( [ seq(a[i],i=0..15) ], scaling=constrained );

A spectacular implicit plot with contours is the following example in spherical coordinates.

> r * ( 4 + 2*cos(3*theta) - cos(3*theta+2*phi) 
>   - cos(-3*theta+2*phi) + 2*cos(2*phi)) = 2;

> implicitplot3d( ", r=0..2, theta=0..2*Pi, phi=0..Pi,
>   coords=spherical, grid=[10,40,40],
>   style=patchcontour, thickness=2, orientation=[35,30] );

The following fun example of a look-alike of the Canadian flag illustrates transformations from two-dimensional to three-dimensional graphics and other mappings on graphics objects. We start with the maple leaf.

> S := t -> 100/(100+(t-Pi/2)^8): # for scaling 
> R := t -> S(t)*(2-sin(7*t)-cos(30*t)/2):
> mapleleaf := plot( [ R, t->t, -Pi/2..3/2*Pi ],
>   coords=polar, axes=none, color=red, numpoints=1000 ):

These commands create a closed curve resembling the Maple leaf. In the Canadian flag, the inner space should be colored red. The easiest way to do this is to replace the CURVES object name by POLYGONS. Moreover, we add two rectangles to get a plane Canadian flag and a border to indicate the white background (we assume that the default background color is white).

> mapleleaf := subs( CURVES=POLYGONS, mapleleaf ):
> rectangles := rectangle([-5,-1],[-3,4], color=red ), 
>               rectangle([3,-1],[5,4],color=red ):
> border := plot( {-1,4},-3..3, color=black ):
> flag2d := display( [ mapleleaf, rectangles, border ], 
>   view=[-5..5,-1..4], scaling=constrained ):
> flag2d;

Finally, we use the transform procedure from the plottools package with the mapping to convert the two-dimensional graphics object into a three-dimensional one. Finally, we apply the mapping to project the plane flag onto the sine surface.

> flag3d := transform( (x,y,z) -> [x,y,0] )(flag2d):
> wavingflag3d := transform( (x,y) -> [x,y,1+1/15*sin(x)] )(flag3d):
> display( { flag3d, wavingflag3d }, 
>   scaling=unconstrained, orientation=[-110,60],axes=none,
>   style=patchnogrid, shading=none );





Andre Heck
Thu Jan 4 12:27:55 MET 1996