Take the 2-minute tour ×

Does anyone have some useful beginner tutorials and code snippets for playing with basic geometric shapes and geometric proofs in code?

In particular something with the ability to easily create functions and recursively draw them on the screen. Additional requirements, but not absolute, support for Objective-C and basic window drawing routines for OS X and Cocoa.

A specific question how would one write a test to validate that a shape is in fact a square, triangle, etc. The idea being that you could draw a bunch of shapes, fit them together and test and analyze the emergent shape that arises from the set of sub shapes.

This is not a homework question. I am not in school. Just wanted to experiment with drawing code and geometry. And looking for an accessible way to play and experiment with shapes and geometry programming.

I am open to Java and Processing, or Actionscript/HaXe and Flash but would also like to use Objective C and Xcode to build projects as well.

What I am looking for are some clear tutorials to get me started down the path.

Some specific applications include clear examples of how to display for example parts of a Cantor Set, Mandelbrot Set, Julia set, etc...

One aside, I was reading on Wikipedia about the "Russell's Paradox". And the wiki article stated:


The point about squares seems intuitively wrong to me. All the squares added together seem to imply a larger square. Obviously I get the larger paradox about sets. But what I am curious about is playing around with shapes in code and analyzing them empirically in code. So for example a potential routine might be draw four squares, put them together with no space between them, and analyze the dimensions and properties of the new shape that they make.

Perhaps even allowing free hand drawing with a mouse. But for now just drawing in code is fine.

share|improve this question
does "put shapes together" mean union of the filled shapes? –  balint.miklos Sep 7 '09 at 16:58
Russells paradox has nothing to to with squares, its about set theory. You seem to assume that a set of squares somehow means something like the connected area of all squares. This is not the case, it it just a set of squares. The whole paradox is still valid if you swap every occurrence of "square" with "cow". Maybe it becomes clearer if you see that a set of cows is definetly not a cow, but a non-cow may be a set (or anything else but a cow). –  hirschhornsalz Sep 8 '09 at 12:45
@drhirsch Thanks for the clarification, and I recognize that this is talking about sets and not the components that making up the set. But it seems to me that in certain cases the set is the sum of its parts and shares a self similarity with the individual parts. So a set of pure 2 dimensional squares in geometry would also be a square (assuming nothing else exists in the set space, dimension, other objects etc). But as soon one throws in types that vary the paradox kicks in. I assume this is what Type theory solves. Anyway, thanks for the feedback still learning this stuff. –  Gordon Potter Sep 8 '09 at 13:56
@balint.miklos Yeah I think that is what I mean, union of filled shapes. Although admittedly I am not much of a mathematician to be very precise in these matters. –  Gordon Potter Sep 8 '09 at 13:58
In the quote the term "set of" is the particular mathematical meaning and cannot be considered the same as the geometric union of squares. That is why a set of squares does not result in a geometrical figure. Hope that's clear enough!! –  danio Sep 9 '09 at 16:04
add comment

3 Answers

up vote 4 down vote accepted

If you're willing to use C++ I would recommend two libraries:

boost::GGL generic geometry library handles lots of geometric primitives such as polygons, lines, points, and so forth. It's still pretty new, but I have a feeling that it's going to be huge when it's officially added into boost.

CGAL, the Computational Geometry Algorithms Library: this thing is huge, and will do almost anything you'll ever need for geometry programming. It has very nice bindings for Qt as well if you're interested in doing some graphical stuff.

share|improve this answer
add comment

I guess OpenGL might not be the best starting point for this. It's quite low-level, and you will have to fight with unexpected behavior and actual driver issues. If you emphasize the "playing" part, go for Processing. It's a programming environment specifically designed to play with computer graphics.

However, if you really want to take the shape testing path, an in-depth study of computer vision algorithms in inevitable. On the other hand, if you just want to compare your shapes to a reference image, without rotation, scaling, or other distortions, the Visual Difference Predictor library might help you.

share|improve this answer
add comment

I highly recommend NeHe for any beginner OpenGL programmer, once you complete the first few tutorials you should be able to have fun with geometry any way you want.

Hope that helps

share|improve this answer
Thanks. The tutorials look useful. I will check them out. –  Gordon Potter Sep 7 '09 at 15:43
OpenGL is all about drawing very primitive objects. This is probably not what you want. Are you looking for writing an application similar to Kig? edu.kde.org/kig/screenshots.php –  hirschhornsalz Sep 8 '09 at 12:52
add comment

Your Answer


