OpenSCAD Basics: Manipulating Forms

Complex forms from simple forms

Complex OpenSCAD forms from simple OpenSCAD forms

With the first three OpenSCAD tutorials I showed you how the basics of the OpenSCAD interface works, how to make a 2D form, and how to make some basic 3D forms1  As you know from playing with Legos, you can build almost anything if you have a few different shaped blocks of various sizes.  Armed with the knowledge of how to make a sphere, cylinder, cube, tapered cylinder, cone, and rectangular box of any size in OpenSCAD now gives you the ability to design almost anything!  Not bad for just three tutorials, eh?  Unfortunately, although we know how to make those forms, they are all attached to the XYZ origin at [0,0,0] which doesn’t do us much good.

Not to worry!  That changes today!  I’ll show you how to take any of those forms, and move them around in 3D space at will!

Manipulating forms is not that difficult as soon as you remember the lesson of the “cube” command.  As you recall, the cube was formed by specifying the dimensions as X, then Y, then Z to say how long, how deep, and how tall an object is supposed to be.  When you can spin a model around in your computer, the concepts of long, deep, and tall being a little disorienting.  So, it’s best to learn to think of these objects in terms of the actual dimensions themselves.  This last rectangular box was written as “cube([4,8,16]);” to achieve a cube with an X dimension of 4, Y dimension of 8, and Z dimension of 16.

  • Translate.
    • When you “translate” an object, you’re really just moving it, that’s all.  And, you can move it in any combination of the three dimensions at the same time.  For the sake of simplicity, let’s take a basic sphere with a radius of 5.
      1. “sphere(5);”
    • Now, let’s move it around in the X dimension.
      1. “translate([10,0,0]) sphere(5);”
    • Now, just the Y dimension.
      1. “translate([0,20,0]) sphere(5);”
    • Now, just the Z dimension.
      1. “translate([0,0,30]) sphere(5);”
    • Now, all three at once.
      1. “translate([10,20,30]) sphere(5);”
    • As you can see, it’s really just a matter of using the “translate()” command, inserting a set of distances to move an object in each of the three dimensions, and then saying what object you’d like to move.  This same system works equally well with any of the other 3D forms we described.  Very quickly, here’s how you can move any of them in the same fashion. 2
    • Here we go with a cylinder, cube, tapered cylinder, cone, and rectangular box:
      1. “translate([10,20,30]) cylinder(20,5,5);”
      2. “translate([10,20,30]) cube(5);”
      3. “translate([10,20,30]) cylinder(20,5,10);”
      4. “translate([10,20,30]) cylinder(20,5,0);”
      5. “translate([10,20,30]) cube([4,8,16]);”
  • Rotate.
    • Rotating an object is easy once you get the “translate” command.  Just as with “translate” above, all you have to do is specify how much you want (in degrees) to rotate an object around the X, Y, and Z axis.  Let’s rotate a rectangular box in each of the three directions.  First, just the box.”cube([4,8,16]);”
    • Now, let’s rotate it 90 degrees around the X axis.
      1. “rotate([90,0,0]) cube([4,8,16]);”
    • As promised, the way we use the command “rotate” is really similar to the “translate” command.  Now let’s rotate that same box around the Y axis by 90 degrees.
      1. “rotate([0,90,0]) cube([4,8,16]);”
    • Now, the same box around the Z axis by 90 degrees.
      1. “rotate([0,0,90]) cube([4,8,16]);”
    • Now, the same box rotated around the X, Y, and Z axes by 90 degrees each.
      1. “rotate([90,90,90]) cube([4,8,16]);”
    • Now, the same box rotated around the X axis by 45, Y axis by 90, and Z axis by 135 degrees.
      1. “rotate([45,90,135]) cube([4,8,16]);”
    • Pro Tip:  I tend to get disoriented very quickly when rotating an object in 3D space in OpenSCAD.  Since it’s easy to render the changes by hitting “F5,” if I need to make a change to the way something is being rotated in 3D space I just make a change to one of the axes in “rotate,” render, then try another axis if I got it wrong.
    • For the same of completeness, let’s spin each of our basic forms in the same manner.  Here’s a rotated sphere, cylinder, cube, tapered cylinder, cone, and rectangular box in that order:
      1. “rotate([45,90,135]) sphere(5);”
      2. “rotate([45,90,135]) cylinder(20,5,5);”
      3. “rotate([45,90,135]) cube(5);”
      4. “rotate([45,90,135]) cylinder(20,5,10);”
      5. “rotate([45,90,135]) cylinder(20,5,0);”
      6. “rotate([45,90,135]) cube([4,8,16]);”
    • You now have the power to create any basic sphere, cylinder, cube, taper cylinder, cone, or rectangular box of any size you wish, move them to any place in 3D space you wish, and then rotate them in any way you wish.  It has been just four short tutorials to this point – but you now have the ability to make almost anything you want.  Savor the moment!
    • But, while we’re here… why not learn just one more simple command?
  • Scale.
    • Just as “translate” let you specify how to move an object in each of the three dimensions and “rotate” let you rotate an object around any of the three axes, “scale” will let you scale (or, really, stretch) an object in any of the three dimensions.  However, instead of using a distance (as with “translate”) or degrees (as with “rotate”), with scale we specify the percentage to scale a dimension up or down in decimals.  A decimal of “1″ will effect no change in that dimension, a decimal of “2″ will double the size of the object in that dimension, and a decimal of “0.5″ will halve the size of the object in that dimension.
    • My favorite thing to scale is a sphere because they just look cool when stretched or squished.  First, our trusty basic sphere with a radius of 5:
      1. “sphere(5);”
    • Now, to scale it to 200% in the X axis:
      1. “scale([2,1,1]) sphere(5);”
    • Now, scaling it to 50% in the X axis:
      1. “scale([0.5,1,1]) sphere(5);”
    • Now, let’s scale it 200% in the Y axis:
      1. “scale([1,2,1]) sphere(5);”
    • Now, let’s scale it 200% in the Z axis:
      1. “scale([1,1,2]) sphere(5);”
    • Now, let’s scale it 50% in the X axis, 150% in the Y axis, and 200% in the Z axis:
      1. “scale([0.5,1.5,2]) sphere(5);”
    • For the same of completeness, let’s scale each of our basic forms in the same manner.  Here’s a scaled sphere, cylinder, cube, tapered cylinder, cone, and rectangular box in that order:
      1. “scale([0.5,1.5,2]) sphere(5);”
      2. “scale([0.5,1.5,2]) cylinder(20,5,5);”
      3. “scale([0.5,1.5,2]) cube(5);”
      4. “scale([0.5,1.5,2]) cylinder(20,5,10);”
      5. “scale([0.5,1.5,2]) cylinder(20,5,0);”
      6. “scale([0.5,1.5,2]) cube([4,8,16]);”

