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 trioof 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
- OpenSCAD Basics: The Setup
- OpenSCAD Basics: 2D Forms
- OpenSCAD Basics: 3D Forms
- OpenSCAD Basics: Manipulating Forms
- OpenSCAD Intermediates: Combining Forms
- OpenSCAD Intermediates: Mashups
- OpenSCAD Intermediates: Modularity
- OpenSCAD Intermediates: Extruding 2D Objects
- OpenSCAD Intermediates: Fixing Design Problems
- OpenSCAD Intermediates: How to Make Organic Shapes
- OpenSCAD Design Tips
- OpenSCAD Design Tips: How to Make a Customizable Thing
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!
| Tagged with | 3d form, digital design, openscad, tutorial | 22 comments |







22 Comments so far
Dave Durant
> I’d really like to know what you guys think
I, for one, welcome our new tutorial overlords.
I’d like to see openscad grow a bit more but maybe that’s just because I’m a software guy and always assume the language has C-type features, which turns frustrating when I find/remember it doesn’t..
It’s still a very powerful tool, though, and having some good walk-throughs to get people started is definitely a good thing – keep ‘em coming!
(I also think you have a copy/paste typo in the 2nd cone example)
MakerBlock
@Dave Durant: Others have mentioned that it’s easier sometimes to just use another language to write OpenSCAD, rather than rely upon the programming capabilities of this language. http://makerblock.com/2011/01/the-cake-was-a-lie/#comments
And, really, I’m kind of okay with that. I figure once I figure out what I’m doing with OpenSCAD I could design an object I like – but perhaps needs highly dynamic input, then build some LAMP architecture program to churn out interesting variations.
Bryan Monti
Keep the tutorials coming! They’re great and wouldn’t change a thing! I’ve been trying forever to learn OpenSCAD and the tutorials for it aren’t that great >.> If you wouldn’t mind though, it would be nice if you could put some screen shots of some of the “things” you make with certain commands. Thanks for the tutorials! =D
Xaq
Keep on rockin! I’m fairly comfortable in openSCAD but these tutorials are really clear and I’m looking forward to when you get to the geometrical transformations, boolean operations, and language features like conditionals, loops, and modules.
Grant Henninger
I’ve found these tutorials to be great so far. I’m just trying to learn OpenSCAD so they’ve been helpful. I do with there were more of them that were already done, since it doesn’t take long to read through these and master what you’re teaching.
What I’m interested to learn next is now to add shapes together, rotate shapes, and subtract shapes from one another. For example, how do you create a “C” shaped object?
MakerBlock
@Bryan: I’ll see what I can do about adding some screenshots.
@Xaq: Geometrical transformwhatsis?
@Grant: I see. The student has now become the master.
I’m glad you guys appreciate them. In all honesty, I’m learning OpenSCAD about one tutorial faster than I’m writing. (It’s not that I’m a slow learner – it’s that I have a REALLY slow internet connection) But, if you want to leapfrog ahead of the rest of the class…
http://en.wikibooks.org/wiki/OpenSCAD_User_Manual
JohnC
Liking the tutorials so far, one thing that bugs me so far about OpenSCAD though is the use of really bad terms for functions. square(5,4)? if the sides are different it isnt a square for petes sake.(has a lot to answer for that pete!) likewise cylinder(h,r1,r2) if the rs arent the same then its not a cylinder….
MakerBlock
@JohnC: Okay, I see your point. I guess, the square function should really have been called “rectangle()” instead, since all squares are rectangles but not all rectangles are squares. And, then, cylinder() could have been called “roundthingie()” since both cylinders and cones are roundthingies.
JohnC
Wouldnt be too bad if it defaulted to actually creating a cylinder if you only give it one r, but it creates a cone, go figure.
I’d just have gone with cylinder(h,r) and conical(h,r1,r2) where r2 is optional and defaults to 0. likewise cuboid(x,y,z) would be correct, whereas cube(x,y,z) is just gonna bug me every time I type it. May have to create a function called roundthingie() now just for you
MakerBlock
@JohnC: Nah… we’ll make a module!
Tim
Thank you MakerBlock for these tutorials! I know pretty much how to use openscad, but I am learning new things from your tutorials.
-Tim
Nicholas C Lewis
@JohnC
cylinder(r=2,h=8); does give you a cylinder not a cone.
JohnC
@Nicholas
yet cylinder(2,8) generates a cone. Gotta love the consistancy.
JohnC
was playing earlier, any thoughts?
http://simarilius.wordpress.com/2011/01/26/openscad-export-from-inkscape-anyone-interested/
MakerBlock
@JohnC: FYI: Here’s my rough outline. http://makerblock.com/2011/01/openscad-tutorial-outline/ I was going to include the use of other programs down the line – but as Allan Ecker says, the more tutorials the better!
OpenSCAD Intermediates: Modularity - MakerBot Industries
[...] little more interesting than just make a pile of trees. Do you remember back when we talked about cylinders and how it was good form to describe a cylinder like [...]
Jack Samrox
hi makerBlock,
great stuff this tutorial – many thanks.
i’ve just discovered openscad and 3d printers a week ago and i’m hooked.
so keep up the good work and thanks again.
jack
MakerBlock
@Jack Samrox: Thanks man!!! I hope you keep with it! People are doing some truly amazing things with OpenSCAD and 3D printers. I’ve tried to make this series as gentle an introduction as I can manage.
Dan
I am using Blender and every time I run a boolean subtraction with round objects, I fall into “non-manifold Hell”.
Can I get around these “dirty Blender booleans” by switching to OpenSCAD?
MakerBlock
@Dan: YES!!!
Melysa
I am very interested in a polyhedron tutorial!
GiqueGEAR_Todd
I like these tutorials a lot. Thank you!