OpenSCAD User Manual/Example/Strandbeest

Abstract
This chapter describes how to animate a complex mechanism like the using OpenSCAD.

The model is not meant for 3D-Printing.

The source code is just one file without the use of external libraries, tested with OpenSCAD version 2015.03.

Target audience / Prerequisites
You need to have OpenSCAD installed and need to have a basic understanding in how to use OpenSCAD.

A basic understanding of geometry is necessary to understand on how to construct the linkage on paper and how to use the functions which are used to calculate the linkage. An understanding of trigonometry is helpful to understand the math behind the functions, but it is not strictly necessary.

Computer Geometry
To transfer this into source code, we need a few geometry functions.

Most of them are simple trigonometry.

Note worthy are "atan2" and the Law of cosines, implemented in the function VVLL2D (Vector Vector Length Length 2D).

All you need to know about atan2 can be read up on Wikipedia:

For the law of cosines, I recommend this article: http://www.dummies.com/education/math/trigonometry/use-the-law-of-cosines-with-sss/

Remember that with two points and two lengths, there are either two or no solutions. We can ignore the case with no solution as of now, because we know that the mechanism those not bind up. In order to get the alternate solution to the equation, the parameters can simply be swapped.

Drawing function
What we also need are some "drawing" modules. To keep it simple, the module is named rod and simply draws a rod from one point to the other.

Implementation
The implementation it self is surprisingly easy, now that we have the geometry functions to calculate the points, a module to draw a rod between two points and a general understanding on how to construct the object.

Leg Module
Let us take a look at the leg module.

The calculation is only eight lines of code and the drawing of the rods only twelve lines.

Strandbeest
For the full strandbeest we just need six legs with some spacing and angular offset.

Exporting the animation
OpenSCAD can export the frames of animation into PNG files. This PNG files can under Linux be turned into a gif via command line: convert -delay 10 -loop 0 *.png myimage.gif Convert is part of ImageMagick.

The resulting GIF can then (if necessary) be cropped with GIMP.

Next when working with this example
I recommend to split the source code into different files. One way to split it is: I would recommend to use "use". This allows you to include self tests with each file.
 * Trigonometry Function
 * drawing function
 * Jansen Mechanism / Leg
 * Strandbeest

To prettify the animation, you can draw the axes connecting the legs and/or add a support frame.

If you have access to a 3D-Printer, you can modify the code, so that the connecting points can actually rotate.