Wednesday, March 29, 2017

Creating interactive 3D models in your browser with Solvespace

Interactive 3D model

It may be convenient to view a interactive model made in Solvespace using a webbrowser. For instance if you want to share the model with someone who hasn't Solvespace installed. Luckily Solvespace has an option just for this under File -> Export Triangle Mesh. Now in the dialog window select Three.js-compatible mesh with viewer (html). Save the file. An html file is now available that can be viewed in the browser (I only had succes with Firefox, Chrome wouldn't show me the model). The html file created by Solvespace consist for a large part on Javascript and relying on the Three.js Javascript library. All the points, edges and faces of the 3D model are included in this file.

Screenshot of the html file created by Solvespace and opened in the Firefox browser.

When the html file is opened the 3D model can be rotated (left mouse button), moved (right mouse button) and zoomed (scroll wheel). The options are activated by a mouse click in the frame. Clicking on the scroll wheel deactivates these options.

One step further

This can be taken one step further. The model can be integrated in a website. The simplest way is to use the <iframe> tag in html. Below is a simple example where cube.html is the file that has been generated by Solvespace.

<!DOCTYPE html>
    This is a cube
        <iframe src="cube.html", height="600", width="800"></iframe>

That's it, the interactive model will show up in the webpage which is a pretty cool Solvespace feature. BTW: I didn't bother demonstrating it in Blogger because I think it's to much of a hassle editing the template.

For this tutorial I used Solvespace 2.3 on OSX.

Solvespace is open source (GPLv3 license) and is available for Window, OSX and Linux. It is developed by Jonathan Westhues and maintained by whitequark and others. It can be downloaded here:

Friday, March 17, 2017

Creating a mathematical rose in OpenSCAD


In my previous blog post I explained how to create complex 2D shapes in OpenSCAD. Once a mathematical expression for a shape is known it's possible to translate it to OpenSCAD script. The Carthesian coordinates of mathematical rose, a rose shaped sinusoid, can be expressed by x = cos(kθ)cos(θ) and y = cos(kθ)sin(θ). If k is an integer a the shape will be relatively simple but is k is a fracture more complex shapes are created.

One of the shapes that can be created with the rose_points function (linear_extrude is used to create a 3D shape).

Writing the script

All the points needed to create the rose will be generated in the function rose_points. Rose
_points returns these points in a list. The function will have the form:

function rose_points(k,n,radius) = [...]

The parameters k and n will determine the shape of the rose. If n = 1 the curve will a simple rose shape but if n > 1 more complex shapes are drawn. Here is a link to all the possible shapes when varying k and n. The syntax of OpenSCAD for lists allows us to use if and for elements to construct a list. In the case of our function we can use these elements.

step = 1;
function rose_points(k, n , radius) = k%2 == 0 && n%2 ==1 ? [for (theta = [0 : step : 360 * n]) [radius * cos(k/n*theta) *sin(theta), radius * cos(k/n*theta) * cos(theta)]] : [for (theta = [0 : step : 180 * n]) [radius * cos(k/n*theta) * sin(theta), radius * cos(k/n*theta) * cos(theta)]];

color("red") polygon(a);

The function looks intimidating at first due to the list comprehensions.  The key is to just break it apart. The two parts between square brackets contain lists of points (generated by a for loop). The rest is an if, then, else statement: if k is even and n is uneven then [] else []. More information on the syntax for a list (list comprehensions) can be found here.

The function isn't perfect. With some combination of k and n (e.g. 6 and 2) nothing is displayed on the screen. The reason is that with this combination all points are repeated prompting the polygon function of OpenSCAD to draw nothing. In this cases it helps to change the range of theta.

Caveat: List comprehensions as shown in the rose_points function 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. 

Shape created with k = 2 and n = 1.

Shape created with k =8 and n = 7.

Friday, March 10, 2017

Creating complex 2D-shapes in 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 functions for some simple 2D shapes and explain how to manipulate the functions make more complex shapes with them.

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


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

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 create 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 generalisation 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));

Ellipse created with the code above.

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.


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 polyhedron function of OpenSCAD should be used. This however is a topic for a future blog entry.

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. 

A special thanks to Xavier Faraudo who explained the advantages of functions in OpenSCAD to me.

Saturday, March 4, 2017

Getting creative with OpenSCAD


OpenSCAD is software to create solid 3D CAD Models but other than most 3D CAD programs a model can be created with a programming language. Although OpenSCAD is often used to create models for 3D printing it also very capable as a tool for creative coding. Creative coding is more about being expressive than being functional.

Sierpinski triangle made in OpenSCAD (recursive algorithm).

Creative coding

