Friday, July 27, 2012

First object - train tracks

As a start, I tried modeling a piece of toy train track.

The approach I took was to make 2d objects and then extrude them. It is made up of a rectangle for the main part. I then add a circle and a rectangle for the connector stem. I use the same connector to remove the hole at the other end. I extrude all of this to get the basic shape. I then extrude another set of rectangles and subtract them to make the grooves.

I tried to parameterize everything. The train track module takes a parameter to adjust the length of the track, and then all the other measurements of the object are variables at the top of the file.
Here is the result

and here is the code that produced it
  
//Units in mm
TRACK_WIDTH = 40;
TRACK_HEIGHT = 12;
GROOVE_WIDTH = 6;
GROVE_DISTANCE_IN = 4;
GROOVE_DEPTH = 3;

CONNECTOR_RADIUS = 6;
CONNECTOR_STEM_LENGTH = 4;
CONNECTOR_STEM_WIDTH = 3;

$fn=100;

module train_track(length = 250) {
 difference() {
  linear_extrude(height = TRACK_HEIGHT) {
 difference() {
  union(){
   translate([CONNECTOR_RADIUS + CONNECTOR_STEM_LENGTH, -TRACK_WIDTH/2, 0]) square([length, TRACK_WIDTH]);
   connector();
  }
  translate([length, 0, 0]) connector();
 }
  }
  translate([CONNECTOR_RADIUS + CONNECTOR_STEM_LENGTH + length/2, 0, TRACK_HEIGHT - GROOVE_DEPTH])
  linear_extrude(height = GROOVE_DEPTH) {
   translate([0, (-TRACK_WIDTH/2) + GROVE_DISTANCE_IN + (GROOVE_WIDTH/2), 0]) square([length, GROOVE_WIDTH], true);
   translate([0, (TRACK_WIDTH/2) - GROVE_DISTANCE_IN - (GROOVE_WIDTH/2), 0]) square([length, GROOVE_WIDTH], true);
  }
 }
}

module connector() {
 union(){
 translate([CONNECTOR_RADIUS, 0, 0]) square([CONNECTOR_STEM_LENGTH + CONNECTOR_RADIUS, CONNECTOR_STEM_WIDTH], true);
    circle(CONNECTOR_RADIUS);
 }
}
train_track(); 

You can also find it on Thingverse here.

Any comments as to style or how I could do it better would be much appreciated.
Also, I uploaded it to Shapeways to see how much it would cost to make - $93 for plastic? Pretty sure I did it right, but that seems like an amazing amount.

No comments:

Post a Comment