Welcome to MakerHome

We've completed our yearlong print-a-day project! New projects will be posted at www.mathgrrl.com/hacktastic.

All mathgrrl designs and associated images and files on MakerHome are licensed under the Creative Commons Attribution Non-Commercial Share Alike license. If you want to use designs, images, or files outside of the terms of this license, please email request@mathgrrl.com.

Thursday, May 1, 2014

Day 248: Thursday refactor - Sofa redesign

On Day 230 we printed some tiny sofas to try to figure out what will fit in our Brooklyn apartment this summer. (The answer: not much!)  In the comments, kitwallace suggested a very clean refactoring of our clunky OpenSCAD code, as well as a way to make the sofa dimensions more accurate while still being rounded. Today we reprinted our sofa models with this improved code, and now more things fit in our apartment! The new model is on the left, the old on the right:


Thingiverse link: COMING SOON - eventually we'll post a full customizable set of models...

Settings: MakerBot Replicator 2 with .3mm/low, as usual.

Technical notes, improved OpenSCAD flavor: The top of the code is the same as on Day 230, with scaling factors set so that we can measure our sofas in inches and then create them in OpenSCAD using millimeters so that they print at 1:50 scale. Note the "soft" factor for making soft corners on things like sofas and beds, and the "sharp" factor for making hard things like tables and desks.

/////////////////////////////////////////////////////////////
// parameters ///////////////////////////////////////////////

$fn = 12;     // facets
scale = 50;   // enter desired scaling factor here e.g. 50 means 1:50
m = 25.4;     // measurement unit conversion
      //(m=25.4 does 1:1 scale with inches entered)
      //(m=12*25.4 does 1:1 scale with feet entered)
      //(m=10 does 1:1 scale with cm entered)
      //(m=1000 does 1:1 scale with meters)
s = m/scale;  // scaling factor 
soft = 3*s;   // radius for soft bevels depends on scale
sharp = .2;   // radius for sharper edges

The next section is a neat cuboid module that save us work when constructing the sofa shapes from rectangular solids. The cuboid is made by forming a hull around spheres that are placed at its eight corners, and the coordinates of the centers of those spheres are defined so that the size of the sphere doesn't affect the overall dimensions of the object. In other words, sofas have corners that are rounded in, rather than sides that poof out, as we had in our previous model. It seems like a little thing but at 1:50 scale it can make a difference of a few inches, which is significant when trying to see if your furniture will pack into a small space!

/////////////////////////////////////////////////////////////
// module for cuboids ///////////////////////////////////////
// thanks, kitwallace! //////////////////////////////////////

module cuboid(depth,length,height,r) {
hull(){
translate([r,r,r]) sphere(r);
translate([depth-r,r,r]) sphere(r);
translate([depth-r,length-r,r]) sphere(r);
translate([r,length-r,r]) sphere(r);
translate([r,length-r,height-r]) sphere(r);
translate([depth-r,length-r,height-r]) sphere(r);
translate([depth-r,r,height-r]) sphere(r);
translate([r,r,height-r]) sphere(r);
}
}

Now that we have the cuboid module, it is easy to make a sofa shape out of four of those cuboids. Another improvement from our previous code is that the scale is built into the top level of the module instead of being factored into every dimension or translation.

/////////////////////////////////////////////////////////////
// module for making sofas //////////////////////////////////

module sofa(depth,length,height){
scale(s)
union(){
// back of sofa
cuboid(depth/4,length,height,soft);
// left arm of sofa
cuboid(depth,depth/4,height*.6,soft);
// right arm of sofa
translate([0,length-depth/4,0])
                    cuboid(depth,depth/4,height*.6,soft);
// cushions of sofa
cuboid(depth,length,height*.4,soft);
}
}

Finally, all that is left is to measure your sofa's dimensions and render with the "sofa" module. By the way, this one doesn't fit in our apartment, so let me know if you are in the market for a very nice brown loveseat.

/////////////////////////////////////////////////////////////
// render ///////////////////////////////////////////////////

// brown loveseat
sofa(depth=36,length=54,height=34);

No comments:

Post a Comment