Simulating Mechanical Curve Drawing using Pymunk

 

For several years I've been teaching geometry to school kids by having them use LEGO Technic pieces to build linkages for drawing straight lines, parabolas, ellipses, and more. I've used GeoGebra to work through the mathematics behind those linkages.

The main problem I've had with GeoGebra and LEGO was quickly pointed out by my students – the physical builds usually fail to draw the clean, smooth curves rendered by the software. Real world issues related to mass, friction, torque, elasticity, and rigidity (kinematics in other words) aren't captured by the purely geometric descriptions in GeoGebra. A (simple) tool which lets students experiment with linkages that have these properties would help to fill the gap between geometry and its implementation.

The zipped download includes many examples using my linkUtils Python module, a small collection of functions that utilize Pymunk and Pygame for creating and animating 2D linkages.

The library is designed around the notion of 'beams' pinned together by 'balls' that support rotation. These are 2D shapes, conceptually resting on a sheet of paper, allowing the programmer to ignore the issues of gravity and collision detection. Sliding joints are supported, as well as constraints on how far beams can rotate around a ball. Several functions create composite beams (e.g. t-shapes, frames, and triangles), balls can be enlarged into 'wheels', and there is a limited form of gearing to make wheels rotate at the same speeds. The image below shows a linkage for drawing a parabola:

Parabola Drawing Linkage

Pymunk is more powerful than what's offered by linkUtils, but the functional restrictions are deliberate. I wanted to make the mechanisms as simple as possible, while retaining realistic curve drawing.

The examples in the download are divided into four categories: simple examples that illustrate the main elements of linkUtils, examples that draw straight lines, code for drawing conic section curves, and a collection of other curve mechanisms.

 

Downloads

 

Dr. Andrew Davison
E-mail: ad@coe.psu.ac.th
Back to my home page