< back to home

Computer-Aided Design

Goals

2D design

ImageMagick

The Swiss Army knife of 2D graphics, ImageMagick let me process an humongous number of formats; this software suite has no GUI and runs from your terminal, thus allowing easy integration in scripts
During this assignement it has been used mainly to record screenshots of my work with the following command:

            
import -window WIN-ID -quality 85 OUTPUT.PNG
            
          

you can get your window id with the "xwininfo" command in order to capture a single window or, if you want to grab the whole screen, use the "root" value.
The images taken with this command are needlessly big, so let's bulk resize them with this command:

            
convert *.png -resize '960x>' cropped-%d.png
            
          

ImageMagick will procede to shrink only the .png files which are wider than 960px, preserving their aspect ratio and renaming them with a progressive number.

As a final note I tried to make an animated gif. As you may remember during the last lecture (1st February) mr. Bas Withagen was wearing a pair of safety goggles while working on something that involved lasers. That left quite an impression on me and I quickly got down to work.
The screenshot taken with my mobile was too big and dull for what I wanted to attain so I shaved off the top and bottom parts and increased the saturation:

            
convert bas.jpg -shave 10x300 -modulate '100,200,100' bas_ts.jpg
            
          

The resulting image has then been resized and rotated:

            
convert bas_ts.jpg -resize 200x200 -rotate 90 minbas1.jpg
            
          

I repeated this operation other 3 times, increasing the rotation angle by 90 degrees each time, thus obtaining four 200x200 images.
I then dowloaded and resized other 2 gifs (the "!" after the geometry forces a resize to the detriment of aspect ration).

            
convert laserrave.gif -resize 200x200! minlaser.gif && convert viking.gif -resize 200x200! minvik.gif
            
          

Finally I put all together, duplicating the .jpg in order to make them last for multiple frames, actually "slowing" them.

            
convert minlaser.gif minlaser.gif minbas1.jpg -duplicate 3 minbas2.jpg -duplicate 3 minbas3.jpg -duplicate 3 minbas4.jpg -duplicate 3 minbas1.jpg -duplicate 3 viking.gif -loop 0 result.gif
            
          

And here is the result:

No Transformers or Techno Vikings were harmed during the making of this gif, and we hope intensely that mr. Withagen's feelings won't be hurt by what is meant to be a harmless joke.

ImageMagick proved to be a powerful and versatile tool and, given enough time to read its extensive documentation I'm sure I'll find other uses for it.

3D design

FreeCAD

Solidworks is the go to choice for solid modeling in my Lab, but it's not avaible for GNU/Linux, so I decided to try FreeCAD.
I was immediately overwhelmed by the interface, and I spent the first hours reading the official documentation and watching a several video tutorials: 1, 2
After that, still lacking any clue, I started drawing my "machine", using a geometric constrained sketch:

After the extrusion, a litte fiddling with the fillet setting and a clone I got the supports part for my machine:


The axis were created in a similar fashion, but translating them proved to be a tiresome experience till I discovered the Edit > Alignment feature:


The biggest problem I faced was how to rotate things: by default FreeCAD sets the rotation center at the axis origin, but I wanted to rotate a simple object (in this case my mock up pen) over its own axis; in the end I was not able to change the center (I know for sure it is doable by python scripting), so I was forced to reposition the pen after the operation:


In the end this is what I was able to make:

The source file can be downloaded from here.

FreeCAD is obviously a very powerful tool with a high skill ceiling. I am sure this software will be an invaluable companion for this FabAcademy, provided that I can harness its power.

OpenJSCAD

My initial plan was to use OpenSCAD to make a parametric model, but I was quickly put off by the idea of learning its programming language (truth to be told it is quite straightforward, but my struggle with FreeCAD left me weak in body and mind).
I was suggested by my guru Fiore Basile to take a look at OpenJSCAD, a 2D and 3D modeling tool similar to OpenSCAD, but web based and using Javascript language; I took this as a good opportunity to learn a little JS and dived in.
OpenJSCAD offers, in my opinion, several benefits over OpenSCAD, the most notable being its web based nature (sharing files and code is a breeze) and the ability to list the project parameters in their own panel, thus preventing the need for editing the actual code.
The first problem I stumbled upon was my inability to draw a 2D primitive on the ZX plane:


A fast glance at OpenSCAD documentation told me that is by design: the Z axis is the only one avaible for rotating 2D shapes.
After this initial setback things proceeded smoothly and I was able to put together something similar to my FreeCAD sketch:

The .jscad file is freely avaible (and editable!) here. It is by no means perfect (I need to apply a few restrains to some parameters) but I really enjoyed working with OpenJSCAD.
Here is the code for quick reference:

            
function getParameterDefinitions() {
    return [
        { name: 'axis_radius', type: 'float', initial: 0.5, caption: "Axis radius:" },
        { name: 'axis_length', type: 'float', initial: 30, caption: "Axis length:" },
        { name: 'slider_position', type: 'float', initial: 4, caption: "Slider initial position:" },
        { name: 'slider_body', type: 'float', initial: 4, caption: "Slider body length:" },
    ];
}
var w = [];

function supporto(radius) {
    var test = CAG.fromPoints([ [0,0],[10,0],[5,10]]);
    var cil1 = CSG.cylinder({start: [4,4,0], end: [4,4,4], radius: radius});
    var cil2 = CSG.cylinder({start: [6,4,0], end: [6,4,6], radius: radius});
    var cil3 = CSG.cylinder({start: [5,2,0], end: [5,2,6], radius: radius});
    test = test.extrude({offset: [0,0,1]});
    return test.subtract(cil1).subtract(cil2).subtract(cil3);
}

function gruppo_assi_01(radius, length) {
    var asse01 = CSG.cylinder({start: [4,-1,4], end: [4,length,4], radius: radius});
    var asse02 = CSG.cylinder({start: [6,-1,4], end: [6,length,4], radius: radius});
    var asse03 = CSG.cylinder({start: [5,-1,2], end: [5,length,2], radius: radius});
    return [asse01.setColor(0,0,1), asse02.setColor(0,0,1), asse03.setColor(0,0,1)];
}

function carrello01(start_position, body, radius, length) {
    var corpo = CSG.cube({corner1: [3,start_position,1], corner2: [7,start_position+body,5]});
    for (numero_asse = 0; numero_asse < 3; numero_asse++){
        corpo = corpo.subtract(gruppo_assi_01(radius, length)[numero_asse]);
    }
    return corpo;
}

function main(params) {
    var axis_radius = params.axis_radius;
    var axis_length = params.axis_length;
    var slider_start = params.slider_position;
    var slider_body = params.slider_body;
    w.push(supporto(axis_radius).rotateX(90));
    w.push(supporto(axis_radius).rotateX(90).translate([0,axis_length,0]));
    w.push(carrello01(slider_start, slider_body, axis_radius, axis_length));
    w = w.concat(gruppo_assi_01(axis_radius, axis_length));
    return w
}
            
          

I just started scratching the surface of this tool and, at the time of writing, can't fathom building non trivial models with it; but I'm sure it is very powerful and I definitely keep using it (and hopefully improve my js: two birds with one stone).

Links and files