It is one of those commands that I personal don’t find a lot of use for, but here and there I find ways it can make life easier.

For example:

Two sphere’s and a hull give us this pill shape:

hull(){ sphere(r=5,$fn=50); translate( [20,0,0] ) sphere(r=5,$fn=50); }

Just for this article I made this Axe Head using hull and a few other commands. Don’t ask why, it just popped into my head. Is is a little more “Low Poly” than I wanted but it was interesting how easily I was able to complete it.

Here is the code I used:

One of the concepts this code highlight s is that hull() works on both 2D Object and 3d Objects

```
rotate([-90,0,0]){
hull() {
linear_extrude(1)
square([5,20],center=true);
rotate([30,0,0])
rotate([0,-90,0])
rotate_extrude(angle=60,$fn=50)
translate([40,0] )
circle(.1,$fn=50);
}
difference() {
union() {
hull(){
translate([0,0,-20])
linear_extrude(1)
square([5,20],center=true);
translate([0,0,-10])
linear_extrude(1)
square([5,25],center=true);
}
hull(){
translate([0,0,-10])
linear_extrude(1)
square([5,25],center=true);
linear_extrude(1)
square([5,20],center=true);
}
}
translate([0,50,-10])
rotate([90,0,0])
linear_extrude(){
hull($fn=50){
translate ([0,0]) circle(r=2);
translate ([0,3]) circle(r=1.5);
translate ([0,-3]) circle(r=1.2);
}
}
}
}
```

2d vs. 3d Hull

the hull command coan be used in the 2d sub-system or the 3d system

2D Hull

3d Hull

hull to make a simple cam, using cylinder.

Before hull()

After hull()

Simple code for this cam:

```
CAM_OFFSET=30;
hull(){
cylinder(h=20,r=30);
translate([CAM_OFFSET,0,0])
cylinder(h=20,r=10);
}
```

Hopefully this gives you some ideas on what to use hull() for, I will keep looking looking for some best use case.

]]>OpenSCAD does not have a built in Array command but we can easily create an array with a for loop, or even create an array module, and have our own command.

If you have not already learned about using for loops in OpenSCAD take a look at this tutorial:

To create a linear array in OpenSCAD is pretty straight forward. The measurements will be embedded in the Step and End values of the Loop.

Normally a basic forloop in OpenSCAD looks like this

for ( i=[start:count:end] )

But for our linear array we can think of like

for (i =[ origin : spacing : distance ] )

So in the example below, we have a cube 5 unit cube at 0,0 then one cube every 10 units, in both the X and Y direction, ending with a cube centered at 100 units.

for ( i=[0:10:100]) { translate([i,i,0]) cube(5,center=true); }

With an additional loop we can create a grid of objects.

for ( i=[0:10:100]) { for ( j=[0:10:100]) { translate([i,j,0]) cube(5,center=true); }}

The Polar array is very similar, but instead of translating we use the loop value in a rotate command.

Just like linear array we can re-think of our for loop like this.

for ( i=[ START OF ARC: DEGREES: END OF ARC )

We use the translate([]) command to add a radius to the polar array. The radius will be the axis perpendicular the rotational axis, for a basic polar array.

translate([0,RADIUS])

To create a full polar array we start at zero degrees and go all the way around to 360 degrees.

for ( i=[1:10:360]) { rotate([i,0,0]) translate([0,30]) cube(5); }

It is fairly simple to create arc segments. The following code we create an array of cubes from 90 degrees around the x Axis to 180 degrees.

for ( i=[90:1:180]) { rotate([i,0,0]) translate([0,30]) cube(5); }

We can easily create a linear array “command” using the module and children command. We will create a basic linear array that extends on a single axis and uses spacing to create a number of objects. This version will always make an array of whatever object it precedes on the X axis

linear_array( 10,10) cube(5); module linear_array( count, spacing ){ for ( i=[0:spacing: spacing * count]) { translate( [i,0,0]) children(); } }

Our polar array works similarly to the linear array but instead of linear spacing we give the module the number of items and the spacing in degrees. We need a third parameter for the radius of the array. The result polar array will be a full circle only when the count and degrees multiply to 360, otherwise it will always be an arc starting from 0 degrees

polar_array( 20, 18, 30 ) cube(5,center=true); module polar_array( count, degrees, radius ){ for ( i=[0: degrees: count * degrees]) { rotate( [i,0,0]) translate([0,radius,0]) children(); } }

Here are the two of them, so you can use them in your code, or add them to your library folder.

```
module linear_array( count, spacing ){
for ( i=[0:spacing: spacing * count]) {
translate( [i,0,0])
children();
}
}
module polar_array( count, degrees, radius ){
for ( i=[0: degrees: count * degrees]) {
rotate( [i,0,0])
translate([0,radius,0])
children();
}
}
```

]]>Although concept wise, this may not be “easy”, it is easy in the sense it is concise and demonstrates some efficient concepts

