Introduction: Design With OpenSCAD Linear and Circular Pattern: Lego Duplo Build Plate

About: I am mechanical engineer and I work on robotic mechanical design. I am running my startup and sometime working on my design hobby.

This is an example of using OpenSCAD designing linear and circular pattern for 3D printing. 

What are the linear pattern and what is circular pattern?

To simplify the terms, when you have an instance and you want to distribute it in X and Y directions that's the linear pattern or you want to distribute them on a circle, it's a circular pattern. The question is can you do this with the normal CAD software and how?

Every CAD software has it own pros and cons. Normal CAD software unusually has problem with large size array. For this Lego Duplo build plate, I first tried with FreeCAD, it works fine with the small size (4x4) but when I tried to make the bigger size like 12x12, it crashed. In the opposite, OpenSCAD works faultlessly.

Step 1: Linear Pattern With Lego Build Plate

Here are the parameters of the build plate I want to make. Basically it is a 2D arrays of button on a plate. Each button is a cylinder with diameter d1. The distances in X and Y directions are deltaX and deltaY accordingly. 

First, let's make the instance. In this case, it is a Lego Duplo button with diameter d1 and height.

d1 = 9.4;         // Duple button's diameter (mm)
height = 4.5;       // Duplo button's height (mm)
thickness = 1.2;  // Base's thickness (mm)
cylinder(height+thickness,d=d1);

Now, to make an array in X direction we need to define the number of instances n as well as the distance between 2 instances. Adding a for loop as a function of n and deltaX will give us all the center points of all the buttons.

d1 = 9.4;    // Duple button's diameter (mm)
height = 4.5;    // Duplo button's height (mm)
thickness = 1.2;  // Base's thickness (mm)
deltaX = 16;    // Center distance between 2 buttons X(mm)
n = 12;      // Number of buttons

for(i =[0:n-1])
  translate([i*deltaX,0,0])
  cylinder(height+thickness,d=d1);

So that is how you make a linear array in X direction. If you want to make a 2D array in both X and Y directions, we need to define the distances as well as the numbers of buttons in each direction. There are more parameters such as numbers of rows, columns, and the distances deltaX, deltaY. We will need another for loop for Y direction. 

d1 = 9.4;           // Duple button's diameter (mm)
height = 4.5;       // Duplo button's height (mm)
thickness = 1.2;  // Base's thickness (mm)
deltaX = 16;        // Center distance between 2 buttons X(mm)
deltaY = 16;        // Center distance between 2 buttons Y(mm)
row = 6;            // Number of rows
col = 12;           // Number of columms

for(i =[0:col-1])
    translate([i*deltaX,0,0])
    for(j=[0:row-1])
        translate([0,j*deltaY,0])
        cylinder(height+thickness,d=d1);

The last step is adding the base for these buttons. You can simply use the cube function 

translate([-deltaX/2,-deltaY/2,0])
  cube([col*deltaX,row*deltaY,thickness]);

Or to be more beautiful, fillet all the square corners of the rectangle base with a fillet_radius of deltaX/2

fillet_radius = deltaX/2;

points = [ [0,0,0], [(col-1)*deltaX,0,0], [0,(row-1)*deltaY,0], [(col-1)*deltaX,(row-1)*deltaY,0] ];
    rounded_box(points,fillet_radius,thickness);
 
module rounded_box(points, radius, height){
    hull(){
        for (p = points){
            translate(p) cylinder(r=radius, h=height);
        }
    }
}

Using this code, you can make the Lego Duplo build plate at any size you want.

Step 2: Circular Pattern

Now let' talk about circular pattern. Like in the coaster photo, instances are distributed on a circle. To understand this, let's have a look at the polar coordinate. Each point in the space is defined by the parameters radius r and the angle phi. Basically, we need to translate this polar coordinate of r and phi into the x and y Cartesian coordinate because we want to present them on openSCAD. The translate equations are x = r*cos(phi) and y = r*sin(phi)

d1 = 9.4;           // Duplo button's diameter (mm)
thickness = 1.2;    // Base's thickness (mm)
height = 4.5;       // Duplo button's height (mm)

n = 8;              // Number of instances
delta = 360/n;		// Angle between instances
r= 25;

for(i =[0:n-1])
{
    phi = i*delta;
    translate([r*cos(phi),r*sin(phi),thickness])
        cylinder(height,d=d1);
}

If you add another for loop, you can spread the pattern along r. For example, I add another for loop in which I have the j parameter of [0.5, 1, 1.5]. Then I multiplied that j into the radius r so basically I have 3 values of the radius r

for(i =[0:n-1])
{
    for(j = [0.5,1,1.5])
    {
        phi = i*delta;
        translate([j*r*cos(phi),j*r*sin(phi),thickness])
        cylinder(thickness,d=d1);
        
    }
}

Now we have the three circular patterns over the r. Each of them has eight instances on it.

The last step now is adding a base to have a coaster for example.

difference(){
    cylinder(height,d=4*r+2*thickness);
    translate([0,0,thickness])
    cylinder(height,d=4*r);
}


Step 3: Have Fun

This is how I use OpenSCAD to design my linear or circular patterns. I hope it will be useful for you with your design. Have fun playing around with the pattern and get something nice for yourself.

Happy making.

Made with Math Contest

Participated in the
Made with Math Contest