Pages

Thursday, December 14, 2017

OpenSCAD: Generating Triangles and Poyhedron

Polyhedron, vertices and faces

OpenSCAD offers three methods to make 3D model. First is Constructive Solid Geometry where primitive objects are combined using boolean operations. The second method uses two dimensional shapes that are extruded either in the z direction (linear_extrude)) or around the the z-axis (rotate_extrude). In the third method vertices (or points) and faces are defined to shape the surface of a 3D model (polygon mesh). This, at least in theory, provides us with a method to create the most complex 3D shapes.

Polygon mesh of a dolphin. In this example a triangle mesh is used. A public domain image from Wikipedia (https://en.wikipedia.org/wiki/Polygon_mesh#/media/File:Dolphin_triangle_mesh.png)

The third method can be achieved with the polyhedron function of OpenSCAD. The description polyhedron function in the OpenSCAD manual is more than adequate but it only provides the user with examples where the vertices and faces are manually entered in OpenSCAD. This can be a cumbersome process that is prone to bugs, leading to a non-valid solid. Having OpenSCAD generate these vertices and faces is a method that is more favorable (at least to me) for two reasons. First once the algorithm is correct the chance to generate non-valid solids is minimized but more importantly computer is so much faster in calculating the vertices needed.

Triangle mesh of a sphere

An important question is what kind of faces are needed for our polygon mesh. From OpenSCAD version 2014.03 onward a face description can have any number of vertex larger than two however I think that the triangle mesh is still the best choice. If the user chooses more than three vertices OpenSCAD subdivides the faces to triangles and this can cause problems as is demonstrated in an article of Justin Lin where a cube that consist of four vertex faces and one of the faces is not planar with the other three. So in conclusion the triangle mesh provides the best control over the 3D model in OpenSCAD.

In the following video tutorial I'll explain how to create such a 3D model of a sphere, cone, torus and cylinder in OpenSCAD.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.