- 2d Subsystem
- square()
- offset()

- 3d System
- hull()

- linear_extrude()
- rotate_extrude()
- scale()
- resize()

- Modules
- List Comprehension

We get started by making the walls using the 2d subsystem. But before we do this let’s add some global variables that we will use throughout the tutorial. Add these to your OpenSCAD ide. ( The comments are for the customizer )

BOX_W = 80; // Box Width BOX_L = 120;// Box Length BOX_H = 12; // Box Height SCREW_SIZE = 3; // Screw size in mm CORNER_RADIUS = 3; // Radius of corners WALL_THICKNESS = 2;// Wall Thickness

Then add a square() after the variables using the Width and Length

square( [BOX_W, BOX_L] );

We will round the corners with offset() command, place this offset() before square().

offset(r=CORNER_RADIUS) square( [BOX_W, BOX_L] );

Next we will remove the inner portion, with difference() and another square(). We will subtract the wall thickness to remove all but the wall.

difference(){ offset(r=CORNER_RADIUS) square( [BOX_W, BOX_L] ); square( [BOX_W-WALL_THICKNESS, BOX_L-WALL_THICKNESS] ); }

There are two things we will need to adjust. First the inner wall is not positioned well, so let’s center both squares

difference(){ offset(r=CORNER_RADIUS) square( [BOX_W, BOX_L],center=true); square( [BOX_W-WALL_THICKNESS, BOX_L-WALL_THICKNESS],center=true); }

Now let’s use offset() to add an inner radius. To calculate the inner radius we will subtract the wall thickness from the corner radius.

difference(){ offset(r=CORNER_RADIUS) square( [BOX_W, BOX_L], center=true );offset( r= CORNER_RADIUS - WALL_THICKNESS )square( [BOX_W-WALL_THICKNESS, BOX_L-WALL_THICKNESS], center=true); }

Lastly for the wall , we just nee to give it height. We can use lienar_extrude to give th box height. Add a linear_extrude() using BOX_H for the parameter, on the line above the difference.

linear_extrude( BOX_H )

We want a bottom that has rounded edges. This is where hull() comes in we can use hull() with four spheres() to create a rectangle with rounded edges. We want to add four, we we use list comprehension so we don’t have endless translates().

First we will create a list of coordinates.

coordinates = [ [0,0], [0,120], [80,120], [80,0] ];

Then we will use the coordinates variable in a for loop to iterate through using a for loop.

for (i = coordinates)

every time through the loop we will add a sphere and translate it by the coordinates. Here is the full piece of code to add:

coordinates = [ [0,0],[0,BOX_L],[BOX_W,BOX_L],[BOX_W,0] ]; for (i = coordinates) translate(i) sphere(CORNER_RADIUS);

Now let’s put that entire object into a hull() Notice how you don’t need to add brackets {} as the for loop is the direct child of the hull(). As a result hull works on the results for the for()

coordinates = [ [0,0],[0,BOX_L],[BOX_W,BOX_L],[BOX_W,0] ]; hull() for (i = coordinates) translate(i) sphere(CORNER_RADIUS);

