Categories
FLOSS Linux open source

My favorite free and open source software

I’ve been writing about free and open source software (FLOSS) for several years now. Not only is this software free as in free beer but it also means freedom for me to use the software as I deem fit. I can install it on any system I like, copy it, distribute it and even study the source code, change it and perhaps create my own version if I want to.

Over the years I’ve become attached to the FLOSS programs that I often use. I often discovered them reading articles mostly on blogs about FLOSS or on the Fediverse where people love to share their experience with FLOSS. Below I’ll go through my list of favorite FLOSS. I’ve created the list ordering the programs in the following categories: operating system, office, games, social, music, video, browser, graphics, 3d cad and cloud. So here it goes.

Operating System: MX Linux

There are plenty of Linux distros and I tried several but MX Linux has been my daily driver for several years now. It’s stable, pretty light weight, well maintained and I allows me to easily install all the software that I need.

Office: LibreOffice

From LibreOffice I use the LibreOffice Calc part the most. For our personal accounting something like GNUcash is a bit too much so I’m using LibreOffice Calc for that. Importing our financial transactions as a .csv file, using pivot tables to sort the current accounts and sum the amounts. Lastly I add a category per current account and filter.

Games: Beyond All Reason

My favorite game was Mindustry for a while but now it’s Beyond All Reason (BAR). BAR is the spiritual successor of Total Annihilation, an old RTS game, but it has become so much more. Like Starcraft 2 it’s used for competitive gaming which makes it also fun to watch.

Social: Lemmy (Beehaw server)

Currently I’m using Beehaw which is a very good moderated Lemmy server. Lemmy is the federated version of Reddit but the main Lemmy servers are radical to the point that it’s becoming unbearable (although I do believe that lemmy.ml has cleaned up their act recently). Beehaw has plenty of users with good links and discussion without the toxicity that seems indigenous on almost all social media.

Music: Squeezebox

I’m still using Squeezebox, a complete home audio streaming system. I’m running my own Squeezebox server where I uploaded my music to. It also contains my favorite radio stations and podcasts. Squeezebox is no longer produced by Logitech but since everything is FLOSS even the hardware can be made from off the shelf components.

Video: Invidious

All YouTube videos from an Invidious server (Yewtu.be). With all the content YouTube is hard to avoid but at least with Invidious I’m no longer served with ads and the relentless data mining from Google has stopped.

Browser: Firefox

I’ve been using Firefox for many years now. It’s the last FLOSS browser with a decent, although shrinking, market share and offers good privacy, speed and stability. And it’s not Google.

Graphics: Inkscape

I’m using Inkscape for many years now for all my vector graphic design work. As with all vector illustration design programs it’ll take some time to get used to but once you do it’ll allow to get the most out of your 2d graphic designs. It’s unbelievable how it has grown over the years and is able to compete with the proprietary and expensive Adobe Illustrator.

Cloud: Nextcloud

During my quest to get away from Google I needed cloud storage to replace Google Drive. I discovered NextCloud a couple of years ago and setup my own home server (a Nuc) with NextCloud. It’s great to sync photos from my smartphone and to exchange documents. I never looked back.

3D CAD: OpenSCAD

Perhaps a bit of an oddity for some people but I do 3d printing as a hobby and although I also use Solvespace or FreeCAD if I need a more functional part, OpenSCAD holds a special place since it allows me to make more creative designs. Some people might be put of by the UI and the fact that every 3d model needs to be programmed instead of drawn.

And that concludes my list of my favorite FLOSS programs. I use plenty more FLOSS. In fact none of the programs that I use for the PC are proprietary (with the exception of proprietary blobs).

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
FLOSS open source social

When to use Friendica over Mastodon

There are many software options to choose from if you want to enter the Fediverse. To name a few, there is of course Mastodon where most people are likely to land on nowadays but there is also Epicyon, Friendica and Pleroma to name just a few. Every option has it’s own unique style, features, pros and cons but in the end they all provide access to the same Fediverse.

