standard logo    Personal Education

3D Central


Train Tankcar

Oil. Bubblin' Crude. Black gold. Texas tea. (Wait a minute. This isn't the opening of "Beverly Hillbillies".)

The petrochemical industry regularly transports their liquid assets by rail. Tankcars carry all sorts of petroleum products safely all around the US. In the era of the steam engine, they were probably less common than they are today, but they are a standard railcar, so, naturally, my developing train set has to have one.

The tank is a hollow cylinder made by removing a slightly smaller cylinder from the outer one by using the difference() function. Each end is a squashed sphere similarly made hollow. This makes the tanker lighter than it would be if filled with the normal infill grid of the slicer software for my printer, Cura. Strength is not compromised with a final thickness of around 2mm. I'm not planning to squeeze these train cars too hard. The lack of infill also reduces the amount of plastic extruded, of course.

    //bottom slab to support ladder
        // outer tube
        // inner tube
// near end of container
// far end of container

As before, the tankcar is designed to sit on the flatcar, so the only other design element is a tricky curved ladder for each side of the tank.

Through version02, (F6) compilation time was long, up to half an hour. The culprit turned out to be how I was making four curved sections for the ladders.

The ladder is in two parts. The vertical section is made with cylinders for the sides and cubes for the rungs. Straight cylinders are easy for OpenSCAD. The curved section, through version02, was made using spheres overlapped to make a partial ring curve. The code for the partial curves turned out to be the main reason for the long compilation time. Making four quarter curves was taking close to half an hour to compile. A complete redesign of the ladder reduced compilation time to one minute and 42 seconds. Hoo-hah!

Let's examine the culprit code and the solution.


// curve from overlapped spheres
// very long compile times

This innocent looking loop (done four times) is apparently difficult for the OpenSCAD compiler. The developers have addressed the problem, but not in my stable version of OpenSCAD (2015.03-1) which is the latest stable release in the Ubuntu repositories from which I get my software. There are pre-release versions I could try, but I like stable software.

The newer software versions solve my problem by allowing the rotate_extrude technique to create partial curves, but in 2015.03-1, rotate_extrude can only do 360 degree complete rings.

However, with some trial and error (a good technique, in my opinion) and some reading in the online OpenSCAD notes (an even better technique), I was able to use the intersection() function combined with a ring made using rotate_extrude to meet my needs. Intersection works like the inverse of the difference() function. While difference() removes the second and third shapes from the first, intersection() eliminates everything but the overlapped part. In the vocabulary of OpenSCAD, second and third, etc. parts are considered "children" of the first.

Looking at the next code section, note that a cube overlaps part of the ring made by the rotate_extrude() function. Because the ring is the second and the child element of the cube within the intersection() function, we are left with only the partial curve. The illustration eliminates the intersection() effect to make the overlap of cube and ring obvious. I won't be needing that other sphere curve!

more curves
// curve with rotate_extrude    
    rotate_extrude(convexity = 10)
translate([15, 0, 0])
circle(r = 2);

The full ladder code is reorganized between version02 and version03, too. The 03 ladder is entirely in a module and just gets repositioned to go onto the two sides of the tank. I will leave it to you to download the versions and work through comparing how the code changed. I think putting the curves into the module makes the ladder easier to understand as code, and easier to put the ladders where they need to go.

I did find that pulling out the ladder code to a separate file to isolate it from the tank made fixing the ladder easier. Once the new curve code got into good module form and I could do a successful preview of just one ladder all alone, I saved a copy of the old version02 as version03 and yanked a lot of redundant version02 code out and plopped the new module into the car's version03 code. Develop good versioning habits. Nothing frustrates me more than saving unstable code over actual working code.

I guess there's a final point to be made here. Work away at your problems. Accept the early solutions as long as they actually work. Keep plugging along, grabbing onto new techniques you learn with new projects, but also let the new ideas percolate back into your thoughts about older projects. This tankcar was not created fresh after the boxcar. Version00 with only a tank design happened about the same time as the earliest flatcar version. The tankcar isn't an "old" project, but percolation of new ideas into old projects can happen at any time. You may not be able to force them to come, but keep your thinking flexible so that they can come.

Available Files:

(In most browsers, right click each file you wish to download and select "save-as" from the menu options.)

SCAD files for study/modification and STL files for quick prints

tankcar02.scad - tankcar02.stl - old ladder code and long print time (around 7 hours)
tankcar03.scad - tankcar03.stl - new ladder code compiles faster - still a long print time
GPL3 License