7

I'd like to draw an example of a tridimensional mass-spring system in LaTeX (preferably with TikZ or Asymptote). See the example below:

Mass-spring system example from Gibson & Mirtich 1997

(this one was taken from the article by Gibson and Mirtich (1997) here)

If possible, I want the coils to be realistic, like the example here.

Minimal (partially working) example follows. I only need to connect the dots in each plane with springs to finish it:

\documentclass{standalone}

\usepackage{luatex85}
\usepackage[inline]{asymptote}

\begin{document}
  \begin{asy}
    settings.tex = "lualatex";

    import three;
    settings.prc = false;
    settings.render = 0;

    size(10cm);

    currentprojection = orthographic(-1, 0.5, 0.5, up=Y);
    draw(unitbox, pink);

    for (int i = 0; i <= 3; ++i)
    {
      for (int j = 0; j <= 3; ++j)
      {
        // plane "X" in Unity
        dot((0, i/3, j/3), magenta);
        // plane "Y"
        dot((i/3, 1, j/3), red);
        // planz "Z"
        dot((i/3, j/3, 1), black);

      }
    }
  \end{asy}
\end{document}

Demo of a mass-spring system in Asymptote

How can I finish it?

amyspark
  • 628

1 Answers1

7

Would you be happy with springs like these?

\documentclass[border=10pt,multi,tikz]{standalone}

\usetikzlibrary{
    decorations,
    decorations.pathmorphing,
}

\begin{document}

\begin{tikzpicture}[
    decoration={
        coil,
        amplitude = 1.5mm,
        aspect=1,
        pre length=1mm,
        post length=1mm,
    },
    every node/.style={circle, draw}
]

\foreach \x in {0,4,...,12}{
    \let\lasty\undefined
    \foreach \y in {0,3,...,6}{
        \let\lastz\undefined
        \foreach \z in {0,3,6}{
            \begin{scope}[draw=black!\z0!gray]
                \node[fill=black!\z0] (n\x\y\z) at (\x,\y,\z) {};
                \ifx\lastx\undefined\else
                    \draw[decorate] (n\x\y\z) -- (n\lastx\y\z);
                \fi
                \ifx\lasty\undefined\else
                    \draw[decorate] (n\x\y\z) -- (n\x\lasty\z);
                \fi
                \ifx\lastz\undefined\else
                    \draw[decorate] (n\x\y\z) -- (n\x\y\lastz);
                \fi
            \end{scope}
            \xdef\lastz{\z}
        };
        \xdef\lasty{\y}
    };
    \xdef\lastx{\x}
};

\end{tikzpicture}

\end{document}

enter image description here

Roel
  • 592