Solving Geometry Problems

When writing graphics programs, you frequently need to dream up little bits of geometry to make things look the way you want. While writing a program last night, I needed to figure out how to draw the lines that smoothly connect two circles of different sizes, like this:

TN01-problemThe geometry isn’t quite as simple as it might appear.

The line endpoints aren’t just points on the diameters of the two circles. Those wouldn’t join up with the circle smoothly unless both circles have the same radius. In the picture below, the drawing on the left shows what happens if we use points on the diameters:

TN01-notdiamsThat’s not smooth. We want the picture on the right, where I’ve marked with little dots the endpoints of the two lines.

As I worked on this, I thought about how being able to solve this kinds of problem is essential for anyone writing graphics programs. Although you can find a lot of stuff online, you need the freedom to be able to draw whatever you want, whether someone else has worked it out before or not.

I thought it would be useful to document how I go about solving these kinds of problems, dead ends and all. Finding an answer online is like drinking a coffee drink that a barista has prepared for you: it’s great, but you don’t learn how to do it yourself. To see how I solve this kind of thing, download the PDF for SolvingGeometryProblems. It shows how I got from the initial problem above to a final solution, and it even includes code you can run. Here are some screenshots of my demo program, smoothly joining up pairs of random circles.

TN01-result

Leave a Reply

Your email address will not be published. Required fields are marked *