Saturday, June 7, 2025

Python to draw geometry

Over the last couple of weeks I've been working on a library of geometry utilities in Python, code to work with matplotlib to draw figures for my geometry textbook. One motivation is to make the figures more uniform in style.

Although in several places I implemented what seem like Euclid's methods, in fact it is all analytic geometry. We deal with circles as a center and a radius and that's it. We find intersections and tangents by solving quadratics.

The main advantage is that if you don't like the triangle you started with, you can change it and the rest of the figure will redraw itself.

A significant pain point is is pushing the labels for vertices around until they look right. I am not sure whether I can write code to do that automatically. It would be nice.

It's been a fun project. However, there are so many figures in the book (more than 500 in Volume I alone), that I'm unlikely to redraw all of them any time soon.

Here is an example: the nine point circle. It's a little busy but let's walk through it.

We have a triangle and bisect the sides (red points) and then draw the circle and the triangle through those points. That circle is the nine point circle. Its center is in red as well.

This circle goes through the feet of the altitudes (blue). It also passes through the altitudes at another set of points (these points are halfway between the orthocenter and each vertex).

The easiest way to find those points is to rotate the triangle drawn on the midpoints by 180 degrees (purple). You can read the book to find out why.

As usual, the project is here, on github. The Geometry book is here, also on github.