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?

3
  • If you name the coordinates (e.g. P\i.\j) you could connect them with decorations or shapes (circuitikz fancy inductor comes to mind). Aug 31 '16 at 19:22
  • Alas, I cannot find asymptote.sty. Aug 31 '16 at 19:28
  • You could try to give it three point perspective, to give it more realism.
    – Manuel
    Aug 31 '16 at 19:33
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

0

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.