I've been using OpenSCAD for over a year now for my 3D printing projects but as of late I'm exploring the creative possibilities of this programming language. It all started when I was watching another episode of The Coding Train, a great and often hilarious YouTube channel from Daniel Schiffman. In this show Daniel Schiffman takes on coding challenges. These coding challenges can be a physics simulation, data visualization or computer vision. While watching the show I was wondering which tool would be suitable to take on these challenges myself. Schiffman is mainly using Processing and P5.js which aren't in my skill set. I have a basic understanding of Python but not enough to start coding these challenges. OpenSCAD has become the programming tool that I'm most familiar with so I figured to give it a try.

OpenSCAD is pretty well equipped for creative coding. No need to import additional modules or libraries to draw onto the screen. It also comes with ready to use 2D and 3D primitives, geometric transformations and boolean operations for 2D and 3D primitives. OpenSCAD is a functional programming language as opposed to most common programming languages such as Python, C and Java which are imperative languages. In OpenSCAD variable keeps one value so i  = i + 1 won't work and f(x) will always produce the same result for a given x (as in mathematics). Once you get your head around that working with OpenSCAD becomes easy.

OpenSCAD doesn't disappoint for creative coding. Although some challenges didn't seem possible with OpenSCAD, because of the limited animation features of the program (or my lack of understanding of these features, others could be easily achieved with it. Below are examples of challenges that I did with OpenSCAD.

Mathematical rose pattern made in OpenSCAD.

Phyllotaxis pattern made in OpenSCAD.

Along the way I discovered that I'm not the only one using OpenSCAD for creative programming. I like to mention the website which has an excellent OpenSCAD section. This section not only explains the underlying fundamentals of OpenSCAD but also has creative chapters about spirals, turtle graphics and maze.

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.

Saturday, January 28, 2017

DIY Hangboard (for climbers)


My youngest son is an avid climber and boulderer and he wanted a hangboard in his room to strengthen is arm, hands and fingers etc. I had a lot of wood left from previous projects so I used some of it to build the hangboard. After searching the internet and seeing a lot of examples we came up with the drawing below.

My son using his newly acquired hangboard for training.

Simple hangboard design.
The backplate and frontplate are made of 12 mm (1/2") plywood while the beams and support beams are made of 30mm (1 1/4") scaffolding wood. The rails are of pine wood of various thickness, 1 1/4" being the thickest and 18mm (3/4") the thinnest. The support beams strengthen the construction considerably.

Parts list

