Categories
3D modeling 3d printing open source

Twisted Vase in OpenSCAD

Earlier I explained how to use polyhedron to create a regular cylinder in OpenSCAD. Not very exciting but this method is very useful to create much more complex objects. As long as we’re able to find the right function we can create the object with this method.

As an example I’ll explain how to create a twisted or spiraled vase. You’ve probably seen them on Printables or Thingiverse and they exist in many varieties. In this post we first create one starting with a simple triangle and then other regular polygons.

Three examples of twisted vases created with this code. On the left in the front a twisted triangle (in blue), on the left in the back a twisted octagon and on the right a twisted regular polygon that consists if 36 edges or vertices.

The code in OpenSCAD

For that we use the same method as in the previous post about polyhedron: first we calculate the points of the vase and then we define the faces.

But first consider a regular triangular plane and extrude that in the height (z-direction). Now suppose we twist this triangular plane while extruding and to make it even more complex increase or decrease the size of the plane while extruding. How would that function look like. In this example I’ll use a sinusoid or sine wave function. A sinusoid is the representation of any mathematical sine (or cosine) function that is smooth periodic in nature. Here is the general formula.

f(z) = a + b * sin(c(z)+d);

By substituting values for a, b, c and d we get very different sine functions. In this example I’ll use:

f(z) = 2 + 2 * sin(z)

Before we’re able to calculate our points we need the following variables.

height = 160; //total height of the vase
radius = 30; //radius of the base
step = 1; //steps in z-direction. The lower the more faces
twist = 1.2; //increase to have more twist

The height is in the z-direction, the radius is the radius of the initial circle when all the three vertices of the regular triangle lie on that circle. Step is the step size in the z-direction and twist is the amount of twist that the vase gets. The higher is more twist. Then we need three angles to calculate the exact point of each triangle.

sh3 = [0,120,240]; //triangle

Now we can calculate all the points with the code below

p = [for (z = [0:step:height], angle = sh3) [radius*cos(angle+twist*z)*f(z),radius*sin(angle+twist*z)*f(z),z]];

It’s a nested loop where in the inner loop the angle is varied according to the values of sh3 and in the outer loop the value of z is varied. Hopefully you’ll see similarities the code below that we used in the earlier post to calculate the basic cylinder: [cos(angle) * r, sin(angle) * r, z].

The first two values in the inner square brackets define the position of a point in the xy-plane. Notice that compared with the our earlier formula we multiply x and y values within the brackets with our sine function f(z). We also changed the parameter of the sine and cosine by adding the twist variable and multiply in with z.

Lastly, like we did with the cylinder, we have to create the faces. The code is similar to the code we used with the cylinder but with some essential changes.

module shape(p,m,n) {

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

    top = [for (i = [n*m:(n*m)+n-1]) i]; //connect points to create the top face

    bottom = [for (i = [0:n-1]) i]; //connect points to create the bottom

    stitches = [for (j = [0:m-1]) [j*n,((j+1)*n)-1,(((j+2)*n)-1),(j+1)*n]]; //connect points between the first and the last face per row

    //now connect all
    //reverse is used to reverse normal of top face
    fcsc = concat([bottom],fcs,stitches,[reverse(top)]); //concatenate the bottom, body and top

    color("teal") polyhedron(points=p, faces=fcsc);
}

The module shape takes as parameters a list of points (p) and the rows and columns of a matrix (m * n). The matrix is calculated as follows.

m = floor(height/step); //numbers of rows of the matrix
n = len(sh3); //number of columns in the matrix
Image from OpenSCAD of a twisted regular triangle. The twist variable has a value of 0.7.

Correcting the normals

Getting back to the shape module you’ll may be noticing that it differs from the cylinder version. One difference is can be found in the fcs list variable. When we watch closely we’ll notice that the for-loop for i has been reversed. This has been done to avoid errors in the stl file. As it turns out the normals of each face from fcs were pointing inwards into the object. OpenSCAD doesn’t complain about it but other programs like Prusaslicer do (see image below).

Prusaslicer auto-repaired 2240 errors in this stl file that was exported from OpenSCAD. These errors are all inward pointing normals that need to be reversed to point outward.

The top also prompted errors and this can be solved by reversing the order of the top list. To do this we need another function called reverse. It reverses the order of the list that is provided as a parameter to it.

function reverse(lt) = [for(i = len(lt) - 1; i > -1; i = i - 1) lt[i]];

Finishing the code

And this leaves only the last part of the code which is simply

shape(p,m,n);

The code that I’ll include with this post is a little more complicated. I added a Customizer to change some of the variables and I added a different sine function (g(z)) that provides a very different vase. I also added the angles for a pentagon, hexagon and octagon (sh5, sh6 and sh8) if you want to change the regular triangle for another regular polygon. If you do make sure to change sh3 on two places in the code: the value for the variable n and in the formula to calculate all points (p).

Screenshot of OpenSCAD where triangle is replaced by an octagon. Notice how the formula for p is changed accordingly.

