Freecad design of a tunnel with variations

I’ve been asked by a customer to design and 3D print a railway tunnel for his model train layout project. The tunnel has a portal frame at both ends, with a groove for the overhead contact line and it’s internal wall is covered with tiles. At the entrance there’s an extra frame, decorated with stone tiles, to fit the facade of the tunnel in his landscape (in the picture the facade with the extra frame to be included in the -still missing- tunnel design).


The tunnel should be designed with different variations: with and without the tiled frame, flat or with either an ascending or a descending slope, of a selectable degree.

In the pictures below a scheme of the internal tiling and of what must be rotated for the ascending/descending versions: the front portal on the left side must remain orthogonal to the horizontal, as well as the front frame. The body of the tunnel is rotated around an axis transversal to the tunnel direction and orthogonal to this 2D view, intersecting the front portal on the lower border (bottom left corner of the picture).

Quite easy to imagine and draw in 2D,  with a lot of tricks for the 3D design.

I started my FreeCAD session and tried some of the many possible constructive solid geometry (CSG) approaches, with the goal of creating a unique design where ideally assigning the value to the parameter “degree of the slope” would generate the different variations of the tunnel. The main difficulty is that the tunnel exterior is a “broken and rotated shape”, while the interior  with the tiling remains continuous and straight although rotated, the front frame is externally vertical, but with a slant cut at the bottom to follow the rotation of the body of the tunnel, and so on. I found a good compromise among having a minimal complexity of the FreeCAD objects, low redundancy and maximal automation looking at the design requirements from the counterintuitive point of view: instead of keeping the front part fixed to the vertical plane and rotating the rest, being it only a matter of relative rotation of the front and the body part one respectively to the other, I designed the body of the tunnel and the internal shape with the tiling to remain fixed along the horizontal axis while the front frame and portal are rotated. Once the complete final tunnel shape is composed, it’s enough to rotate it back to have the front face vertical, for better view or to be positioned it in the virtual railroad layout.

The geometrical concept: orientation and basic blocks

The tiling has both circular and longitudinal patterns: the rectangular and polar “Array” features of the “Draft” workbench will serve to the purpose. As the polar array is implicitly defined around the Z axis,  the section of the tunnel must be parallel to the XY axis, with the length extending along the Z axis. The tunnel is placed e\with the body extending from the XY plane towards the Z direction, while the extension is along the negative Z axis.

The tiles and the tunnel are handled separately, in parallel in the same projects, and will be put together at the final stage.

The concept for the tiles is a longitudinal extrusion of the shape appearing on the front arch, repeatedly cut along the Z axis, instantiated along the section of the tunnel.

The tunnel body is a combination of FreeCAD operations on the basic sketch object where the clearance is drawn.

The details

The tunnel body

tunnel_skThe tunnel clearance is as shown in the picture, where I prolonged the side curves lower than the ground horizontal line (in red) to avoid overlapping edges or surfaces with the other objects which could generate problems for the 3D boolean operations. It will be cut at floor level at the end of the design. tun_int

It is drawn on the XY plane and extruded forward along the Z direction  to cover the tunnel length and backwards to cover the front frame extension length.  The tunnel wall is derived from this solid with the “Thickness” feature of the “Part” workbench.

The same principle is used for the frame: it is a thickness of a pad of the clearance sketch: the pad length is the length of the frame along the Z direction (quite short framecompared with the tunnel length), the thickness of generated from the pad is the frame ring radial length (starting from the internal wall of the tunnel). The same frame will be also needed at the opposite (the end) side of the tunnel, using the “Clone” feature of the “Draft” workbench. The choice of a pad, instead of an extrusion, guarantees that the extension ogroovef the frame is orthogonal to the entrance plane of the tunnel and that the clone “placement” (the position and orientation) is independent from the original object placement. Again, similarly, for the extension at the entrance of the tunnel.  The groove on top of the frame, along the tunnel direction is created with the “Pocket” feature of the “Part” workbench and a square sketch, attached to the frame front.

frextThe front frame, together with the extension, will be tilted with respect to the rest of the tunnel, to create the variations with ascending or descending slope.

frext_fullAs the inside of the tunnel must be straight, the tilted fusion of these two objects will need to be either cut out of the exceeding  part or added with the missing part of the tunnel wall. Then it is necessary to have the full frame and extension object to tilt first and then be perforated by the tunnel full inside clearance solid. In order to avoid crashes of FreeCAD or 2D faces remaining after the cutout, a new “refined shape” of the fusion is needed, with continuous front and back surfaces (without the edges of the clearance). In the picture below it is visible the frame+extension refined shape together with the tunnel full inside, before the boolean “cut” operation (on the left); at the center the result of the cut is together with the tunnel wall: it is clearly visible how the internal surfaces of both elements are adhering one to the other.

A clone of the frame on the back of the tunnel completes the tunnel body rough shape (on the right, above),  before the floor trimming. The choice of a “Clone” ensures that any change in the original frame (e.g. the thickness) will be replicated, while the placement (orientation, translation, rotation in the 3D space) will not be affected by any replacement of the original.

Trimming and cutting the tunnel shape

The tunnel shape, as well as the tiling, need to be cut on the floor and trimmed on the front in both variations with and without extension, while not to forget the hole cut vertically on the front and back frame for the overhead line. For this purpose a fusion of cuboid shapes is generated. It is based on the principle of subtraction: cutter shape for the tunnel with the extension is derived from the cutter shape for the tunnel without extension, cutting away the “slice” corresponding to the extension. While the floor cutter remains parallel to the XZ plane, with the vertical cutter on the end of the tunnel orthogonal to it, the cutters at the front side of the tunnel are created as pads from a sketch attached to the facade which is rotated for the different slopes, thus roptating the cutter automatically.

The internal tiling

The tiling is developed in parallel to the body tunnel, taking into account the need to extrude the arch of stones decorating the facade of the portal, at the same time orthogonally to the portal and aligned with the lines of internal bricks, with any slope of the tunnel. bricks_longIt must be laid on the internal wall of the vault, protruding towards the inside of the tunnel for a certain thickness. bricks_elementThe basic objects are longitudinal pads along the tunnel length, with the section that will be extruded from the facade, regularly cut into bricks_wholetile units by an array of a “cube” object as cutting tool, disposed along the three arches of circumferences of which the tunnel section is composed. This will be realised with polar arrays, which in FreeCAD are by definition created around the Z axis. The pad sketches are on the XY plane, symmetrical w r t the Y axis, at a height which is slightly less than the corresponding radii of the two bricks_vaultcircumferences. They are cloned and shifted of half position along the circumference and of the pace of the tiling along the Z axis, of half the pace of the tiles pattern, to realise the staggered pattern in the picture on top of the page.

This tilingpattern is intersected with a thickness object generated from the full length tunnel solid, as the frames, this one internally to the tunnel (a negative values is used when generating the “thickness” object), to generate the tiling adherent with the tunnel inside wall, no matter the slope.

The facade

The facade stones arch is a special feature: the stones are aligned with the bricks, but they extend orthogonally to the facade, which means the are not extbricks_extended along the direction of the brick elements when the tunnel slope is different form 0 deg.

bricks_fac_detThis is a little bit tricky to do: the same array as above for the bricks is recreated, but with the longitudinal pads still uncut. Once disposed along polar arrays structures, duplicated, rotated and repositioned when needed, as above for the tiles, they are intersected with the facade surface (which will be tilted w r t the tunnel length!) and the intersection will at the end be extruded orthogonally to the facade (which means along the Z axis once the final complete tunnel shape will be tilted back to have the facade parallel to the XY plane).