Homework

As you can see from the image above, you can make some really complex things out of just the simple forms we’ve already learned and the three new ways to manipulate those forms.  Hopefully you’re following along with these tutorials and learning with me because you’ve got something you want to build.  Today’s your day to show us what you can do.  Your homework is to make something, anything at all, using at least one of the OpenSCAD commands you learned today and upload it to Thingiverse.  If you want to make me extra proud, please tag it with “openscadtutorial.”  That way anyone who clicks that link will be able to see all of our hard work!

Bonus Section 1:  The Prior Tutorials

 

Bonus Section 2:  There’s something he’s not telling me

Yes, you’re right, there’s some stuff I’m not covering.  Yet.  There are some finer points to using 2D forms other than just as a stepping stone to 3D forms, positioning cube forms, getting a certain amount of resolution out of spheres and cylinders, but I’ve given you the basic tools you’ll need to assemble anything you want.  You won’t need those finer points right now. 3

Bonus Section 3:  Other sources

If you like reading ahead or want more information about OpenSCAD, I’ve found these three websites to be very helpful.  A word of warning, as much useful information is on these sites, I found the presentation to be confusing.

  1. Official OpenSCAD website
  2. OpenSCAD User’s Manual
  3. OpenSCAD beginner’s tutorial

Humble Request 1

I’d really like to know what you guys think. Are you finding these tutorials helpful?  I’m trying to cover concepts in a way that builds logically on what you’ve already learned, with an emphasis to getting you ready to design things as quickly as possible.  So  please leave a comment telling me what you think, e-mail me, or otherwise express your opinion.  And, if you don’t like these tutorials – please let me know why!  Is there some other program or skill you’d like to learn?  Do you want to know about arduinos, some other design program, a basic primer on soldering?  If there’s enough interest, I’ll learn it myself and create a tutorial!

Humble Request 2

Besides those I’ve already thanked, I want to say a special thank you to Marius Kintel for his continued amazing work on OpenSCAD as the sole current developer.  He’s been especially patient with me and my own basic questions.  Right now he’s finalizing a new version of OpenSCAD with some improvements, but he has put out the call for help from developers.  If you’ve got some coding skills, they’d be gratefully appreciated helping out with the next iteration of OpenSCAD.  And, if you’re a web programmer or designer, the OpenSCAD.org web page is on Github.  And, last but not least, if you want to help Marius please consider flattr’ing OpenSCAD.  Marius told me that whatever comes in on Flattr is going to be used as development bounties for helping to improve the program.

See you next time and don’t forget your homework!!!

  1. The above image is a derivative of the CSG forms from Zottie []
  2. I can see how this might be a little repetitive for you, but sometimes it’s nice to have it spelled out explicitly. []
  3. Plus, I’m still learning those finer points too! []
Tagged with , 6 comments
 

6 Comments so far

  • Matt
    Matt
    January 28, 2011 at 5:54 pm
     

    I for one am loving these tutorials because you started giving them right when I was really leaning into learning the process. I’m really hoping to offer parametric versions of my designs for the most part — so when I’m creating something functional it makes a lot of sense to design in openscad so that I can offer users max flexibility to extend my efforts.
    Because otherwise, who really needs all of these strange things I’m designing? ;-)

     
  • OpenSCAD Intermediates: Combining Forms - MakerBot Industries
    February 2, 2011 at 1:56 pm
     

    [...] OpenSCAD Basics:  Manipulating Forms [...]

     
  • coasterman
    February 2, 2011 at 8:45 pm
     

    I hope this makes you proud, MakerBlock: http://www.thingiverse.com/thing:6029

    You said it would! :)

     
  • Bob McKIssick
    June 27, 2013 at 11:31 am
     

    You stated that the xyz’s got a little mind boggling when rotating around. Maybe putting the axis’ letter at the end of each axis line and making the three axis(?) a different color would help.
    So far I’m very pleased with this tutorial but still a long way off from any real ability to use it. Thanks for your great work. bob

     
  • José Xavier
    July 18, 2013 at 6:22 pm
     

    To help with the rotation you can use the right hand rule, per example: http://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Manoderecha.svg/220px-Manoderecha.svg.png

     
  • Gentleman M/V
    August 21, 2013 at 5:25 pm
     

    Howdy! This article could not be written much better! Going through this article reminds me of my previous roommate!
    He continually kept talking about this. I most certainly will forward this post to him.
    Pretty sure he’s going to have a very good read. Many thanks for sharing!

     
 

Leave your comment

 
 
 

xhtml: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>