# How to produce simple 2D illustrations to accompany geometry answers?

How do you make an upload-able PNG quickly which expresses a geometrical or mathematical idea?

This question was contrived to support my postscript answer but is intended to solicit other solutions that may benefit the SE network more generally. But for credibility, an answer must link to a post where this technique has in fact been used, as well as a sufficient "howto" portion if it involves more than something obvious like "Select export from menu".

There are two meta questions here and here concerning how to scope this question in light of the precedences it may set for our site.

• I personally see this question more on PostScript than it is on computer graphics. – cifz Sep 2 '15 at 7:45
• @cifz right this would fit GD.SE better. But thats not a reason why it can not be here. – joojaa Sep 2 '15 at 19:12
• @citz I think I see what you mean. What if I take it out of the question, and open it up for tikz and asymptote and whatnot. – luser droog Sep 2 '15 at 21:20
• I am answering here to show that this is a bit opinionated as a question, and answers definitely will be. Maybe this entire thread should live in our Meta, like this does on GD.SE. Any thoughts, @cifz – joojaa Sep 3 '15 at 10:15
• Meta question concerning this question. – luser droog Sep 3 '15 at 22:09

I use a variety of tools depending on the particular needs of the moment. I have a bias toward free tools, as I don't have access to things like Illustrator or Mathematica.

For general vector art purposes I use the free Inkscape. It operates on .svg files and can also render them out as high-quality .pngs or other bitmap formats. For example, here's a diagram I made in Inkscape to explain UV mapping:

For 2D function graphs, I often use the online graphing calculator Desmos, which has the handy capability of letting you share graphs online so others can view and modify them. You can also create sliders that can be varied to play with curve parameters in real time. For example, here is a configurable sharpening function.

For more complex graphing tasks that involve a bit of programming, I use Maxima, a free computer algebra system that also has graphing features. I used Maxima to create the graphs in this answer about Gaussian blurs:

This was a bit too complex for Desmos, since it involved programmatically creating a piecewise approximation of a Gaussian.

For really odd graphing tasks that aren't handled well by anything else, I've used Python with the svgwrite package to programmatically generate diagrams into .svg files. These can then be touched up in Inkscape if desired and rendered to bitmaps using Inkscape or ImageMagick. I used that workflow to create the images in this blog post on depth precision, like this:

In this case I wanted to not only graph a function, but place tick marks programmatically and nonuniformly along both the axes and the graph, to illustrate discrete depth buffer values.

And finally, if nothing else suffices, I'll use Python with numpy and pillow to render images pixel-by-pixel. That's how I created the Perlin noise images in this answer (with the help of the noise package too, in this case).

• Nathan you are the one that wrote that about depth precision? Wow cool... i read that thing and it helped a lot! small world :P – Alan Wolfe Sep 3 '15 at 23:03

Personally my choice of poison is Adobe Illustrator. Other apps such as inkscape, Corel Draw, Xara Designer will also do. In a pinch even PowerPoint will work. Though I do not personally recommend PowerPoint due to severe issues with its data model, even tough is possibly worlds most deployed drawing app.

It can also be a good idea to have a graphing application at hand. I personally use Mathematica for this although many other apps would work too. Or if you want you can use Wolfram alpha that's a free online version of mathematica.

Disclaimer: Because examples are mine and shameless self endorsement take with a pinch of salt.

## Illustrator

The first thing you should do in any vector drawing app is to enable the snapping grid. This reduces the tediousness of accurately placing lines. One of the big reasons i do not like to use Inkscape is the inferior way it implements this snapping. PowerPoint actually comes with grid snapping on by default.

I am not really satisfied by Illustrator as it does not fill all my needs. But no software so far does (Maya used to fill this niche but then autodesk happened).

The second reason i choose Illustrator is that it understands postscript natively. So if i need to program something i can do so quickly and existing documents update as my code matures Image 3 is done this way.

Here are some examples of drawings that I have done across the network with Illustrator, mostly by power of grid snap:

