Categories

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.

``````module fillet(l,r1) {
intersection() {
cube([l,l,l]);
cylinder(h=l, r=r1, \$fn=50);
}
}``````

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.

``````module roundedCube(l,w,h,r1) {
d = 2 * r1;
translate([r1,r1,0])
hull() {
rotate([0,0,180]) fillet(l,r1);
translate([0,w-d,0]) rotate([0,0,90]) fillet(l,r1);
translate([h-d,0,0]) rotate([0,0,270]) fillet(l,r1);
translate([h-d,w-d,0]) rotate([0,0,0]) fillet(l,r1);
}
}``````

https://www.printables.com/model/91734-parametric-hook-with-source-file

EDIT: V1.1 of the OpenSCAD file (.scad) has the option to add a countersunk to the screw holes.

Categories

## Solvespace: involute gear

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

The idea for this video comes from the JustThinkering channel on YT who made a video Involute Gears in Solvespace (https://www.youtube.com/watch?v=i6tDWJsNsok).

Categories

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 polar coordinates to Cartesian coordinates.

``````function circle(radius) = [for (phi = [1 : 1 : 360]) [radius * cos(phi), radius * sin(phi)]];
polygon(circle(20));``````

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.

``````function circle(radius) = [for (phi = [0 : 1 : 720]) [radius * cos(phi/2), radius * sin(phi)]];
color("red") polygon(circle(20));``````

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.

``````function ellipse(r1, r2) = [for (theta = [0 : 1 : 360]) [r1 * cos(theta), r2 * sin(theta) ]];
color("cyan") polygon(ellipse(120,80));``````

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.

``````module plotList(p,c) {
for (j = p) {
color(c) translate(j) sphere(r=1.2,\$fn=30);
}
}``````

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. This particular matrix has 6 columns (n=6) and five rows (m=5). The first face will constitute of the four points 0, 1 , 6, 7. So the list this looks like [[0,1,6,7],[1,2,8,7]…[22,23,29,28]].

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.

``stitches = [for (j = [0:m-1]) [j*n,((j+1)*n)-1,(((j+2)*n)-1),(j+1)*n]];``

Next we need a list with all the faces that we created. We use the concat function for that.

``fcsc = concat([bottom],fcs,stitches,[top]);``

Now with all the points and faces we can finally can the polyhedron function of OpenSCAD.

``polyhedron(points=p, faces=fcsc);``

And this gets us the image below.

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.