Creating beautiful images

i1.gifvisited the Walter’s Museum in the nearby city of Baltimore Maryland. I was attracted to the museum by the Archimedes palimpsest. Unfortunately for me they did not even had a page on display of the famous Archimedes Palimpsest but taking advantage that I have done my trip there I decided to see the museum’s collection of illuminated Manuscripts.

All I can say is

wow1.gif

Those monks really knew how to make something beautiful!

After Johannes Gutenberg invention, that is the movable types press, books became more ordinary items that many more people could afford and a big revolution happened when books became more accessible to people.

The down side to this is that books were no longer hand crafted but produce by machines and therefore not unique and not so beautiful! The quality of the images in books degraded very much.

Naturally there is exceptions to this.

Donald Knuth a mathematician and computer Scientist not happy with the way things had turned out for the second printing of his masterful treatise on Computer Algorithm “The Art of Computer Programming” decided to created two wonderful computer systems that are widely use today to produce once again not just beautiful Books but even better, beautiful Math books. Those programs are \TeX and METAFONT. \TeX is use for formatting pages and METAFONT was use by Knuth to create the Fonts to be use by \TeX.

Leslie Lamport another mathematician and computer scientist created a set of \TeX macros and the result was called \LaTeX. Similar transformation happened also to METAFONT. The original intention for METAFONT was to be use in the creation of beautiful Fonts that could be use by \TeX but sometime some programs are use in ways their original authors did not have in mind. Such is the case of METAFONT and METAPOST.

John D. Hobby transformed MetaFont into MetaPost.

How does METAFONT or for that matter METAPOST work?

METAPOST allows one to create Postscript files of beautiful figures. Using Postscript is important since is a language that most printers understand and using other programs one is able to easily translate postscript into other graphic formats.

Some times in the internet one is able to find small little treasures hidden in some hole.

While I was pondering on how to write this entry I was feeling tempted to start like

“In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a hobbit-hole, and that means comfort.”

This is the first beautiful paragraph of “The Hobbit” from Tolkien.

I wanted to begin that way because it almost seems like out of the hole in the ground I found John D. Hobby’s program in the web.

There is no need for anybody to own the program anymore!

Let the web do it for you!

Well here is the site to the METAPOST previewer on the web

http://www.tlhiv.org/mppreview/

This site was created by yet another Mathematician! :-)

Troy Henderson.

I have to say thank you Troy for placing this beauty on the net for all to use!

When you create a METAPOST images. You are creating a sort of computer assisted drawing. The same kind of drawing you do when you are using a computer program like the freely available Inkscape or Adobe’s Illustrator with mouse clicking and moving points but using METAPOST you communicate your intentions to the computer with words. Yes, you are writing in English or a subset of it, describing with this meta language what you like for MetaPost to do.

Henderson’s interface to METAPOST looks like this

metapostprev1.gif

Now let us do a small METAPOST program using Henderson’s Interface to MetaPost.

Draw an arbitrary triangle and the altitudes for this triangle.

By the end of this exercise we should end up with something that looks like this

trianglepreviewb.png

The Metapost program for such an image will be like this

pair A,B,C,AA,BB,CC,H;
A=(0,0); B=(3cm,0); C=(1cm,2cm);
AA - A = whatever * (B-C) rotated 90;
AA = whatever [B,C];
BB - B = whatever * (A-C) rotated 90;
BB = whatever [A,C];
CC - C = whatever * (A-B) rotated 90;
CC = whatever [A,B];
H = whatever [A,AA];
H = whatever [B,BB];
draw A–AA withcolor red;
draw B–BB withcolor red;
draw C–CC withcolor red;
draw A–B–C–cycle withpen pencircle scaled 1bp withcolor blue;
draw H withpen pencircle scaled 2bp withcolor red;
label.lft(btex $A$ etex, A);
label.rt(btex $B$ etex, B);
label.urt(btex $C$ etex, C);

 


A program like this is not difficult to create, once you have master the rudiments of the METAPOST language. Let us explain line by line to see how we created the figure above.

The first line tells METAPOST of our intention to use 7 points A,B,C,H , AA,BB,CC.

A=(0,0); B=(3cm,0); C=(1cm,2cm);

In this line we have specified the Cartesian coordinates for point A,B and C. Now the tricky part is the following two lines

Here we are coercing METAPOST to do some Math for us.

AA - A = whatever * (B-C) rotated 90;
AA = whatever [B,C];

We are giving some mathematical intentions to Metapost. If we call AA the point at the feet of the altitudes then AA-A is the segment between AA and A. Notice the “whatever” is use to denote some factor we will let the computer figure out!

B-C is the segment between B and C and is rotated 90 degrees, now to tell Metapost that AA is somewhere in the segment BC we use the second line that is

AA = whatever [B,C];

and so on. The rest of the program is almost self explanatory but if you have wet your appetite and will like to do some magic with METAPOST I direct you to the Manual for more information about how to use the METAPOST program.

I hope you will enjoy the comfort of this Hobby hole as much as I did!

see John D Hobby A User’s Manual for METAPOST

also

see Troy Henderson A beginner’s guide to METAPOST for creating high-quality graphics .

you may also find very enjoyable this book about Metafont from the horse’s mouth. The Metafont Book.

follow this for Donald Knuth site at Stanford

for a collection of examples of Metapost programs and their output

go Metapost examples.

This is a blog posting from www.isallaboutmath.com

One Response to “Creating beautiful images”

  1. Building a Geometric figure with Mathematica. « Is all about math Weblog Says:

    [...] a Geometric figure with Mathematica. Not too long ago I wrote here a small piece on creating beautiful figures, I was trying to explain a non trivial example on how to use METAPOST [...]

Leave a Reply