I’m a long time user of Mastodon because I like how the web interface enables me to communicate with the Fediverse. The lay-out of the columns with home, notification, local timeline etc always had a certain appeal to me. The last week however, during the first large Twitter migration, I’ve got a bit overwhelmed with too many toots on my home stream not to mention the local timeline. Then my instance Fosstodon had some down time. In these exciting times I was kind of anxious to follow the situation from within the Fediverse. Without access to Mastodon I took refuge to my old Friendica account. I wrote about Friendica in the past but I stopped using it mainly because of the cluttered UI that often confused me.

Entering the Fediverse with Friendica again made me appreciate the Friendica software. First there is just one column or stream instead of three or more in Mastodons web interface. This provides a certain calmness that I was looking for at this moment. Also Friendica provides the option to change the UI by customizing the theme of even by choosing another theme. The combination of these two provides an experience that is currently easier for my eyes and mind.

The Frio theme of Friendica with a dark color scheme which I find easier to the eyes.

Another important difference is that I’m easily able to create groups. When I connect with someone I can add that person to a group that I created e.g friend, acquaintance. I even created groups for companies and bots. Now with just a single mouse click I can change my stream to e.g friends to see what they have to tell today. I use this feature often. I know that Mastodon has a list feature where I can do more or less the same but I somehow never really use it. To take it even further I can create a group with RSS feeds and WordPress blogs. This turns Friendica into a news reader.

Getting back to the cluttered user interface I was talking about. Friendica allows the user to make changes to the user interface. There are a couple of themes to choose from and the themes can be customized in color. Also the layout and the content of the stream can be adjusted. This way I was able to create a style that is easier to digest making Friendica a much better experience than it was for me in the past.

And the list of features in Friendica goes on:

  • Friendica wants you to be able to communicate with every one so besides ActivityPub it supports other protocols such as Diaspora*.
  • It’s easy to access older posts because of the archive option.
  • An event calendar.
  • And a very advanced text editor to create a post that BTW isn’t limited in length. This doesn’t mean that your stream is filled with long ramblings. Just the first few lines of a post will be shown.
  • The ability to create or join a forum. The forum allows people to join a special interest group for discussion etc.
  • A feature to ‘quote share’ a post from someone else. It’s my understanding that this is a much requested feature from Twitter migrants.
  • As an advantage of Friendica I wanted to mention you can have posts with hashtags in your stream and that you can edit a post that has already been published but with version 4.0 this is also possible in Mastodon.

There are also features lacking in Friendica (or I couldn’t find them) that are available in Mastodon. Notably:

  • No option for a content warning in a post you’re creating. This option is heavily used in Mastodon e.g to warn people for a post about a sensitive topic e.g politics. Friendica does respect content warnings from Mastodon though.
  • No option to add a text to an image. Mastodon has this option to include visually impaired people.
  • No option to blur an image. In Mastodon this is a feature similar to a content warning for a text.

It appears to me that Mastodon has more options for inclusion than Friendica like the features mentioned above and deliberate not having the feature of ‘quote sharing’.

I realize that I haven’t even scratched the surface of all the features of Friendica. But I can safely conclude that Friendica is more for power users and for people that want even more control over their stream and don’t want to get overwhelmed with a flood of information such as the local timeline in Mastodon. It lets you fine tune the information even better with easy one click selections of groups. It’s also for people that want to stay in contact with people over different parts of the Fediverse (e.g Mastodon and Diaspora*) and want to be able to keep these contacts manageable in one single stream together with hashtags and RSS feeds.

Friendica local news stream fills the time line with news (in my case mostly German)
A forum on Friendica which allows for special topics to be discussed.
Categories
open source social

To improve Funkwhale

I’ve been following Funkwhale for a while now and have written earlier about the project. Before I start I want to make clear that I love Funkwhale and I’m thankful to the developers and other contributors that have made it awesome. Lately however it has become obvious to me that the project could get more traction if the social interaction between users would be improved. Currently a user can do little to interact with an artist or other users. Also the interface can be confusing for people that are new to Funkwhale. It’s therefore that I’ve come up with some tips for the developers to tweak Funkwhale to provide the user a better experience.

