Simulating linkages in Scratch is here.
Simulating linkages in Python is here.
Optimizing linkages to customize walkers is here.
Linkage Algorithms
The primary algorithm we used to find each joint's X and Y coordinates is Paul Bourke's circle intersection algorithm. Paul's solution uses the Pythagorean theorem and some clever algebra to solve for the joint's coordinates, giving us a fast, analytical solution for calculating linkages. His derivation is the 5th one down on this webpage.
Circle Intersection Algorithm and its Application to Linkages
Each bar of a linkage can trace a circle by rotating it around its joint, as shown in the image to the right. Bourke's algorithm calculates the X,Y coordinates of the two red points where the circles intersect. The third joint that will link the two bars will be one of these red points, and by considering how the mechanism should function you can determine which point to choose for the joint.

Initially, only two joints of a linkage may be known, such as the crank and a frame connection, which dictates the joint that can be calculated next. Then, this third joint allows a fourth joint to be calculated, then a fifth, etc.
Because the circle intersection algorithm yields two solutions, our code provides four variables to make it easier to choose between these solutions: High Y, Low Y, Left X, Right X. When calculating a new joint and determining which of these 4 variables to use, consider the path the joint should follow. This should help you to determine which of the 4 variables will always give you the correct intersection point, regardless of the crank's rotation.
Our code also uses a second algorithm called "line extension", which simply takes the slope of the bar between two joints and extends the bar to the third joint.
Because the circle intersection algorithm yields two solutions, our code provides four variables to make it easier to choose between these solutions: High Y, Low Y, Left X, Right X. When calculating a new joint and determining which of these 4 variables to use, consider the path the joint should follow. This should help you to determine which of the 4 variables will always give you the correct intersection point, regardless of the crank's rotation.
Our code also uses a second algorithm called "line extension", which simply takes the slope of the bar between two joints and extends the bar to the third joint.
Example: Calculating TrotBot's Joints
In the following images the joint being calculated is colored orange and the two known joints are colored green. Also, the bars used in the calculations are highlighted with a red dashed line.
1. For a given rotation angle of the crank, all that is initially known are the coordinates of the frame connection J3, and the crank J1. These joints allow joint J2 to be calculated by using the circle intersection algorithm with the solution choice "High Y".
1. For a given rotation angle of the crank, all that is initially known are the coordinates of the frame connection J3, and the crank J1. These joints allow joint J2 to be calculated by using the circle intersection algorithm with the solution choice "High Y".
2. Next, joint J4 can be calculated by extending the line connecting J2 to J3:
36. The remaining four joints can be calculated in the same manner:
Also, the first joint that needs to be calculated is always the crank, which uses Sine, Cosine and the crank's angle of rotation, as shown below.
To make the code run faster it should first calculate all the joints' coordinates for one rotation of the crank, and save these coordinates to each joint's dictionary (or list). Then, when TrotBot is simulated the crank is rotated, and the joint values are retrieved from the dictionaries which are used to plot TrotBot.