We will need to translate the resulting hull so it is under the wall. Add a translate above the hull() using half the box width and half the box length. Let’s also ad $fn=25; at the very top of our code so we can see things a little better.

translate ( [-BOX_W/2, -BOX_L/2] )

We can add cylinders for screws the same way we made the four spheres. We already have the coordinates from the bottom so we can just use that. but we need to move them in some.

for (i = coordinates) translate(i) difference(){ cylinder(h=BOX_H,r=CORNER_RADIUS); cylinder(h=BOX_H,r=CORNER_RADIUS - SCREW_SIZE); }

I used rend ( f6 ) so we can see the holes.

NExt we need to move the posts to coincide with the box. place a translate() in front of the for() loop. This will move the whole”assembly” into position.

translate ( [-BOX_W/2, -BOX_L/2] )

That gives us cylinders, but they are to close to edge, we could create a second set of coordinates for the second loop, but it get’s pretty messy. It would look like this:

coordinates = [ [0+10,0+10],[0+10,BOX_L=-10],[BOX_W-10,BOX_L-10],[BOX_W-10,0+10] ];

Instead lets use resize() and scale() to do the same thing.

First use a resize() to set the four posts to their final position. The values will be the width and the length between the center of the posts . Add resize() in front of the for() loop for the cylinders. We will used fix values to start with.

resize([75,110,0])

You might notice that the posts are moved but they got smaller ( it is a small change). We can use scale to set the posts back to their original size. Add the scale command right before the difference for the cylinders.

scale([BOX_W/75,BOX_L/110])

Now the posts are the original size.

Here is a before and after. Really hard to see the difference but it is there.

Lets create a variable and see the whole code block. **Add POST_OFFSET=10; to the top of your code.** We will have to subtract that in the resize() and scale() from the box width and box height, we will use intermediaries so it is easier to understand. We also need to divide the SCREW_SiZE by 2 so it represents a radius, not the diameter given Let’s look at the code:

POST_OFFSET=10; ... other code ... p_w = BOX_W - POST_OFFSET; p_l = BOX_L - POST_OFFSET; resize([p_w,p_l,0]) // Move the posts in from the edge translate([-BOX_W/2,-BOX_L/2,0]) for (i = coordinates) translate(i) scale([BOX_W/p_w,BOX_L/p_l]) difference(){ cylinder(h=BOX_H,r=CORNER_RADIUS); cylinder(h=BOX_H,r=SCREW_SIZE/2); }

That’s all there is! There are some improvements we can make but this will work pretty well for now. Here is the final entire code to play with. Some important changes we would need are :

- Setting the floor ( bottom ) to WALL_THICKNESS
- Using a separate value or calculation for the outer cylinder of the post

But we will have to have a part two for that as this post is getting long.

```
$fn=25;
BOX_W = 80; // Box Width
BOX_L = 120;// Box Length
BOX_H = 12; // Box Height
SCREW_SIZE = 1.5; // Screw size radius.
CORNER_RADIUS = 3; // Radius of corners
WALL_THICKNESS = 2;// Wall Thickness
POST_OFFSET=10;
linear_extrude( BOX_H )
difference(){
offset(r=CORNER_RADIUS)
square( [BOX_W, BOX_L], center=true );
offset( r= CORNER_RADIUS - WALL_THICKNESS )
square( [BOX_W-WALL_THICKNESS, BOX_L-WALL_THICKNESS], center=true );
}
coordinates = [ [0,0],[0,BOX_L],[BOX_W,BOX_L],[BOX_W,0] ];
translate ( [-BOX_W/2, -BOX_L/2] )
hull()
for (i = coordinates)
translate(i) sphere(CORNER_RADIUS);
p_w = BOX_W - POST_OFFSET;
p_l = BOX_L - POST_OFFSET;
resize([p_w,p_l,0]) // Move the posts in from the edge
translate([-BOX_W/2,-BOX_L/2,0])
for (i = coordinates)
translate(i)
scale([BOX_W/p_w,BOX_L/p_l])
difference(){
cylinder(h=BOX_H,r=CORNER_RADIUS);
cylinder(h=BOX_H,r=SCREW_SIZE/2);
}
```

]]>Whereas I love math, I do not excel in the knowledge of said math or patience. So like many of us lesser skilled math enthusiasts I tend to look for the easiest way through a problem.

