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 open source programming

OpenSCAD: Polygon and polyhedron

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.

Shapes created with functions and polygon in OpenSCAD

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));
Shape created with x = r cos(φ/2) and y = r sin(φ)

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.

Ellipse created with the code above

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.

All red dots are the points of the cylinder list that we calculated.

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.

And we’ve got ourselves a cylinder made out of square faces.

And our cylinder is complete. The complete OpenSCAD file (with an added twist) can be downloaded here: https://eroic42.nohost.me/nextcloud/s/wRwHSp6mtg3w96y

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.

With some tweaks we can turn the dull cylinder into a nicely shaped vase.

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, development snapshots are 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.

The (somewhat older) video below demonstrates the 2D shapes. Click here to watch the video if the video below doesn’t play: https://peertube.linuxrocks.online/w/7NfsT6STabJ341ViP1eoMR

Categories
Linux open source PC

Linux on a 17 year old laptop

My laptop is a Thinkpad T40 from 2003 with 1GB of RAM and a 30GB HDD (Yes, you can laugh now). I bought it second hand many years ago, it had Windows installed and it was slow as molasses. It was also a time that I got interested in FLOSS. So I looked for a suitable Linux distro and I found Puppy Linux (Slacko and later the TahrPup release). It turned my unusable laptop into a fast and very capable computer. I’ll never forget the amazement when I booted Puppy for the first time and saw how fast it was.

I’m not much of a distro hopper but last year I switched to AntiX because I felt that development of Puppy had slowed down. AntiX does more or less the same as Puppy in that it brings life to an old computer. Both are very lightweight but at this moment I find AntiX definitely more polished with JWM, FluxBox and IceWM as window managers to choose from.

Both Puppy and AntiX contain, as do most of the other Linux Distros, proprietary bits and pieces (e.g drivers and it’s possible to install proprietary programs from the Snap store or PPM) but are mostly FLOSS and are available thanks to many volunteers that dedicate so much of their time to these operating systems. So I think it’s fair to contribute back e.g by donating to the developers that make this possible.

Link to the Antix website.

Link to the Puppy Linux website.

Categories
open source social

Create animated GIFs from MP4 with FFmpeg

Animated GIFs are after all these years still pretty popular. FFmpeg is a good FLOSS tool to create these animated GIFs. FFmpeg is available for Windows, Linux and OSX. A word of warning FFmpeg is a command line tool that’s very versatile but it’s not for everybody. In fact suppose this post is more for users that like to tinker a lot with their animated GIFs. Below I will explain not only how to create a animated GIF from an mpeg4 movie but I also provide instructions to improve the quality.

The basic command to create an animated GIF from a mpeg4 is:

ffmpeg -i input.mp4 output.gif

where the name of the input file is input.mp4 and output.gif is the name of the output file. Unfortunately gif images are large due to their lossless data compression. So you’ll end up with a file that’s much bigger than the original mpeg4 and probably something that exceeds the upload limit of Diaspora*, Friendica or Mastodon.

In order to reduce the size of the file we can reduce the size of the images or we can reduce the number of frames per second. To achieve this we need the following command:

ffmpeg -i input.mp4 -r 12 -s 320x180 output.gif

This command reduces the framerate to 12 per second and resizes to 320×180 pixels. For the size of the GIF make sure that the aspect ratio remains the same or the resulting GIF will be distorted.

When we look closely at the resulting GIF we clearly notice some shortcomings in the animation. This is due to the default GIF encoding in FFmpeg. Because GIFs only uses 256 colors the number of colors from the mpeg4 needs to be reduced. FFmpeg by default uses a generic palette of 256 colors that covers the widest range of content. This is in general not optimal for the specific video that you want to convert. Luckily FFmpeg allows us to create a custom palette for our specific video. To create this palette type:

ffmpeg -i input.mp4 -filter_complex "[0:v] palettegen" palette.png

When we look in the folder of our mpeg file well noice that a file ‘palette.png’ has been added. This is our newly created 256 color palette for our specific video which is generated by the palettegen filter. To use the new palette with our mpeg video type:

