# OpenSCAD Basics: 3D Forms

I’ve put together two tutorials to help you learn more about how to create 3D models with OpenSCAD. ^{1} I admit I haven’t actually shown you how to make *anything* “three-dee” with yet – but that changes today! Today I’m going to show you how to make a sphere, a cylinder, and a cube. If you’re still learning the OpenSCAD ropes, you might want to brush up on your 2D forms because the way we make 3D forms is actually quite similar. (I’ve included links to the prior two tutorials at the end of this post).

**Sphere.**- Here’s how you create a sphere with a radius of 5mm.
- “sphere(5);”

- Want a sphere with a radius of 6mm? No problem!
^{2}- “sphere(6);”

- As with the command to draw a circle, it’s a good habit to define the sphere by including a reference to the radius itself. Here’s how you do that:
- “sphere(r = 5);”

- This will draw a sphere identical to the first example. Defining the sphere in this way helps us quickly understand at a glance what’s being described. Either way works, but you’ll find that actually mentioning the “r = 5” will be very helpful down the road.

- Here’s how you create a sphere with a radius of 5mm.
**Cylinder.**- A cylinder is almost as easy as the sphere. For the cylinder you’re going to need to specify the radii and the height of the cylinder. Let’s give this a whirl:
- “cylinder(20,5,5);”

- That use of the cylinder command basically tells OpenSCAD to create a cylinder that’s 20mm tall with a 5mm radius circle at either end.
- What do you think would happen if the radius values for the cylinder didn’t match? Try both of these and find out:
- “cylinder(20,5,10);”
- That should create a cylinder with a 5mm radius bottom and a 10mm radius top.

- “cylinder(20,10,5);”
- That should create a cylinder with a 10mm radius bottom and a 5mm radius top.

- “cylinder(20,5,10);”
- What if we made one of those radii a zero? Try:
- “cylinder(20,5,0);”
- This should create a cone with the base at the “origin” point and the tip of the cone pointing upwards.

- “cylinder(20,0,5);”
- This should create a cone with the tip at the “origin” point and the base of the cone pointing upwards.

- “cylinder(20,5,0);”
- If you’re like me, you’re not much for wanting to memorize arbitrary commands. Remembering that the first number in the cylinder command means the height, the second number means the radius of the bottom circle, and the third number is the radius of the top circle isn’t exactly intuitive. So, just as with the sphere above we can include a little description of what we’re doing inside the actual command:
- “cylinder(h = 20, r1 = 10, r2 = 5);”

- If you use the cylinder command in this way, you’ll always know at a glance that the first value is the height, the second value is the first radius, and the third value is the second radius.

- A cylinder is almost as easy as the sphere. For the cylinder you’re going to need to specify the radii and the height of the cylinder. Let’s give this a whirl:
**Cube.**- Here’s how you create a cube with each side of 5mm.
- “cube(5);”

- Want a cube with each side at 6mm? You guessed it!
- “cube(6);”

- You can also turn the cube into a rectangular box by replacing the number with a bracketed
*trio*of numbers. One number will be the length, the second the depth, and the third number will be the height. Another way to think about it is that the first number is the X axis, the second number is the Y axis, and the third number is the Z axis. I’ve got a really easy way to help me remember – those three numbers are in- “cube([4,8,16]);”

- If you need a rectangular box with different dimensions, all you need to do is change those three numbers. Easy!

- Here’s how you create a cube with each side of 5mm.

With just these few basic 3D forms at your disposal, you should be able to assemble almost anything. Your homework is to practice those forms above – we’ll learn how to assemble parts soon.

**Bonus Section 1: The Prior Tutorials**

**Bonus Section 2: You… You tricked me!**

I believe in under promising and over delivering. ^{3} Although I promised you that you’d learn how to make a sphere, cylinder and cube, I kinda tricked you. ^{4} By teaching you the basics of the sphere, cylinder, and cube I also taught you how to make a tapered cylinder, cone, and rectangular box. That’s quite a lot of shapes.

**Bonus Section3: Hey, what about polygons???**

A keen observer will note that these shapes are very similar to the 2D shapes from the prior tutorial. The sphere and cylinder commands seem to be extensions of the circle command and the cube command appears to be an extension of the square command. So, why isn’t there a 3D polygon command that corresponds to the 2D polygon command? Well, there is. And, I’m here to tell you it’s a huge monster pain. If people are interested in learning more about OpenSCAD, I’ll write a tutorial that covers the “polyhedron” command. ^{5} For now, I’ll leave you with this warning and teaser – if you thought the polygon command was difficult, I think the polyhedron command is *more* than exponentially more difficult than the polygon command.

**Humble Request**

I’d really like to know what you guys think. Do you find these tutorials helpful? Are they too basic? Do you think I’m trying to cover too much or too quickly? If you like these OpenSCAD tutorials, please leave a comment, take my poll, or otherwise express your opinion. Heck, if you don’t like these tutorials – please let me know why! Lastly, is there some other program or skill you’d like to learn? If there’s enough interest, I’ll create a tutorial!