Some of the concepts we will use.

- Global Variables
- Array of Characters
- len() function
- for() loop
- rotate()
- text()
- linear_extrude()

Let’s Start with the text, you can use this tutorial to learn more about the text() command, for this tutorial start by adding simple text(); with one letter.

text(“T”);

We will need to extrude the letter so it has three dimensions. We will set the extrusion length to 1, or we will have a ten unit long T.

linear_extrude(1)text("T");

Being as we will be removing the text from the curved face of the cylinder we will need to rotate it so it is correctly oriented. The rotatation around the X axis will place the bottom of the letter on the XY Plane. The rotation around the Z Axis will face the letter flat to YZ Plane.

rotate([90,0,90])linear_extrude(1) text("T");

We will want to move the letter to the edge of cylinder so we will need a radius, lets kill two birds with one stone. Let’s add a RADIUS variable and use that. Then Translate our letter along the X axis ( because we are facing YZ plane ) the distance of the Radius.

RADIUS=20; translate( [RADIUS,0,0])rotate([90,0,90]) linear_extrude(1) text("T");

Now let’s add a Cylinder, but we will “disable it” so we can see what we are doing. Use the % modifier to make the cylinder translucent. Make the height 1 unit and center the cylinder on the origin. Centering will help a great deal with correctly aligning the text

RADIUS=20;%cylinder(r=RADIUS,h=1,center=true);translate( [RADIUS,0,0]) rotate([90,0,90]) linear_extrude(1) text("T");

Let’s move the extrusion into the cylinder so that we can see how it will remove material. We will just multiply the Radius by .95 so the letter doesn’t go out quite as far. Also, lets make the cylinder taller. Change h=1 to h=10.

RADIUS=20; %cylinder(r=RADIUS,h=10,center=true); translate( [RADIUS*.95,0,0]) rotate([90,0,90]) linear_extrude(1) text("T");

If we look from above we can see only part of the letter is remove. We want the face of the letter tangent to the wall of the cylinder. The text() command has alignment. and we can use that to complete the task.

RADIUS=20; %cylinder(r=RADIUS,h=10,center=true); translate( [RADIUS*.95,0,0]) rotate([90,0,90]) linear_extrude(1) text("T",valign="center",halign="center");

We have a perfectly embedded letter. If we use difference and remove the % we can get a good preview.

RADIUS=20;difference(){cylinder(r=RADIUS,h=10,center=true); translate( [RADIUS*.95,0,0]) rotate([90,0,90]) linear_extrude(1) text("T",valign="center",halign="center");}

This is all well and good for one letter but it won’t work for anything more. If we set the text to a word it just goes off to the sides, and won’t remove the correct material.

We will add an array of characters that can be added and rotated one at a time.

RADIUS=20;stext = [ "T","E","X","T" ];difference(){ cylinder(r=RADIUS,h=10,center=true); translate( [RADIUS*.95,0,0]) rotate([90,0,90]) linear_extrude(1) text("T",valign="center",halign="center"); }

This gives us four character to space evenly around the cube. Let’s add a for() loop to add all four letters. and the for() loop in line 5 and change the string “T” in the text command to stext[i]. As we loop through i will count up values 1 through 4 and that character will be added.

RADIUS=20; stext = [ "T","E","X","T" ]; difference(){ cylinder(r=RADIUS,h=10,center=true);for(i=[0:1:4]){translate( [RADIUS*.95,0,0]) rotate([90,0,90]) linear_extrude(1) text(stext[i],valign="center",halign="center");}}

That’s not enough though, as now we just have all four letters piled up on each other. We need to rotate the letter around the circumference. We can add another rotation to complete this task. We will add a rotate() that rotates the letter ( and it’s rotations and transforms ) around the Z axis by 90 degrees times the value of the variable i. We will end up with 4 roations 90,180,270,360. Don’t forget the brackets {} to enclose the entire text command with the extrusion, rotate and translate.

