I have an interesting programming problem. It has to do with the overall size, or area, of a mechanism. The dimension lines are draw so that the distance between them is always the same on the screen regardless of the zoom level. This is also true for videos, image export, and printing. The problem is that it makes it hard to change the scale of the document to fit within a specific area if changing the zoom or scale doesn’t change the entire document I the same way.


Area With and Without Dimensions

The image above shows the Jansen mechanism with a light green box drawn around the mechanism area including the dimension lines. The darker green box is the mechanism area excluding the dimensions. The first thing that stands out is that the circles around the connectors and some text is outside of the dark green area. That’s because, like dimensions, the text and those circles are all drawn at the same size regardless of the zoom level.


Connector Circles and Text Outside of the Area

Above is a close-up of the problem; the basic document size does not include stuff that doesn’t scale with the document. The reason that I started fiddling with the document area is in order to better support drawing a parts list.

What I did so far for the image export feature is to get the area with and without the dimensions, minus connector circles, text, and a few other things that I’ll include later, and then change the zoom by the percentage difference between those two sizes. Unfortunately, changing the zoom affects only the mechanism and not the dimensions so the overall area is still not right but is close. I repeat this adjustment a few times to narrow down the difference and get as close as needed the actual area containing the dimensions fitting within the export image.

I think that I can improve my math by figuring out how much room is taken by the dimensions and then zooming the mechanism to fit in the remaining area. Then a single math operation should give me the exact result I need.

Then I need to include every bit of dimension information as well as the connector circles, text, etc. to get the most accurate size of the image. Really, I need to call all of the drawing functions to get the locations of everything without drawing anywhere. Then zoom the image and draw it for real. And then I should take into account the width of lines and thickness of characters.

It’s an interesting problem for sure. It’s one of those things, amongst hundreds, that people don’t realize need to be programmed to get this stuff to work right. I had one professor at a prestigious university ask if he could port the program to OS X. Once he saw the size of the source code, he just said something like “Wow that’s a lot of code,” and I never heard from him again.