But first what is Funkwhale. If you already know you can skip this paragraph and the next. Funkwhale lets you listen and share music and audio within a decentralized, open network. So you can upload your music library and share it with friends and family. Music from the public domain or with a Creative Commons license can be shared with all Funkwhale users. Funkwhale currently consists of 53 known servers (called pods in Funkwhale) which can communicate together using standard, free and open source technology. Funkwhale uses the ActivityPub protocol that is often used in the Fediverse, an ensemble of federated servers.

Funkwhale is both for people that create music or podcast and people that just like to listen to it. You can join an existing pod or create your own pod. The last option provides the most control over your music or podcasts. Other than Soundcloud or Bandcamp, Funkwhale is not owned by a central organization. Instead it’s a federation of pods from different owners that share music and podcasts.

Currently the user can explore and listen to music that is uploaded by others. Basic functions like adding to favourites, adding to a playlist or downloading are in place but discoverability and social functions are either non-existing or poorly implemented.

Discoverability. I would love to see a Trending tab in the Explore section. This Trending tab could contain a list of songs that are favoured the most e.g in the last month and a list of songs that are listened to the most in that same period.

Social interaction. Furthermore it would be nice to be able to see number of ‘streams’ per song or the number of times a song is favoured. Maybe further down the line could be the ability to comment on a song although I’m aware of the moderation problems that may cause.

Interface. The interface of Funkwhale is confusing at first. It took me a while to make sense of it with terms like channels, libraries, playlists and radios. Sure they all sound familiar but the intricacies were lost to me in the beginning. I wish I had read the user manual of Funkwhale sooner but I suppose many users just don’t read manuals. Anyway channels are a collection of audio files published directly on Funkwhale. While libraries are used to store collections of music such as your personal music collection or a collection of publicly available music. So a channel would be more for an artist to publish his or her own creations while libraries is for uploading work from others. Playlist have more or less the same function that they have on other music services. A user can create one, add or delete selected songs etc to a queue. Radios on the other hand enable the user to create a queue of music by a range of user defined parameters called filters (a pretty cool feature if you ask me). In addition the interface of Funkwhale has a great number of inconsistencies. To name just one when I open the queue I’m unable to favourite or get more information about any queued song. To conclude this part, the interface of Funkwhale offers a lot of great options but needs to be made more consistent and simplified for the user.

Funkwhale has so much potential and it’s, as far as I know, the only software out there that allows musicians and music listeners to share music and socially interact at the same time in a network without the burden of a centralized network where one organization tells you what you can and cannot do. The Funkwhale project is young and in its infancy so I’m convinced that it will improve over time and that the issues that I mentioned will be addressed. In the mean time I’ll enjoy using Funkwhale when listening to my own library of music, explore what music other have uploaded or just listen to my favourite podcast.

Some useful links for Funkwhale:

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
Linux open source PC

Peeling the onion

About five years ago I got interested in free and open source software (FLOSS) and online privacy in general. The problem was that almost all software that I used at that time was proprietary. I had an iMac with OSX and besides that I worked a lot with Google apps (Gmail, Blogger and Google Docs most notably). From that point it felt as pretty daunting task to switch completely to FLOSS. Where to start? Just installing Linux on my iMac seemed far to large a step. How to migrate all my documents and learn to work with a OS and all these apps that were new to me. Instead I decided a to gradually replace my apps with FLOSS alternatives until I finally reached a point where I could easily replace the OSX operating system with Linux.

I started with the low hanging fruit and the lowest hanging of them all is the web browser. So Chrome was replaced by Firefox. Next was the mail client so I replaced Mail with Thunderbird. At that time I started to work with graphical applications so I chose Inkscape, GIMP and for my 3D CAD work Solvespace, FreeCAD and OpenSCAD. I installed these apps on my iMac still running OSX and took my time to get familiar with them.