RADIUS=20; stext = [ "T","E","X","T" ]; difference(){ cylinder(r=RADIUS,h=10,center=true); for(i=[0:4:1]){rotate([0,0,i*90]){translate( [RADIUS*.95,0,0]) rotate([90,0,90]) linear_extrude(1) text(stext[i],valign="center",halign="center");}} }

We can even set the rotation to smaller values:

But we need to be more dynamic, so that it is easier to change the text. We can use the len() function to count the values in the array. Then we use that value in the for() loop and even calculate a rotation angle for the rotation.

RADIUS=20; stext = [ "M","Y"," ","T","E","X","T" ]; chars = len( stext ); difference(){ cylinder(r=RADIUS,h=10,center=true); for(i=[0:1:chars]){ rotate([0,0,i*360/chars]){ translate( [RADIUS*.95,0,0]) rotate([90,0,90]) linear_extrude(1) text(stext[i],valign="center",halign="center"); } } }

Now we are getting somewhere, but it would be nice to be able to constrain the text to just a portion of the cylinder. Let’s change the 360 used in the rotation to a variable. Let’s use ARC_ANGLE. Let’s set it to half the perimeter and make the text a little smaller with the size=, keyword. The size keyword set’s the total height of the text to the units given.

RADIUS=20; ARC_ANGLE=180; stext = [ "M","Y"," ","T","E","X","T" ]; chars = len( stext ); difference(){ cylinder(r=RADIUS,h=10,center=true); for(i=[0:1:chars]){ rotate([0,0,i*ARC_ANGLE/chars]){ translate( [RADIUS*.95,0,0]) rotate([90,0,90]) linear_extrude(1) text(stext[i],size=9,valign="center",halign="center"); } } }

So that is pretty much all you need to add text to side of a cylinder. And no complicated Trig. We could enhance this even further by making it a module, adding more Variables so it is more dynmic and probably more.

If you can think of a way to make it even easier ( other than use different software ) feel free to leave a comment.

]]>text( "Basic Text" );

This command can be translated and rotated just liky any other object in OpenSCAD, but keep in mind it is 2d first and needs to be extruded.

linear_extrude() text( "Extruded Text");

So the defaults for size are 10 for text size and 100 for linear_extrude let’s fix that by giving some sizes.

linear_extrude(3) text( "Extruded Text", size= 5);

The text is now 5 Units Tall, and it is extruded 3 units in thickness

We can change the Font Type using the Font keyword.

OpenSCAD can use any of the system fonts found in the installation. To make it easier to use a font stlye you can list fonts from the Help menu.

Click Help-Font List to get this list:

Select the font you would like to use and click “Copy to The Clipboard” This will copy the Font and Style in the correctly formatted string.

linear_extrude( 1)

text( "Text",size=5,font="Uechi:style=Gothic" , $fn=50);

We can place text into various orientation, by using the direction keyword. There are four directions we can organize lettering.

text( "Left to Right" ,size=5, direction="ltr"); translate([5,0,0]) text( "Up" ,size=5, direction="btt"); translate([20,0,0]) text( "Down" ,size=5, direction="ttb"); translate([0,10,0]) text( "Right to left" ,size=5, direction="rtt");

Horizontal alignment is in regard to to origin and the bounding box of the text. It is best explained visual. Take note of where the origin is for each alignment. The alignment is by length of the rendered text NOT by character count.

text( "Left Aligned" ,halign = "left" );

text( "Right Aligned" ,halign = "right" );

text( "Center Aligned" ,halign = "center" );

Below you can see the 3 vertical alignments. The alignment refers to were origin will align with the text.

text( "Text", valign="top"); text( "Text", valign="center"); text( "Text", valign="bottom");

There are a few more options for Text in OpenSCAD but the above are the ones you will use the most.

]]>The full code is at the end of the article but if you just want the goods you can go to the Models tab and get the code there.

We will be basing our bearing off the famous 802zz Skate Bearing. You can find a drawing of that model over at mathcodeprint.com