Image 1: One of many images i drew in illustrator on this site. Note: I am a quite experienced Illustrator (sometimes commercial) and this is extremely simple by my standards.

The Circle march image in is fairly simple to do. Just draw a random shape by clicking around. After this disable snap and let the smart guides do your work for you. Draw lines to closest point on the line, make circles to the line and (i deleted the guide lines after i was done). Rinse and repeat. It took me about 3-5 minutes to draw the image once i got my workspace started.

Image 2: GD.SE Continuation wave.

While this image seems quite more elaborate, its not much more work than the first image. It is more technical so in addition to grid snap I and now using the shift key to constrain lines to 45 degree angles. Hatch fills are easily just assigned to regions with the shape builder tool of illustrator. (example of shape builder in use, screen capture)

Image 3: Sometimes its easier to start from scratch in postscript. Image added to post on ENG.SE.

Finally a image that really is easier to do by typing the values in postscript. It is relatively easy to do in postscript. Ive still done the typography in illustrator. While drawing this by hand is not a big deal i prefer not to, but i will do it if i must do judgement call by eye.

## Mathematica

Mathematica is wonderful if you want to explore things a bit more. The only drawback to Mathematica is that it is NOT cheap. But it can do nearly anything quickly. Ive used Mathematica for some of my pictures on of nurbs basis.

One of Mathematicas core competencies s that its easy to develop even fairly complex pictures without much hassle. It can also easily animate your simple picture within you editor.

Graphics[{
orig = {
Table[
GeometricTransformation[
Line[{{0, 0}, {50, 0}}],
RotationTransform[ang]],
{ang, 0, 3 Pi/2, Pi/2}
],
Line[{{20, 0}, {30, 20}, {40, 0}}]
},
Red,
GeometricTransformation[
orig,
RotationTransform[Pi/6]
]
}]


Results in same picture as others have. Wrapping it inside a table as per results in:

Image 4: Animation is simple to do inside the code editor using Mathematica.

# PostScript+ps2eps+mogrify

For the Affine Transformations answer, I wrote a very small postscript program and then saved several copies under different names and edited each one to do each different task: scale, translate, rotate. For example, here's the basic one, ident.ps which does nothing to change the coordinates between the red drawing and the black drawing. I made the red lines a little larger and always draw it first, so the two show up nicely superposed and visible (IMO). I previewed with ghostscript with the vi (ex) command :!gs %. (all source files)

%!
/axis {
currentpoint 4 {
2 copy moveto
50 0 lineto
90 rotate
} repeat pop pop
} def
/shape {
20 0 moveto
30 20 lineto
40 0 lineto
closepath
} def

100 100 translate

gsave
% do transform here
currentlinewidth 1.5 mul setlinewidth
1 0 0 setrgbcolor
0 0 moveto axis shape stroke
grestore

0 0 moveto axis shape stroke

showpage


I then used the ps2eps command from psutils to calculate bounding-boxes automatically

$ps2eps -f *.ps Input files: ident.ps rotate.ps scale.ps skewx.ps skewy.ps translate.ps Processing: ident.ps Calculating Bounding Box...ready. %%BoundingBox: 50 50 150 150 Creating output file ident.eps ... ** Warning **: Weird heading line -- %! -- ready. Processing: rotate.ps Calculating Bounding Box...ready. %%BoundingBox: 50 50 150 150 Creating output file rotate.eps ... ** Warning **: Weird heading line -- %! -- ready. Processing: scale.ps Calculating Bounding Box...ready. %%BoundingBox: 25 25 175 175 Creating output file scale.eps ... ** Warning **: Weird heading line -- %! -- ready. Processing: skewx.ps Calculating Bounding Box...ready. %%BoundingBox: 50 49 150 151 Creating output file skewx.eps ... ** Warning **: Weird heading line -- %! -- ready. Processing: skewy.ps Calculating Bounding Box...ready. %%BoundingBox: 49 50 151 150 Creating output file skewy.eps ... ** Warning **: Weird heading line -- %! -- ready. Processing: translate.ps Calculating Bounding Box...ready. %%BoundingBox: 50 50 165 165 Creating output file translate.eps ... ** Warning **: Weird heading line -- %! -- ready.  And finally used imagemagick's convert command to produce cropped png images. (I didn't think of a quick way to automate this part. Edit: as commented, this can be done with mogrify -format png *.eps. Thanks, joojaa!) $ convert ident.eps ident.png