For my simple video editing tasks I kept lazily working with iMovie for a long time. I tried OpenShot but it kept crashing but after I while I discovered Shotcut which I found a better replacement. More recently I discovered Avidemux which is simple and works on lightweight systems. Next was Darktable instead of Photos to organize the thousands of photos that I have.

To replace Google proved to be even more difficult. Google is everywhere. The easiest one is Google Search. I first replaced it with DuckDuckGo. DDG is not FLOSS but at least it’s not Google. Currently I’m experimenting with MetaGer which is free and open source software. Google Maps was replaced by Openstreetmap and to upload my content I exchanged YouTube for PeerTube. This was all pretty simple. Next was Google Drive and this proved to be more difficult. I figured the best was to replace Google Drive with NextCloud. But instead of having someone else running NextCloud for me I found it appealing to have my own server. But I don’t know anything about installing and maintaining a server. Then someone mentioned Yunohost to me. Yunohost is an operating system that allows an idiot like me to setup and manage a server in a very simple way. Installing it went flawless and installing NextCloud on top of Yunohost encompassed little more than a few mouse clicks. After this I could say bye bye to Google Docs.

In the mean time I felt confident enough to replace OSX with Linux. With all the preparation that I had done it was an almost painless transition. I downloaded a Linux distro, put on a USB drive and installed it on a PC (not the iMac). Next I could install all the FLOSS apps that I was already familiar with and I was up and running in no time.

I’d like to call this method Peeling the Onion. Where the onion is the problem. Remove the outer most peel first and working my way to the inside. I work pretty much exclusively with FLOSS now and I couldn’t be happier with the result. I feel more in control of the software and and my data which is a very satisfying experience. Yes, some of the software is little bit rough around the edges and not as smooth as some of the proprietary software I was used to but I feel that I’m at the helm of my PC without a giant cooperation driving me into a direction that I don’t want.

Categories
open source

Your music library and MusicBrainz Picard

With all the steaming services available why have your own digital music library? The reason for this is two-fold. First streaming services like Spotify or Deezer have a constant changing library of music as a consequence of the agreements that they make with rights holders. This means that music in your playlist can suddenly disappear (or being greyed out) or, what happened to me, explicit songs are being replaced by clean ones. The latter can cripple them to a point that they aren’t listenable any more. What the examples demonstrate is that eventually you have limited control over the music of these services. Secondly the service itself can change e.g the app that you’re relying on disappears as happens with the Spotify app on my Squeezebox network music player.

Alternatively you can build your own digital music library e.g from your CD collection. This is called ripping and is done with software such as the free and open source Asunder. Asunder creates nice digital music files in the audio coding format that you desire. It can even add metadata to the file by checking an external music database. The process of adding or changing metadata is called tagging. The result of this process is often incomplete and results to gaps in the music collection. This is where MusicBrainz Picard comes in. It’s a tag editor that can fill all these gaps and it’s pretty good at it.

To work with MusicBrainz Picard open a music file, a folder with music files or even multiple folders with music files. MusicBrainz either gets the missing metadata by comparing it with it’s own. If that fails MusicBrainz Picard can get the correct metadata with acoustic fingerprinting. This compares part of a song with their huge online database of MusicBrainz to find the right song and add the correct metadata. After everything is done just save the info to the music files and your done.

Another powerful option of Picard is to organize your all your digital music file. To do this just select all the music and drag it into Picard. This video https://yewtu.be/watch?v=02fWYIur42g demonstrates just how powerful this option is (alternatively you can also watch the video here: https://www.youtube.com/watch?v=02fWYIur42g).

MusicBrainz Picard and the MusicBrainz database are projects of the MetaBrainz Foundation. MetaBrainz Foundation has a philosophy of free, open access of data. It has been set up to build community maintained databases and make them available in the public domain or under Creative Commons licenses. Most contributions come from volunteers so users are encouraged either to donate or contribute to the data gathering process.

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