# OpenSCAD User Manual/Example/Strandbeest
## Abstract

This chapter describes how to animate a complex mechanism like the strandbeest 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.

## Preparation

First of all, we need a drawing with the constants.
Theo Jansen has published the numbers on his website: (Video "The Legsystem", 3:36) or on archived version the webpage:
I suggest to name the points. The naming can be arbitrary. I have used Z..S to avoid confusion with the lengths a..m.
It can be very helpful to print out the drawing to scribble on.

## Construction by hand

Now we have to think about how we could construct the mechanism by hand.
We need a non collapsible compass, a ruler, paper and a pencil.
* non collapsible compass and ruler
We set the origin Z to an arbitrary point. For Y, we are going down l and a to the left. The crank m can be at an arbitrary angle. Drawing the crank results in the point X.
From this point, we construct triangles that are defined by two points and two lengths.
In geometry, this is the SSS case (constructing a Triangle with three sides given, see also Solution of triangles#Three sides given (SSS)).
On paper, this can be easily solved using a compass.
Let us start with setting the compass to length b and then putting the compass in point Y. Then we set the compass to the length j and put the compass in point X. The crossing point of the arcs is the point W.
Note that when two points and two lengths are given, there are always two solutions, speak crossing points. Given that we already know the general shape of the mechanism, we know which one we need. But keep it mind for later.
The rest is more or less "rinse and repeat".

### Geometric Construction Instructions
#### Conventions

* lengths are written in lower case
* point are written in upper case
* lines and arcs used for construction have a '

#### Instructions

* construct point Z
** draw a horizontal line h
** draw a vertical line v crossing the horizontal line h
** mark point Z where the h and v cross
** that will be the origin of this construction and crank axis of the leg mechanism
* construct point Y
** draw a horizontal line h' distance l down from h
** draw a vertical line v' distance a left from v
** label the crossing point of h' and v' as fix point Y
* construct point X
** draw a line m' trough Z add an arbitrary angle (the angle is the crank angle)
** draw an arc from point Z with radius m, the crossing point of arc n and Point Z is crank pivot X

##### draw line m from Z to X

* construct point W (SSS case)
** draw an arc j' from point X with radius j
** draw an arc b' from point Y with radius b
** the crossing point of arc j' and b' is point W

##### draw line b from Y to W

* construct point V (SSS case)
** draw an arc e' from point W with radius e
** draw an arc d' from point Y with radius d

##### draw line d from Y to V

** the crossing point of arc e' and d' is point V
* construct point U (SSS case)
** draw an arc c' from point Y with radius c
** draw an arc k' from point X with radius k

##### draw line k from X to U

** the crossing point of arc c' and k' is point U
* construct point T (SSS case)
** draw an arc f' from point V with radius f
** draw an arc g' from point U with radius g
** the crossing point of arc f' and g' is point T

##### draw line g from U to T

* construct point S (SSS case)
** draw an arc h' from point T with radius h
** draw an arc i' from point U with radius i
** the crossing point of arc f' and g' is point S
*** this is the "foot" of the mechanism

##### draw line i from U to S

* Step 1
* Step 2
* Step 3
* Step 4
* Step 5
* Step 6
* Step 7
* Step 8

#### Points
## 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: atan2
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 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:
* Trigonometry Function
* drawing function
* Jansen Mechanism / Leg
* Strandbeest
I would recommend to use "use". This allows you to include self tests with each file.
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.

## Next when building the mechanism with a different method
### Wrong Angle / Missing measurement / Tilt

* Strandbeest with correct dimensions a = 38.0 l = 7.8 locus correct and grounded
* Strandbeest with incorrect dimensions a = 38.0 l = 0 locus extraged and tilted
* Strandbeest with incorrect dimensions a = 38.79 l = 0 locus correct, but tilted
Examples:
* Klann R & D, Joe Klann, Jansen Linkage - Klann Linkage Comparison
** https://web.archive.org/web/20160304035711/http://www.mechanicalspider.com/comparison.html
* Adam Savage's One Day Builds: Pedal-Powered Strandbeest!
** https://www.youtube.com/watch?v=G96YQQ7vW8w?t=740
** https://www.youtube.com/watch?v=G96YQQ7vW8w?t=1018
Note that the examples are not to mock the creators for their mistake, but praising them for sharing their experience so that we all can learn from them.
This mistake is made more likely by speaking about the eleven magic numbers instead of the 13 magic number.
(There are elven rods, but the two fixed points are a and l apart from each other)

### Triangle

Traditionally, the leg is formed by just using rods:
When manufacturing from flat stock like paper or wood, realizing that that one leg can also be constructed from 2 triangles and 5 rods can simplify the assembly and make the mechanism more robust
here some practical examples:
* Leg mechanism made from card board
* Mini Strandbeest

### Model ready for 3D-Printing

A fully-parametric strandbeest implemented in OpenSCAD, with assembly instructions, is available for 3D printing.

### Using Rod of the same length

f=39,4 and c=39,3 are so close in length, that using rods of the same length can simplify the assembly without affecting the gait to much.
Note that in practice, the whole mechanism as play and flex, undergrounds are not perfectly flat and lengths and holes have manufacturing inducted errors.

## References

* ↑ https://ethanzuckerman.com/2007/03/08/theo-jansens-strandbeests/
* ↑ Linda Leinen (26 September 205). "Theo Jansen: Walking on the Mild Side".
* ↑ A. Matulich (23 May 2020). "Building the Strandbeest".