Or purchase a licensed copy at : https://www.teacherspayteachers.com/Product/Engineering-Diagram-for-608zz-Bearing-Basic–5719806

The inner race will be made simple by subtracting a circle from a cube.

First lets make the main body of the inner race.

Add add square where x = 7 and y = 2, then translate that square 5 units on the X axis. The inner Radius is 4 but because we turn centering on we need to add 1 to offset half the thickness of the square. Turn centering on for the square.

```
translate([5, 0, 0]){
square([2, 7], center=true);
}
```

Press F6 to Render the Square

Now add a circle ( which will cut the ball pattern ). We will use a radius of 1.98. Move that circle by 7.56 units on the X-Axis

```
translate([5, 0, 0]){
square([2, 7], center=true);
}
translate([7.56, 0, 0]){
circle(r=1.98);
}
```

Press F6 to Render the Square and the Circle

Place both commands inside a difference() {}

```
difference() {
translate([5, 0, 0]){
square([2, 7], center=true);
}
translate([7.56, 0, 0]){
circle(r=1.98);
}
}
```

We will repeat the same procedures but with values suitable for the outer race.

```
difference() {
translate([10, 0, 0]){
square([2, 7], center=true);
}
translate([7.56, 0, 0]){
circle(r=2);
}
}
```

That is all you need to create the Inner and Outer Race. Now we can use rotate_extrude to add the third dimension.

Place all your code so far inside a rotate_extrude(){}

So both the Inner RAce and the Outer Race will be within the brackets of the rotate_extrude. You code should look something like this. OpenSCAD does not see the extra whitespace, like tabs, the formatting here is just for clarity.

```
rotate_extrude(){
//Inner Race
difference() {
translate([5, 0, 0]){
square([2, 7], center=true);
}
translate([7.56, 0, 0]){
circle(r=2);
}
}
//Outer Race
difference() {
translate([10, 0, 0]){
square([2, 7], center=true);
}
translate([7.56, 0, 0]){
circle(r=2);
}
}
}
```

If you render now you outer in inner race will be 3d !

Now lets add bearing balls

The bearing balls are easier to complete in 3d so we will start with a sphere that has a radius of 1.98 ( Just a tiny bit smaller than the Raceways ). We will move that ball into position by translating it along the x to 7.56 To make the sphere actually resemble a sphere lets set $fn to 25.

```
translate([7.56, 0, 0])
sphere(r=1.96, $fn=25);
```

It may appear as if the sphere is intersecting the raceways. That effect is due to the low number of polygons used to render the raceways. We will fix that last.

The last modeling step is adding the other balls. There are seven in the 608xx bearing. So we will add seven. Add the rotate command and for loop as shown. This will add one sphere at each of 7 positions moved through by the for loop.

```
!for (i = [1 : 1 : 7]) {
rotate([0, 0, (i * 360/7)]){
translate([-7.56, 0, 0])
sphere(r=1.96, $fn=25);
}
}
```

Use the Exclamation Point, in front of the for loop to see only the seven balls. Then press f5 to get a preview.

Finally , lets clean it up a bit. Remove the Exclamation point and place $fn=50; at the beginning of your code. Press F6 to render the final model.

Here is the full code if you would like to try it:

```
$fn=50;
rotate_extrude(){
difference() {
translate([5, 0, 0]){
square([2, 7], center=true);
}
translate([7.56, 0, 0]){
circle(r=2);
}
}
difference() {
translate([10, 0, 0]){
square([2, 7], center=true);
}
translate([7.56, 0, 0]){
circle(r=2);
}
}
}
for (i = [1 : 1 : 7]) {
rotate([0, 0, (i * 360/7)]){
translate([-7.56, 0, 0])
sphere(r=1.96, $fn=25);
}
}
```

]]>Sometimes, if we know the shape is going to be uniform around an axis, it may be easier to create the shape in 2 dimensions. When the shape is complete we can use rotate_extrude to build up the 3d model. This is the approach used in many full feature CAD system. This sample is made as an example of the approach.