ffmpeg -i input.mp4 -i palette.png -r 12 -s 320x180 -filter_complex "[0:v][1:v] paletteuse" prettyOutput.gif

FFmpeg needs two input files (streams) in this case test.mp4 and our newly created palette.png. The paletteuse filter takes the two streams as input specified by [0:v] and [1:v] where v stands for video and the preceding number for the number of the stream. The output file is renamed to prettyOutput.gif to differentiate it from the earlier output.gif. The resulting video should be much … prettier. If your resulting video is still too large either reduce the frame rate or resize even further (or just reduce the length of the video of course).

Further reading:
http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/

Categories
open source social

FLOSS tools to create a forum or community

Introduction

With the demise of G+ a lot of community owners are suddenly looking for a new home. Since a lot of G+ users despise FaceBook (and rightfully so) other social networks are mentioned. The problem with a lot of these networks is that they are centralized and proprietary making the users depending on the whims of the owner of the network. Below I summerize the FLOSS options for people interested in setting up a community. This is not an exhaustive list. I encountered these options after discussions often on G+ and I experimented with some of these options during the last couple of months.

Self-hosted or not

An important decisions is whether or not to host the forum or community yourself. If you want to host it yourself you’ll keep full control of the server however the maintenance is considerably more labor-intensive than with a non-selfhosted solution. You also need to install the software on a server and configure it.

Friendica (self-hosting possible)

Both are macroblogging social media networks that offer the possibility to create a forum. The UI of Friendica doesn’t look very modern but the functionality needed to use and maintain a forum is all there. Click this link to see an example of what a Friendica forum looks like. If you want to create a forum on a existing server please note that the administrator of this server can place limits to the forum e.g the number of participant or the number of forums that can be created by one account. Be aware that you’re a guest on someone else’s server.

A practical example. In the German town of Zwenkau the citizens are provided with a community platform, the Zwenkauer Flaschenpost, for online communication and discussion between citizens. This is all done with a standard Friendica install on a server. If you want to read more here is a link.

Movim (self-hosting possible)

Movim is social platform that let you share and chat. Movim is build on top of the XMPP communication protocol. A strength of Movim is that is federates and that everyone with a XMPP account (e.g Jabber) can connect. Once you’ve created an account it’s very easy to create a community. The UI looks modern but some community admin features are missing (or I couldn’t find them). As an example as an owner I couldn’t ban someone from the community. On the other hand I found Movim community the easiest to set up (in a non-selfhosted environment). This is a link to my Movim community. Also a word of warning if you create a forum on an existing server be aware that you’re a guest of that server and that restriction may be applicable.

I recently wrote a more lengthy post about the chat capabilities of Movim.

Mastodon (self-hosting possible)

Mastodon is a microblog social network that has a TweetDeck like interface. I was hesitant to add it to this list because the UI and the dynamic experience differ from a classical forum where the same post remains in the viewport for days or weeks. However when joining the right instance (=server) or create one yourself it may very well become a great dedicated community. Here is a link to mastodon.art an instance where artists can show their artwork.

Flarum (only self-hosting)

Open source forum software that is currently in beta. Nice, modern UI. I’ve read some concerns about the beta status and the stability of Flarum. If you want to see what the interface looks like here is a link. Here is a link to a guide how to install Flarum.

NodeBB (self-hosting possible)

Open source forum software with a modern UI. You can either self host for free or use a NodeBB hosting plan that comes with a price tag. Here is a link to the source of NodeBB. You can check the interface yourself on this website.

phpBB (self-hosting possible)

Forum software based on the PHP programming language. I know phpBB mainly because it’s used on the FreeCAD forum, a place that I visit sometimes. phpBB is feature rich and from a user perspective it’s a joy to use. The documentation about this forum software can be found here. Here is a link to the source code.

Discourse (self-hosting possible)

Discourse discussion management software with a modern UI. It can either be self-hosted or Discourse can host for you. The latter which is clearly the business model of Discourse comes at price tag. If you want to see what Discourse looks like take a look at the discussion forum of Diaspora*or Tom’s 3D community. Here is a link to the source code and another to the install guide.

Last updated: 02 November 2021