Here are the parts that are needed for this build.
1 x backplate 90 x 61 cm (3' x 2') plywood (12mm or 1/2")
1 x frontplate 90 x 31 cm (3' x 1') plywood (12mm or 1/2")
2 x beam 30 x 19 cm (12"x 7.5") scaffolding wood (30mm or 1 1/4")
2 x support beam 41.5 x 6.2 cm (14" x 2") scaffolding wood (30mm or 1 1/4")
2 x rails 90 x 5 cm (3' x 2") pinewood of various thickness
8 x carriage bolts 6mm (1/2")
8 x wingnut 6mm (1/2")
4 x lag screws 7 x 60mm (5/16" x 2.5")
4 x wall plug fisher 10 mm (3/8")
18 x twinfast screw 4.5 x 40mm (3/16" x 1 1/2")

Building the board

Building the board is straight forward. First I'd cut the plywood to the plates with the size indicated above. Next I'd cut the scaffolding wood for the beams. I used a simple Dremel DSM20 for this but any circular saw will do. Lastly I'd cut the pinewood beams. I used a router to make a radius on one side of the beams. This radius ensures that the beams are easier on the hands.

With all the pieces cut, I drilled the holes in the backplate, frontplate and rails. Next I assembled all the parts. Starting with the backplate and the beams. I used a 3mm drill before fastening the beams and the plywood with the twinfast screws. This avoids that the wood splits open. The beam and supportbeam were fastened with a single twinfast screw. Next I fastened the frontplate to the beams again using twinfast screws. To finish the hangboard I fastened the beams to the frontplate using the carriage bolts and wingnuts. Lastly I applied a transparent oil to the hangboard to provide protection It's more pleasing to look at too.

Fastening the hangboard to the wall may differ from situation to situation but since we have concrete walls I used four large wall plugs (Fisher brand). The board was then attached to the wall using the lag screws with washers to protect the wood.

Assembling the hangboard. Clamps of various size are very useful in situations like this.

The finished hangboard attached to concrete wall with four large wall plugs, lag screws and washers.

Inside view of the hangboard. By removing four wingnuts the beams can be exchanged for smaller of wider ones.
Detailed view of the lag screw and washer on the plywood backplate.


The hangboard proves to be strong enough for my son (he weights approximately 65kg). I tried it myself (I'm 90kg) but my fingers just aren't strong enough to keep my weight. Nevertheless I'm confident that the construction is more than enough to keep a weight well over 65kg. As for esthetics the board looks pretty good (for a hangboard that is).

Monday, January 9, 2017

Peddle wheel boat (3D printed)


At the moment I'm making 3D design and 3D printing lessons for schools. A good idea that I'm exploring is the Paddle Wheel Boat. 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 the ground up with 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:

Assembled Paddle Wheel Boat.

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 positon 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 immediatly 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.

Peddle wheel loaded in Cura 2.3.1.

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 favorite slicer. After printing the Peddle wheel boat can be assembled and tested. Have fun.

All printed parts plus the rubber band.

Tuesday, November 22, 2016

Things you can do with PocketCHIP (other than gaming)


As a backer of the PocketCHIP Kickstarter I received the PocketCHIP a couple of months ago. For those who don't know, PocketCHIP is a very portable Linux computer.  It comes in a case complete with keyboard and screen. After receiving it I played with it but it soon ended up in the drawer. PocketCHIP is very nice and all but I just couldn't think of a killer app for it. Recently however I saw a YouTube video of SuperHouseTV who used PocketCHIP to reprogram Arduino's on remote places. This inspired me to get my PocketCHIP out of the drawer and do something useful with it. In this blog post I describe three different purposes that the PocketCHIP can be used for.

PocketCHIP, Arduino and breadboard peacefully together on my workbench.

Radiostreams and music

The PocketCHIP can be a very basic mp3-player. I first tried mpd with mpc as client but it was too much of a hassle. Next I installed mplayer and it worked flawlessly.

apt-get install mplayer

Now I can listen to mp3's and radio streams. For example to listen to a radio stream of  Dutch Public Broadcasting type:


or to run an mp3 or ogg file

mplayer <filename>

I noticed that the audio stream was interrupted when I did other things on the PocketCHIP (running CHIP 4.3) diminishing the usability. Hopefully this will change when the CHIP software will be optimized in the future. NOTE: The mplayer software is more than an audio player in fact it's a very capable media player.

Camera surveillance

Earlier I installed a Raspberry Pi based camera system to keep an eye on our backyard. I wanted the PocketCHIP to connect with the Pi not only for maintenance but also to check the backyard from. This proved to be surprisingly easy. First login from the PocketCHIP to the Pi using SSH:

ssh pi@ (change the ip address to your own)
your password

Next I use simple surf webbrowser to stream the video from the Pi to the screen of my PocketCHIP.


and presto a video stream of my back yard is shown on the PocketCHIP display.

Keeping an eye on my backyard with the PocketCHIP.

Programming an Arduino with PocketCHIP

as mentioned above the PocketCHIP can be connected to an Arduino to (re)program it. But I took it a step further. On the top floor of our house I have a hobby space. The Linux laptop (Puppy Linux) in the hobby space is very old and I'm unable to install the Arduino IDE on it. So I have the PocketCHIP with Arduino software installed connected with a USB cable to my Arduino UNO. With SSH I remotely connect my Linux laptop to the PocketCHIP and program the Arduino making use of the keyboard and screen of the laptop. This works great.

To install the Arduino software on PocketCHIP follow the instructions of SuperHouse. In addition to his instruction make sure to install the GNU make utility on PocketCHIP:

sudo apt-get install make

Now Arduino sketches can be written or changed on PocketCHIP and uploaded to the Arduino. Now to remotely connect to PocketCHIP I open the terminal program of the Linux laptop and type:

ssh -X chip@
your password

substitute the ip address of my PocketCHIP with the one of your own. The default password of PocketCHIP is chip. The -X option enables the X11 forwarding which is needed for the following step. Type in the terminal:


and after a few moments the Arduino IDE becomes visible on the laptop monitor enabling me to write, save, compile, build  and upload sketches from the PocketCHIP to the Arduino, remotely controlled by the laptop. Type:

make upload

To compile and upload the sketch from the PocketCHIP to the Arduino. Call me crazy but I really love this.

Working with the Arduino IDE on my laptop but running on the PocketCHIP.

Overview of my workbench with the Linux laptop on the left and PocketCHIP and Arduino side by side on the right.


These three purposes of the PocketCHIP reignited my interest in the platform.  The PocketCHIP has gotten a permanent place on my workbench which is much better than lying around in a drawer. I'm use it almost on a daily basis to program my Arduino. In the next months I hope to give some more tips on PocketCHIP and the things you can do with it (other than gaming).