The code can be found in this link: https://eroic42.nohost.me/nextcloud/s/mMbtCciBMA7BEpj.

Categories
3D modeling 3d printing FLOSS

Lithophane creator for 3d printing

I wrote an OpenSCAD script to make it easier to create a lithophane for the 3d printer. There are a lot of lithophane models of photos to be found on Printables, a community hub for 3d printing, but none that I could find offered the possibility to easily add your own photo to the model. Luckily OpenSCAD has a Customizer. The Customizer provides an easy to use graphical user interface (GUI) to change an existing model in OpenSCAD. It is therefore not necessary for the user to change the code.

Example of a lithophane created in OpenSCAD

The small OpenSCAD script revolves around the Surface() command. This command reads heightmap information from text or image files. Alpha channel information of the image is ignored and the height for the pixel is determined by converting the color value to grayscale. The invert boolean parameter inverts the color value of the image if set to true. Below is the module that handles the Surface() command and determines the thickness of the model.

module place_image(img,th,inv) {
        //import the image and scale it to the desired height and width and adjust the thickness.
        scale([1, 1, th])
        surface(file = img, invert = inv, convexity=3, center=true);
}

The script, example photos and an example stl file can be found on Printables here: https://www.printables.com/model/293702-lithophane-creator.

The lithophane model can be created in five steps described below.

  1. Download OpenSCAD. For this your need the free and open source program OpenSCAD which is available for OSX, Windows and Linux. Start OpenSCAD and load the .scad file available here together with the sample negatives photos below. Easiest is to have the .scad file and the negatives in the same folder or map. Now use the Customizer to create you .stl file. 
  2. Make a negative of your photo. If you start with a jpg file you need to convert it to a png file first. Before loading your png file into OpenSCAD you need to make a negative of the photo first. There are many ways to do this but I use Imagemagick, a command line tool for Linux, Windows, Mac OSX, and others. To create a negative file type: convert -negate foo.png inverted_foo.png on the command line.  To create a negative png file and reduce it 20 percent type: convert -negate -resize 20% foo.jpeg inverted_foo.png. (If you rather use a GUI instead of the command line you can also use GIMP, yet another free and open source program. Download GIMP for OSX, Windows or Linux. Open the original photo. Next select Colors and then Invert in the menu.)
  3. Use the Customizer. The Customizer has the option to change the background. This is important to select. If the background of your original photo is mostly white or lightly coloured choose ‘light’. If it’s mostly dark choose ‘dark’. In addition enter the height and width in pixels of your photo.
  4. Render and save the .stl file. To create an .stl press F6 or select Design/Render in the menu. It’s important to know that rendering takes longer when the image is larger. I found that a a 200×200 pixels photo takes a few minutes to render. Since the resolution of the 3d printer is limited it’s probably needless to go beyond 40.000 pixels.
  5. Slice and print. Make sure that the photo is placed in the upright position as shown in one of my photos on Printables (see link above).

The script in this blog post provides a flat model of a photo. If you want to have a curved model take a look at this blog post of mine: https://homehack.nl/a-curved-3d-printed-lithophane-in-openscad/

Categories
3D modeling 3d printing

A curved 3d printed lithophane in OpenSCAD

How can I wrap a flat surface around a cylinder in OpenSCAD. This was a question I asked myself. OpenSCAD doesn’t provide a ready made method so we need to write our own. Luckily we don’t have to invent the wheel here, others have done that already. Justin Lin has written a very handy tutorial on his website Openhome.cc how to wrap a text around a cylinder.  In this project I took it a step further and wrapped a png image over part of a cylinder resulting in a curved image.

3D printed curved lithophane

It seemed like fun to combine this technique of wrapping with the 3D print of a lithophane. A lithophane is an engraved image on translucent material. Many 3D printers have already produced lithophanes sometimes with stunning results. For this experiment I’ll use white PLA because it  has excellent translucent properties.

Now first let me explain the basics on how to wrap a 2D image around a cylinder. First we create a circle out of triangles. These triangles are then extruded to segments to form a cylinder.  Next all segments of the cylinder are lined up in a row and the image is place on the far side but just within the limits of the segments. When we intersect the image with every individual segment and return the segments to their original position in the cylinder, a curved image emerges (see images below).

If you want to know more please watch my video below. In this video the OpenSCAD script is explained and demonstrated. Also is shown how to import the stl file in Cura and what settings are used.

Here you can download with an example file of a curved lithophane:

If you want to use your own png file change the surface command in the OpenSCAD file to include your own png file. Make sure to also change the height and width according to the imported png image in px. Prerender and render can take some time so it’s recommended to use a fast PC. And the larger the png the longer it takes.

A circle created out of triangles
The extruded triangles form a cylinder
The segments are lined up in a row
Image placed on the far side of the triangles
The triangles returned to their original positions
The image intersected with the triangles and returned to their original position.
Categories
3D modeling 3d printing open source programming

Peddle wheel boat (3D printed)

