Discovering Curves and Surfaces Maple® with Springer Science+Business Media, LLC Grazyna Klimek Maciej Klimek Discovering Curves and Surfaces Maple® with With 1 1 8 Black & White Illustrations and 26 Color Plates EXIRA MATERIALS extras.springer.com Springer Grazyna Klimek Maciej Klimek Gustaf Kjellbergsv. 18 Department of Mathematics 756-43 Uppsala Uppsala University Sweden P.O. Box480 751-06 Uppsala Sweden Additional material to this book can be downloaded from http://extra.springer.com. Library of Congress Cataloging-in-Publication Data Grazyna Klimek Discovering curves and surfaces with Maple I Grazyna Klimek, Maciej Klimek. p. em. Includes index. ISBN 978-l-4612-7301-l ISBN 978-l-4612-1826-5 (eBook) DOl .10.1007/978-1-4612-1826-5 1. Curves, Algebraic-Data processing. 2. Surfaces-Data processing. 3. Computer-aided design. 4. Maple (Computer file). I. Klimek, Maciej. II. Title. QA567.K58 1997 516.3'52'02855369-dc21 97-1016 Printed on acid-free paper. © 1997 Springer Science+ Business Media New York Originally published by Springer-Verlag New York, Inc. in 1997 Softcover reprint of the hardcover 1st edition 1997 All rights reserved. This work may not be translated or copied in whole or in part without the written per mission of the publisher Springer Science+Business Media, LLC except for brief excerpts in connection with reviews or scholarly analysis. Use in connection with any form of information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed is forbidden. The use of general descriptive names, trade names, trademarks, etc., in this publication, even if the former are not especially identified, is not to be taken as a sign that such names, as understood by the Trade Marks and Merchandise Marks Act, may accordingly be used freely by anyone. Production managed by Robert Wexler; manufacturing supervised by Johanna Tschebull. Photocomposed copy prepared by the Bartlett Press, Marietta, GA, using the author's LaTeX files. 9 8 7 6 5 4 3 2 1 ISBN 978-l-4612-7301-1 To my parents Graiyna To my mother in memoriam and to my father Maciej Contents Introduction ix 1. Maple Preliminaries 1 1.1 General Comments 1 1.2 Basic Plots 3 1.3 Accessing Plotting Structures 6 2. Two-Dimensional Plots 9 2.1 Basic Graphs 9 2.2 Additional Options 19 2.3 Maps of Surfaces 22 3. Geometric Manipulation 27 3.1 Affine Transformations in Two Dimensions 27 3.2 Affine Transformations in Three Dimensions 35 3.3 Coordinate Systems 41 3.4 Perspective 45 3.5 Shadow and Radial Projections 50 3.6 Matrix Notation 54 3.7 General Transformations of Plots 58 4. Three-Dimensional Plots 61 4.1 Basic Three-Dimensional Plots 61 4.2 Overview of Plotting Options 72 4.3 Color 76 viii • Contents 4.4 Lighting 85 4.5 PLOT and PLOT3D Data Structures 88 4.6 Examples 97 5. Functions and Procedures 105 5.1 Elementary Functions 105 5.2 Graphics and Functions 107 5.3 Procedures 109 5.4 Interpolation 119 5.5 Iteration and Fractals 125 5.6 Mixing Curves and Surfaces 129 6. Animations 135 6.1 Overview of Animation Commands 135 6.2 Animations in Two-Dimensions 140 6.3 Animations in Three-Dimensions 147 7. The plottools Package 165 7.1 The plottools Objects 166 7.2 Plot Transformations 169 8. Specialized Graphics 177 8.1 Graphing Complex Functions 177 8.2 Differential Equations 184 8.3 Miscellaneous Commands 192 9. Saving and Exporting Maple Graphics 199 9.1 Saving, Editing, and Printing 199 9.2 External Rendering and Ray Tracing 201 Index 211 Introduction With the arrival of powerful desktop computers and affordable software, computer graphics have become omnipresent. Within a relatively short time they have reached a new level of sophistication. Endless possibilities of image creation and manipulation have opened for the graphics artist and the technical or scientific illustrator alike. Most of the software used in these areas has been discussed in numerous books and articles, but some other methods and systems, like the ones described in this book, are largely unexplored. This book is addressed to several different groups of readers. We hope that students and practitioners of engineering, mathematics, computer sci ence, scientific visualization, and graphical art and design may find it use ful. The prerequisites are minimal. Apart from very limited familiarity with Maple run under Microsoft Windows, not much experience with comput ers is required. Most of the book is built around fairly basic mathematics. Therefore, it is suitable for anyone who needs to plot any type of curves and surfaces, whether to visualize scientific data or for aesthetic pleasure. Basic principles, important in computer graphics in general, are also dis cussed: primarily lighting, color, perspective projections, simple geometric transformations, and splines. More specialized graphics, like those related to differential equations, vector fields, conformal mappings, fractals, and iteration of functions are represented as well. We have tried to distribute topics evenly, so that all readers can learn how to use the tool of our choice-Maple-to produce the results they want. Over the last few years Maple has gained remarkable popularity as one of the most comprehensive symbolic manipulation packages. Apart from symbolic algebra, it offers an impressive array of graphical tools for de signing and producing a wide variety of two- and three-dimensional plots. x • Introduction Yet, when looking at publications illustrated with the help of Maple, one is often surprised how few of Maple's options are actually used. The main objective of this book is to show the reader, in a very practical way, how to unleash the graphical power of Maple. The reader is guided step by step from elementary curves to complex surfaces, like those presented on the cover of this book. One of the more attractive aspects of creating graph ics in Maple is their portability. The main three elements of a plot-the shape, the colors, and the lighting-are described by mathematical for mulas. As such, they are software and hardware independent and can be easily adapted to other systems; for instance, those offering better render ing. Furthermore, the principles governing these three elements, as well as the perspective projections, are universal and apply to computer graphics in general, whether learned through Maple or not. Ever since the publication of the thought-provoking Fractal Geometry of Nature by Benoit Mandcdbrot in the early 1980s, mathematical graph ics have been invariably associated with fractals. The latter have filtered through to popular culture and have been reproduced on countless home computers all over the world. Fractals have created a surprisingly varied and colorful counterbalance to visually dull images conventionally associ ated with geometry: lines, planes, triangles, circles and so on. They have also provided a basis for mathematical descriptions of complicated natural shapes, like clouds,certain plants, or landscapes. But the suggestion that all natural forms are essentially fractal is a vast exaggeration. The shape of the human body (observed without a microscope) provides a prime coun terexample. Animals, plants, and minerals provide many other examples. The outer layer, or boundary, of many biological as well as artificially cre ated forms can be described mathematically as a surface (with varying degrees of smoothness). In this book we show the reader how to create a multitude of interesting and aesthetically pleasing surfaces. Contempo rary mathematics, as a discipline, is devoid of any interest in visual beauty of the surfaces it investigates.1 Instead, totally verbalized and symbolic descriptions of surfaces (and other more general objects) are studied for their symbolically or numerically tangible properties. This is why creating beautiful, mathematically generated surfaces means entering a relatively new territory, which is accessible to all those interested. Such a pursuit can be contrasted with the modeling of sampled curves and surfaces created by nonmathematical means, with the help of splines or other numerical methods. We would like to take a moment to explain certain assumptions we have chosen to adopt. Our intention is to provide the reader with a complete I This, however, cannot be said about some mathematicians who are fascinated by the visual beauty of new and old geometric entities! Introduction • xi and comprehensive account of the subject, structured in such a way that it can also serve as a pragmatic do-it-yourself guide. The best and most biologically natural way of learning is through imitation. That is why we place a strong emphasis on practical examples, showing as many different graphical options as possible. We have also decided to concentrate only on the type of graphics for which Maple can be regarded as a natural medium. For instance, business charts are not discussed here, because many easily accessible business graphics programs provide better and faster tools for producing them. We also describe how to export graphics from Maple to other programs and how to edit these pictures with the help of image manipulation software. Although Maple can run on various platforms, it will be assumed throughout the book that the reader uses Maple V (Release 3 or 4) for Microsoft Windows (3.xx or 95). Modifications required for other plat forms are minimal and are not discussed here. We would like to add a few words about the writing and production of this book. The typesetting was done in Jb.TEX. The color Maple graph ics were copied to the clipboard and then converted to the TIFF format. The monochrome pictures were exported from Maple as Encapsulated PostScript files and then incorporated in the Jb.TEX files with the help of Trevor Darrell's PsfigffEXmacro package. Subsequently, the DVI files were converted via Tomas Rokicki's DVIPS program into PostScript files. All the Maple code segments presented here are also supplied on the accompanying disk. This should give the reader quick access to reproduc tion and modification of the Maple commands included in the book. The input files are supplemented by three high-resolution pictures showing an alternative rendering of some of the color plates. The file README.TXT (in ASCII format) provides a full description of the contents of the disk. We would like to thank Darren Redfern, who read the entire manu script, for his helpful corrections and suggestions for improvements. We have had a great deal of pleasure experimenting with graphics in Maple. We wish the reader the same. G.K. &M.K. Uppsala, June 1996