$convert scale.eps scale.png josh@cadabra ~/affine$ convert rotate.eps rotate.png

$convert skewx.eps skewx.png josh@cadabra ~/affine$ convert translate.eps translate.png

$convert skewy.eps skewy.png  Which produces PNGs, ready to upload. $ ls -l *.png
-rw-r--r-- 1 josh None  587 Sep  1 21:16 ident.png
-rw-r--r-- 1 josh None 1431 Sep  1 21:21 rotate.png
-rw-r--r-- 1 josh None  798 Sep  1 21:19 scale.png
-rw-r--r-- 1 josh None 1133 Sep  1 21:22 skewx.png
-rw-r--r-- 1 josh None 1197 Sep  1 21:23 skewy.png
-rw-r--r-- 1 josh None  756 Sep  1 21:23 translate.png


• I dont really see the point of generating the encapsulation with ps2eps cant you just type the eps header in your template. It makes the instruction cleaner (and user needs less dependenies). Instead of converting each file separately do mogrify -format png *.eps – joojaa Sep 2 '15 at 9:43
• Cool. I didn't know about mogrify. For the ps2eps part, it automatically calculates (and adds) the bounding-box info. Omitting that part, convert will produce full-page-sized images – luser droog Sep 2 '15 at 20:48

I just use Powerpoint to make such diagrams and it works great as soon as you're comfortable with its basic primitives. It supports all simple operations like rotation, translation, etc. and recent revisions also have shear and 3D transforms. Examples:

Here is an example of a Powerpoint diagram I made for an answer.

For more complicated diagrams, especially in 3D, I sometimes use Blender with shadeless materials. I can elaborate and show examples if it is relevant to your question.

Looks like jsfiddle is also popular around here.

• I agree---my answer is likely not valid any more because I haven't used diagrams in any answers so far. But I expect that to happen soon. So if it's OK for this answer to hang around for a few days, I am sure I will be able to find an answer. – ap_ Sep 8 '15 at 19:04
• Done! My answer should be valid now. – ap_ Sep 13 '15 at 18:24
• Excellent. Deleting my earlier comments. – luser droog Sep 13 '15 at 19:44

Not the definitive toolbox you might be looking for, but just an extra tool I use myself: for 3d graphics, Blender might come in handy. Especially if you use the Export_SVG plugin (available from http://dl.dropbox.com/u/16486113/Blender/archivos/temp/SVG/export_svg.py and http://blenderartists.org/forum/showthread.php?282824-SVG-output-script )

This allows you to get Blenders 3d objects as vector graphics in Illustrator or Inkscape. I find it gives me a nice quick start for creating simple 3d illustrations.

Allow me to paste an example. (In this example I use a lot of colors, but ofcourse, it can be all made black-and-red-on-white instead)

• surely you mean illustrator and inkscape (instead of illustrator and illustrator) – joojaa Sep 16 '15 at 8:10
• I sure do! Tnx! – Ideogram Sep 16 '15 at 8:30

I use Powerpoint and various (expensive) CAD packages. I wrote Powerpoint macros (VBA code) to do some special things like draw the control polygons of Bezier curves. Then I use the standard Windows Snipping Tool to grab screen shots. Here are some examples:

And some further examples from Math.SE

• Powerpoint is actually quite expensive considering things. Its ok, after all drawing skill comes from you. But atleast tikz, inkscape, blrnder and postscript are way cheaper than powerpoint. – joojaa Nov 1 '17 at 5:38
• I'm old, so time is more important to me than money. Inkscape is good, but there's no way I'd spend time writing tikz or Postscript code to produce pictures. – bubba Nov 1 '17 at 12:47