I found an example on Thingiverse, a rubber band powered boat with two peddle wheels, but it has two problems. First of all the author only provides .stl files and second the design is a bit flawed. I therefore decided to design the boat from scratch with the 3d CAD program OpenSCAD. With OpenSCAD I’m not only able to edit my models quickly, I’m also able to share the OpenSCAD script allowing other to use and change it. Links to the downloadable files can be found here: https://my.hidrive.com/share/pyilt3itb8

Assembled Paddle Wheel Boat.

The Paddle Wheel Boat that I created consists of four parts: the boat, the shaft and two peddles. The main change of the boat that I designed is the position of the shaft. It’s been shifted to the middle of the boat providing more balance. I also enforced the attachment point of the rubber band to the boat making it impossible to break it.

The redesigned Paddle Wheel Boat with shifted position of the shaft and enforced attachment point for the rubber band.

I also increased the size of the paddles enabling the boat to move faster. The shape of the paddles are rounded instead of square improving the dynamics of the paddles through the water. A problem with the old design is that the rubber band has to be fixed to the shaft with some tape. Not a very elegant solution. I added a square hole to the design of the shaft. The rubber band can be inserted through the hole and fixed to the shaft. No tape needed.

Simple square hole in the shaft. The rubber band fits right through the hole making it easy to fix it to the shaft.

Changes to the models are easily made. The OpenSCAD script is simple and the result of a change can be reviewed immediately by pressing F5. E.g to move the shaft to the back of the boat can be achieved by just one simple change in the script.

Just four parts, the boat, shaft and two peddles, are needed to make the boat. If you don’t want to make changes to the design just download the provided .stl files and open them in your favourite slicer. After printing the Peddle wheel boat can be assembled and tested. Have fun.

All printed parts plus the rubber band.
Categories
3D modeling 3d printing open source programming

OpenSCAD parametric hook

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).

Screenshot of the script with the Customizer on the right side.
Smaller hook with chamfer
Larger hook with fillet

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);
    }
}

I published the OpenSCAD script (.scad) and some example hooks (.stl) on Prusaprinters. You can download it here:

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
3D modeling 3d printing open source

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
3D modeling 3d printing open source

My videos remastered on PeerTube

I wrote earlier about my move from YouTube versus PeerTube. My new videos will appear on both platforms but I’m also remastering my old Solvespace videos. These videos were all 720p which isn’t ideal for a tutorial. Having most of the material of the videos available I’m recreating them in 1080p. When I’m done I’ll only upload these HD videos to PeerTube. The videos take a lot of time to create and I’m currently very busy so the videos appear irregularly but whenever I have time I’ll make them.

The latest video that I remastered is about the Geneva Drive. A wonderful project to design and 3d print. I redid part of the screen recording because either the original was gone or wasn’t good enough. For this video I used the latest version of OpenShot (v2.5.0) but I’m unfortunately still having issues with this video editor. For the next video I’ll return to Shotcut which is currently my favourite free and open source editor. Here is a link to the video if you want to see it on PeerTube.

When I tried to embed a PeerTube video here I found that the WordPress embed block is not suitable for this purpose. Apparently PeerTube is not (yet) whitelisted by WordPress. Also it appears that iframe tags, my other option, are blocked by WordPress because of security reasons. That’s a bummer.

Categories
3d printing

Hephestos 2 upgraded with heated bed

Adhesion problems and warping

I own a Hephestos 2 for over a year now and although I was pretty happy with it I very much wanted to upgrade the 3D printer with a heated bed. The reason for that was not so much the desire to use other material like ABS but I was hoping for better adhesion. Adhesion problems in the past led to warping and misprints. To counter this I used BuildTak en Pritt. This helped most of the time but it also led to a new problem. It was very hard to remove the model from the printbed. With the help of a vise to clamp the printbed and a special knife I was able to do it but it was far from ideal (to say the least).

A heated bed is the obvious solution to this problem. Warping is mainly caused by uneven cooling and therefore shrinking of the different areas of the print. The printbed counters this effect by keeping the whole printbed warm and thus warming the print evenly over it’s surface.

Printing a Benchy on the heated bed. Gone is the BuildTak.
Categories
3D modeling 3d printing

The BQ Hephestos2 (3D printer), nine months later

Introduction

It’s been nine months since I received and assembled my BQ Hephestos 2 printer and I think it’s time to share some of the experiences that I had with it. For those who don’t know the Hephesthos 2 it’s a 3D-printer that is based on the Prusa i3 design with a thick steel frame and almost all metal parts. It’s not cheap but it’s a well designed, high quality 3D-printer with a large printbed. It does have it’s shortcomings but more of that later.

Categories
3D modeling 3d printing

Make a Photography Light Box of cheap material (part 1: design and 3d print).

Introduction

My wife has a lot of stuff she wants to sell online and asked me to create a sturdy but cheap Photography Light Box. The dimensions of the different objects vary, so I wanted to be flexible with the dimensions of the light box. We came up with a simple idea to create a three way connector that connects curtain rods. The frame will be covered with white bed sheet cloth kept together with velcro. At the local hardware store I found plastified steel curtain rods. These were the cheapest I could find but are still very strong.