We can use the 2d system where it seems appropriate and, after they are extruded into 3d, add the 3d components.

Here is all the code to create this model, you can copy and paste this code directly into you OpenSCAD editor.

```
rotate_extrude($fn=50){
difference() {
translate([10, 0, 0]){
square([10, 9], center=true);
}
translate([15, 0, 0]){
circle(r=5);
}
}
difference() {
translate([20, 0, 0]){
square([10, 9], center=true);
}
translate([15, 0, 0]){
circle(r=5);
}
}
}
for (i = [1 : abs(1) : 10]) {
rotate([0, 0, (i * 36)]){
translate([15, 0, 0]){
{
$fn=50; //set sides to 50
sphere(r=4.5);
}
}
```

]]>This short tutorial will help you create a basic gear in OpenSCAD. The gear will need two cylinders to create the gear and a 3 sided polygon to create the teeth.

The concepts you can learn about in this Tutorial

- cylinder()
- circle()
- linear_extrude()
- difference()
- for loop
- translate()

We will actually start with the 2d items. It will be easier to create a triangular tooth using a 2d circle with 3 sides. The radius of the circle will be half of the “Whole Depth” of the gear. If we draw a line perpendicular to the “Root Diameter” to the “Pitch Diameter”, this will be equal to the radius we use.

circle(3,$fn=3);

Press f6 to see the 2d rendered version

Next we nee to give our gear tooth some meat. We will use linear_extrude() to add 3 Dimensions

linear_extrude(2) circle(3,$fn=3);

Then we will offset the circle using the translate, this will set the single gear to to it’s final diameter. When we rotate in OpenSCAD it is around the main Z-Axis. In order to rotate around our diameter we set tooth the diameter distance from the Z-Axis.

translate([18,0]) linear_extrude(2) circle(3,$fn=3);

Next we will repeat this cylinder around the Z axis.We will use the for loop to add the desired number of gear teeth and rotate() to position the tooth around the axis.

for(i=[1:1:20]){ rotate([0,0,(360/20)*i]) translate([18,0]) linear_extrude(2) circle(3,$fn=3); }

Each time through the for loop, a triangle is added at Z angle. The Z angle is calculated by dividing 360 by the number of teeth, then multiply the resulting angle by the tooth we are on.

Next we can add a cylinder that will define the Root Diameter. This is a cylinder that extends all the way to the edges of the Gear Teeth.

cylinder(h=2,r=17);

Finally we will add a second cylinder that will remove the center with difference()

Press F6 to get the finished render.

difference() { cylinder(h=2,r=17); cylinder(h=2,r=3,$fn=25); }

Here is the final code for our super basic gear.

```
difference() {
cylinder(h=2,r=17);
cylinder(h=2,r=3,$fn=25);
}
for(i=[1:1:20]){
rotate([0,0,(360/20)*i])
translate([18,0]) linear_extrude(2)
circle(3,$fn=3);
}
```

]]>This simple Tutorial will walk you through the process of making a cylindrical pipe.

In this Tutorial you will only need two commands:

- cylinder();
- difference();

Bebgin by creating a new model in OpenSCAD then add your first cylinder. We will make the cylinder with a Radius of 10 and a Height of 100. The cylinder will not be centered.

cylinder( r=10,h=100);

Press F5 to Render the Preview. The Press the Reset View Icon and the Magnify Icon to fully reset and center your view.

Add the second cylinder, which will be subtracted later:

cylinder(r=10,h=100); cylinder(r=9,h=100);

Press F5, it seems like nothing happened, but the cylinder was added.

Place a # in front of the first cylinder and press f5, you will see the second cylinder inside the first.

#cylinder (r=10,h=100); cylinder (r=9,h=100);

Remove the # and add the difference command in front of the two cylinders. Place a Left Curly Bracket after the difference() and after the second cylinder.

difference(){ cylinder (r=10,h=100); cylinder (r=9,h=100); }

The opening will look like it is partially closed off, however in the final render it will be open. Press f6 to get a final render.