Monday, July 30, 2012

Day 4 - Toy Wrench

Continuing on the trend of "what is laying around", I modeled a toy wrench.
This is definitely a step up in complexity from the first few objects. The hardest part for me was the toolhead. My first thought was that I could create the outside shape as a cylinder with a hexagon taken out, then scale that and subtract it to end up with the raised rim. However, I couldn't get that to work. Then I decided to take a different tack and use a minkowski sum to trace a cylinder around the cylinder/hexagon part to build up the wall. Much better.

The problem I had with the minkowski sum is that I forgot it adds the one object all over the other, so my tool head was twice as tall. I probably could have doen this in 2d and extruded, but instead I just wanted to move ahead and compensated. (This is one of those cases that a ruler on the screen would have helped, as I would have realized sooner that this is what was going on.) As an aside - don't try to scale by '0' - it doesn't like that and crashes.

I rounded one of the edges by rotating a circle to get a torus. I also created the little grip bars by joining a cylinder and a sphere (and then I rotated that in a for loop to place it around the handle). I didn't bother hollowing out the handle.

It seems to me that if you up the value of $fn just a little, the CGAL render time goes up a *lot*. Bumping it to 50 (just for the handle) made the time go from nothing to almost five minutes.

Here is the end result:
And the code
  
include <MCAD/shapes.scad>

TOOL_HEIGHT = 14;
FLAT_PART_THICKNESS = 1;

module wrench_head_part() {
  difference() {
    cylinder(h = TOOL_HEIGHT, r = 22.5);
    translate([7.5, 0, TOOL_HEIGHT/2]) hexagon(25, TOOL_HEIGHT);
    translate([14, -12.5, 0]) cube([25, 25, TOOL_HEIGHT]);
  }
}

module outer_hull() {
  scale([1, 1, 0.5])
  minkowski() {
    wrench_head_part();
    cylinder(h = TOOL_HEIGHT , r = 1);
  }  
}
  
module full_wrench_head() {
  difference() {
    outer_hull();
    translate([0, 0, (TOOL_HEIGHT/2) + FLAT_PART_THICKNESS]) wrench_head_part();    
    translate([0, 0, -(TOOL_HEIGHT/2) - FLAT_PART_THICKNESS]) wrench_head_part();    
  }
}

module stem() {
  difference() {
    rotate([0, 90, 0]) cylinder(h = 37, r=8);
    translate([-.5, -7,  FLAT_PART_THICKNESS]) cube([38, 14, 10]);
    translate([-.5, -7, -10 - FLAT_PART_THICKNESS]) cube([38, 14, 10]);    
  }
}

module grip_bar() {
  $fn = 50;
  rotate([0, 90, 0]) linear_extrude(height = 59) circle(1);
  translate([59, 0, 0]) sphere(1);
}

module handle() {
  $fn = 50;
  translate([-75, 0, 0]) rotate([0, 90, 0]) cylinder(h = 60, r=14);
  translate([-15, 0, 0]) rotate([0, 90, 0]) cylinder(h = 15, r=13);
  rotate([0, 90, 0]) cylinder(h = 5, r1 = 13, r2 = 8);
  translate([-75, 0, 0]) rotate([0, 90, 0]) cylinder(h = 3, r=15);
  for (i=[0:7]) {
    rotate(i*45, v=[1, 0, 0]) translate([-75, 14, 0]) grip_bar();
  }
  translate([-15, 0, 0]) rotate([0, 90, 0]) rotate_extrude(convexity = 10) translate([13, 0, 0]) circle(r = 1);
}

module wrench() {
  union() {
    translate([0, 0, -TOOL_HEIGHT/2]) rotate([0, 0, -14]) full_wrench_head();
    difference() {
      translate([-37 - 20, 0, 0]) stem();  
      translate([0, 0, -TOOL_HEIGHT/2]) rotate([0, 0, -14]) outer_hull();    
    }
    translate([-42 - 20, 0, 0]) handle();
  }
}

wrench();

No comments:

Post a Comment