Intro
I have started printing a variety of models on my Elegoo Neptune 3d printer. 3D models which I make using Tinkercad or are available at 3D websites are predominantly defined in the STL file format. Once a suitable STL file has been created and saved the Cura app is used to "slice" them into layers and printing instructions are saved in TFT / gcode files which are sent to the printer.
STL stands for stereolithography but is better translated as "Standard Triangle
Language". It makes 3D shapes by combining 2D triangles. Curved surfaces are approximately with lots
of triangles. As you make the triangle
smaller, you can make smoother surfaces at the expense of using more and more
triangles. Most STL files are in an
unreadable binary format but ASCII STL is a valid alternative where points,
polygons and surfaces are defined in a readable format.
It occurred to me that it should be interesting and
straightforward to create simple ASCII STL models, e.g. for polyhedra. In particular, the simplest polyhedron is a
tetrahedron which comprises four vertices and four triangular edges.
Rules
The STL file format is very simple, you define a number of facets (i.e. triangular faces) each with three vertices. You should also define a unit vector which is normal to the surface in the triangle.
A "solid" is made up of a set of facets.
There are some
simple rules which are explained below:
1 The normal should be pointing outwards
2 Vertices should be listed anti-clockwise.
3 Each triangle should share two vertices
4 All vertices should be positive values.
5 values should be exponentials e.g. +2.00e03

It seems that, in practice, it is not necessary to follow all the rules.
As I want to read my STL files into Tinkercad or Cura I ignore any rules that they dont appear to require.
I didn't specify normal values as they are difficult to work out.
It appears that values dont have to be positive.
I used floating point or integers instead of exponentials.
Googling
I started by googling for ASCII STL examples but there don't appear to be many out there. Florida State University have a Computational Geometry course, which contains a number of examples I may look at.
A couple of printables users Ambrosia and GaelLaFond provide details of STL tetrahedrons, including ASCII STL, which I will investigate further.
There seem to be a number of python apps which help with STL generation,
Hand-and-Machine looks the best, it appears to generate various polyhedra in ASCII STL form.
As I hoped I came across an app, called
OpenSCAD, which will be extremely helpful if I want to write STL to generate geometric shapes. Gael LaFond's tetrahedron was written in openscad as shown below.
There is a little
quirk with OpenSCAD, in that it will only export ASCII STL files if you run it from the
command line. However, that isn't too much of a problem.
I have two possible files for my simplest possible STL object, from printables users
Ambrosia and
GaelLaFond .
 |
Ambrosia |
 |
Gael LaFond
|
Ambrosia's tetrahedron definition is very simple. Normals are all set to zero, vertices are at unit addresses and are set as integers.
Unfortunately there is an error somewhere and I cant import the file into Tinkercad.
In contrast Gael LaFond provides a regular tetrahedron with all faces the same. For a regular tetrahedron some of the vertices will always be at non-integer values.
I decided to make my simplest tetrahedron like Ambrosia's.
I started from Gael LaFond tetrahedron then changed the vertices to have unit co-ordinates and set normals to zero.
The result loads perfectly. We now have our simplest tetrahedron. It isn't at all regular but it is very simple. It has vertices (0,0,0), (1,0,0), (1,1,0), (1,1,1).
It is also very small as each co-ordinate is only 1 unit. However choosing the units as inches makes it 25.4 times larger, alternatively it is easy to
enlarge within Tinkercad.
I wanted to improve my design a bit. Firstly I wanted to make the tetrahedron with a right angle corner at the origin. This has co-ordinates origin O(0,0,0), x-axis X(1,0,0), y-axis Y(0,1,0), z-axis Z(0,0,1).
I also found that the vertex command can have a description after it, so I added the vertex name after each. This makes it easier to identify the order for the four facets (O,X,Z), (O,Y,X), (OZ,Y), (X,Y,Z).
Outro
It is interesting to understand how STL files are used to make up 3D objects and to be able to define them myself. The files quickly become very complicated as they grow so a tetrahedron, as the simplest example is very instructive. To me the hardest part is putting the vertices in anti-clockwise order when speciying triangular facets. I suspect it would be very difficult to construct more than a few shapes manually. I aim to be able to create more STL files using OpenSCAD, particularly poly