I'm trying to figure out to deal with (and design) .stl files within Mathematica.

As an example, I would like to generate a FCC lattice without the atoms (but connecting all nearest neighbours), and exporting it as an STL file. I've obtained the coordinates from LatticeData, connected the nearest neighbours with NearestNeighbourGraph, and modified the Edge thickness. However, exporting the data as an .stl file only shows the atoms (the vertices), and not the edges.

How can I generate a list of nearest neighbour edges within Mathematica from a lattice structure that can then be successfully exported into the .stl format?

cell = LatticeData["FaceCenteredCubic", "Image"];
coords = Translate[DeleteCases[cell, {_, _, Polygon[_]}, Infinity][[1]], 2 Tuples[Range[1], 3]][[1]][[1]][[1]]
graph = NearestNeighborGraph[coords, VertexSize -> .05,  EdgeShapeFunction -> ({Darker[Black], Thickness[0.04], Line[#1]} &)]
  • 1
    $\begingroup$ Instead of Line[#1] for the EdgeShapeFunction, try Tube[#1, 1/40]. $\endgroup$ – LouisB Nov 14 '20 at 8:28

Extract the edges from the graph and convert them to tubes:

gr = EdgeList[graph] /. UndirectedEdge[x_, y_] :> Tube[{x, y}, 0.1] //

enter image description here

You'll have to add spheres at vertices to make the object manifold, I believe, and good luck with including support structure if you are interested in 3D printing.

  • $\begingroup$ Thanks - I'm interested in using the lattice to hollow out parts with otherwise higher density. They seem to work out well for the ball and bond models, but I haven't tried printing any without atoms yet. Have you tried with just the edges and found them difficult to print without support structures? $\endgroup$ – Zhao Nov 14 '20 at 13:21
  • $\begingroup$ I've been working on ways to print molecules: Export["<file.stl>", MoleculePlot3D@Molecule["Methane"]] and simple models work fine if the bonds and atoms are similar in size. As I move up to bigger molecules (and therefore want smaller atoms and bonds) the support structure is becoming an issue. $\endgroup$ – bobthechemist Nov 14 '20 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.