Writing a script for a simple hook in OpenSCAD is easy but I wanted to do something more and make a parametric hook. With parametric I mean that a user can easily adjust the script by changing some variables to make your own hook.

To make it even easier the script makes use of the Customizer of OpenSCAD. This means that users don’t have to tinker with the code but can adjust the values of the variables with a easy to use panel on the right side of the GUI of OpenSCAD called the Customizer. (If you don’t see the Customizer in OpenSCAD go to the menu bar and click on Windows and then Customizer).

Aside from changing the dimensions I also added the possibility to add a fillet or a chamfer to the hook. And I added the option to change the radius of the hook and the diameter of the screw holes.

If you’re interested here is an explanation of some parts of the code. The fillet of the cube shaped parts of the hook is created with the fillet module. Within this module I simply intersect a cylinder with radius r1 and a cube of the desired length l.

In the module roundedCube the thus created fillet pieces are positioned in a such a way that the hull command shapes them to the desired filleted cube.

We first need to create a involute of a circle in Solvespace to get a better understanding of an involute gear. This video will be followed by another where we create an involute gear and a third where we adjust the gear in Solvespace.

I’ve used version 2.3 in this video but v3.0 should work fine too for this tutorial. This is a series in progress. I will at least make one more video to demonstrate how one gear drives another in Solvespace.

First video tutorial: Involute of a Circle in Solvespace. Before creating an involute gear we first need to understand how to create an involute of a circle.

Second video tutorial: To create an involute gear we only need three parameters, the module which determines the length of the teeth, the number of teeth and the pressure angle. With these parameters we can determine the Pitch Circle, Addendum Circle or Top Circle, Dedendum Circle or Root Circle and the Base Circle. With these circles and the pressure angle the shape of the teeth can easily be created in Solvespace.

Third video tutorial: This is the third video in a series about creating an involute gear in Solvespace. If we want to adjust the module, number of teeth or pressure angle of an existing gear in Solvespace we don’t have to start from scratch. We can take an existing gear and change one of the three parameters. This will save us a lot of time. However this change must be done following a procedure that I’ll demonstrate. Other wise Solvespace will give us the error message ‘unsolved constraint’.

Solvespace is an open source, parametric, 3D CAD program that is lightweight and easy to use. It is available for GNU/Linux, OSX and Windows. In Solvespace the user applies geometrical constraints to a sketch and the program’s solver calculates the result (comparable to the FreeCAD part design workbench).

Solvespace is open source (GPLv3 license) and is available for Window, OSX and Linux. Originally developed by Jonathan Westhues and currently maintained by Paul Kahler and others. It can be downloaded here: http://solvespace.com/download.pl

OpenSCAD allows the user to create complex shapes with the polygon function for 2D and polyhedron for 3D. Polygon and polyhedron both accept a list of 2D and 3D coordinates (points) respectively as parameters. A functions can generate a list of points eliminating the need to manually created these lists. This property can be used to create shapes that are impossible with the 2D and 3D shapes that are build-in in OpenSCAD. In this blog post I’ll show how to create some simple 2D and 3D shapes and explain how to create more complex shapes.

Creating a 2D shape

To create a circle with a radius of 20 in OpenSCAD we just have to type

circle(20);

However OpenSCAD doesn’t allow us to reshape this build-in function to for instance an ellipse. Alternatively we can write a function that generates a list of points needed for a circle and then use polygon with the points as parameter to draw the circle. The function uses the trigonometric formulas, x = r cos φ and y = sin φ, to convert polarcoordinates to Cartesian coordinates.

When F5 is pressed a circle is drawn however the x,y coordinates of this circle are available to us. By adding echo(circle(20)); to our script the list of points is printed in the console. The circle function can easily be altered thus gaining a new shape. An example is shown below.

Now let’s take a look at the syntax of the function. Every function generates a value and in this case it is a list of points. In OpenSCAD a list of points in a two-dimensional space is represented by [[x1,y1],[x2,y2],[x3,y3],…] where all x’s and y’s are numbers. In this case of the circle function the point are generated in a for loop. The loop begin at 0 and ends at 720 with a step of 1. The radius * cos(phi/2) and radius * sin(phi) calculate each x,y coordinate for every given phi.

The ellipse, a generalization of the circle, can now easily be created by slightly changing our function.

a second parameter is added. r1 is the radius in the x-direction and r2 is the radius in the y-direction. If r1 is equal to r2 a circle is drawn.

Creating a 3D shape

To create a 3D shape is more complex than 2D. We use polyhedron function of OpenSCAD instead of polygon. For polyhedron to work we need a list of 3D points instead of 2D points and in addition a list of faces. Each face contains the indices of 3 or more point. All faces together should enclose the desired shape. So let’s start create a cylinder. First we need to calculate a list of the points of the cylinder.

h = 180; //height of the shape
step = 18; //height of one layer of the shape
a = 36; //step size for angle in degrees
r = 40; //radius of the base of the vase
p = [for (z = [0:step:h], angle = [0:a:360-a]) [cos(angle) * r, sin(angle)* r,z]];

If you want to display these all the points in the list create the module plotList.

To display all the points in the list p in red type.

plotList(p,"red");

Press F5 and a cloud of points in the shape of a cylinder will appear.

Next we need a list of faces. This is often the most difficult part. In this case we create faces that consists of four points.

Imagine that we define a matrix that has n columns and m rows and we use this to systematically work our way through the points to create perfectly connected rectangles. So the first rectangle will be [0,1,7,6], the second [1,2,8,7] etc.

If we want to translate the complete matrix above we need the code below. Note that instead of using fixed numbers for the matrix the size of the matrix is calculated based on the variables that we defined earlier.

m = floor(h/step); //number of rows in matrix
n = floor(360/a); //number of columns in matrix
fcs = [for (j = [1:m], i = [0:n-2]) [(n*(j-1))+i,(n*(j-1))+i+1,(n*j)+1+i,(n*j)+i]];

We are getting there but we also need to create a top and bottom separately or else we wouldn’t get a solid.

top = [for (i = [n*m:(n*m)+n-1]) i];
bottom = [for (i = [0:n-1]) i];

And we need to connect or stitch the end points by creating additional faces of each row of the matrix. For example [0,5,11,6] for the first row.

You could ask why choose such a complex method to create a cylinder. However just as with polygon this method enables us to create shapes that are impossible to do otherwise in OpenSCAD. Imagine to have the z-direction smoothly curved and on top of that have a periodic curve in the xy-plane of the shape. We would end up with a vase shown in the image below. It’s impossible to create this shape in another way in OpenSCAD. In a next post I’ll explain how to do that.

Conclusion

OpenSCAD allows the user to create complex 2D shapes using functions that generate lists of points This list is used as the argument in the polygon function of OpenSCAD. Every shape can be generated as long as the mathematical expressions are known and can be translated to OpenSCAD script. This opens up a world of possibilities. The same is true for 3D shapes but instead of polygon the more complex polyhedron function of OpenSCAD should be used.

Caveat: List comprehensions as shown in the functions of this article are only possible with OpenSCAD v2015.03 and above.

OpenSCAD is open source (GPLv2 license) and is well maintained by Marius Kintel et al. Besides the stable releases for Windows, OSX and Linux, developmentsnapshotsare available. I recommend using these development snapshots since they have all the latest features.

EDIT: If you render the cylinder that we created above, export it as an .stl file and import it in Prusaslicer you’ll see a message like “auto-repaired 2246 errors”. This problem is caused by the reversed normals on (part of) the faces. I’ll demonstrate how to solve this in a next post. The model however prints fine thanks to Prusaslicer.

You must be logged in to post a comment.