9

I wrote the following code for a picture in TikZ. It is an illustration for an article in acoustics. It should give the impression that the boundary curve is vibrating. I would be grateful for suggestions on how to achieve that. Thanks.

\begin{tikzpicture}
  \coordinate (omega-center) at (4.5,1.3);
  \coordinate (omega0) at ($(omega-center)+(0:2.5cm)$);
  \coordinate (omega1) at ($(omega-center)+(40:2cm)$);
  \coordinate (omega2) at ($(omega-center)+(80:2.5cm)$);
  \coordinate (omega3) at ($(omega-center)+(120:2.5cm)$);
  \coordinate (omega4) at ($(omega-center)+(160:2.5cm)$);
  \coordinate (omega5) at ($(omega-center)+(200:2.5cm)$);
  \coordinate (omega6) at ($(omega-center)+(240:2cm)$);
  \coordinate (omega7) at ($(omega-center)+(280:2cm)$);
  \coordinate (omega8) at ($(omega-center)+(320:2cm)$);

  \coordinate (omega0-out) at (90:1cm);
  \coordinate (omega0-in) at (270:1cm);
  \coordinate (omega1-out) at (90:1cm);
  \coordinate (omega1-in) at (270:1cm);
  \coordinate (omega2-out) at (90:1cm);
  \coordinate (omega2-in) at (270:1cm);
  \coordinate (omega3-out) at (250:1cm);
  \coordinate (omega3-in) at (70:1cm);
  \coordinate (omega4-out) at (200:1.5cm);
  \coordinate (omega4-in) at (20:1cm);
  \coordinate (omega5-out) at (20:1cm);
  \coordinate (omega5-in) at (200:1cm);
  \coordinate (omega6-out) at (60:1cm);
  \coordinate (omega6-in) at (240:1cm);
  \coordinate (omega7-out) at (70:1cm);
  \coordinate (omega7-in) at (250:1cm);
  \coordinate (omega8-out) at (90:1cm);
  \coordinate (omega8-in) at (270:1cm);

  \draw[black, very thick, fill=blue!10]
    (omega0) .. controls +(omega0-out) and +(omega1-in) .. (omega1)
             .. controls +(omega1-out) and +(omega2-in) .. (omega2)
             .. controls +(omega2-out) and +(omega3-in) .. (omega3)
             .. controls +(omega3-out) and +(omega4-in) .. (omega4)
             .. controls +(omega4-out) and +(omega5-in) .. (omega5)
             .. controls +(omega5-out) and +(omega6-in) .. (omega6)
             .. controls +(omega6-out) and +(omega7-in) .. (omega7)
             .. controls +(omega7-out) and +(omega8-in) .. (omega8)
             .. controls +(omega8-out) and +(omega0-in) .. (omega0);
\end{tikzpicture}

enter image description here

  • 2
    Try to insert some copies below the blue shape (so the code should come first) to produce some new shapes with different sizes and positions. For example, a lot of \draw[scale=1.1,yshift=6pt,black!50,thick] and change the scale, the shift, and so on. – Sigur Oct 30 '14 at 17:19
18

Here is an idea. Draw the same shape slightly rotated and transparent above the original one:

\usetikzlibrary{calc}
\begin{tikzpicture}
  \coordinate (omega-center) at (4.5,1.3);
  \coordinate (omega0) at ($(omega-center)+(0:2.5cm)$);
  \coordinate (omega1) at ($(omega-center)+(40:2cm)$);
  \coordinate (omega2) at ($(omega-center)+(80:2.5cm)$);
  \coordinate (omega3) at ($(omega-center)+(120:2.5cm)$);
  \coordinate (omega4) at ($(omega-center)+(160:2.5cm)$);
  \coordinate (omega5) at ($(omega-center)+(200:2.5cm)$);
  \coordinate (omega6) at ($(omega-center)+(240:2cm)$);
  \coordinate (omega7) at ($(omega-center)+(280:2cm)$);
  \coordinate (omega8) at ($(omega-center)+(320:2cm)$);

  \coordinate (omega0-out) at (90:1cm);
  \coordinate (omega0-in) at (270:1cm);
  \coordinate (omega1-out) at (90:1cm);
  \coordinate (omega1-in) at (270:1cm);
  \coordinate (omega2-out) at (90:1cm);
  \coordinate (omega2-in) at (270:1cm);
  \coordinate (omega3-out) at (250:1cm);
  \coordinate (omega3-in) at (70:1cm);
  \coordinate (omega4-out) at (200:1.5cm);
  \coordinate (omega4-in) at (20:1cm);
  \coordinate (omega5-out) at (20:1cm);
  \coordinate (omega5-in) at (200:1cm);
  \coordinate (omega6-out) at (60:1cm);
  \coordinate (omega6-in) at (240:1cm);
  \coordinate (omega7-out) at (70:1cm);
  \coordinate (omega7-in) at (250:1cm);
  \coordinate (omega8-out) at (90:1cm);
  \coordinate (omega8-in) at (270:1cm);

  \def\myshape{
    (omega0) .. controls +(omega0-out) and +(omega1-in) .. (omega1)
             .. controls +(omega1-out) and +(omega2-in) .. (omega2)
             .. controls +(omega2-out) and +(omega3-in) .. (omega3)
             .. controls +(omega3-out) and +(omega4-in) .. (omega4)
             .. controls +(omega4-out) and +(omega5-in) .. (omega5)
             .. controls +(omega5-out) and +(omega6-in) .. (omega6)
             .. controls +(omega6-out) and +(omega7-in) .. (omega7)
             .. controls +(omega7-out) and +(omega8-in) .. (omega8)
             .. controls +(omega8-out) and +(omega0-in) .. (omega0)
  }

  \draw[black, very thick, fill=blue!10] \myshape;
  \begin{scope}[transform canvas={rotate around={3:(omega-center)}}]
     \draw[black, very thick, draw opacity=0.3] \myshape;
  \end{scope}
  \begin{scope}[transform canvas={rotate around={-3:(omega-center)}}]
     \draw[black, very thick, draw opacity=0.3]  \myshape;
  \end{scope}
\end{tikzpicture}

Result

Following the idea given by Dan H. in a comment, it is possible to add "more vibration" by adding more layers. I think that in this case the addditional layers should be thinner than the main one. For example:

  % Ommited all the initialization of coordinates, which is the same
  \draw[black, very thick, fill=blue!10] \myshape;
  \begin{scope}[transform canvas={rotate around={2:(omega-center)}}]
     \draw[black, thick, draw opacity=0.3] \myshape;
  \end{scope}
  \begin{scope}[transform canvas={rotate around={-2:(omega-center)}}]
     \draw[black, thick, draw opacity=0.3]  \myshape;
  \end{scope}
  \begin{scope}[transform canvas={rotate around={4:(omega-center)}}]
     \draw[black, thick, draw opacity=0.1] \myshape;
  \end{scope}
  \begin{scope}[transform canvas={rotate around={-4:(omega-center)}}]
     \draw[black, thick, draw opacity=0.1]  \myshape;
  \end{scope}

Result:

Result

  • Nice! I've tried adding some decoration like snakes but the result is not so elegant. – Ignasi Oct 30 '14 at 18:24
  • 2
    Nice idea, to improve the appeareance you can alternate the rotation instead of one time by +3/-3, two times at +2/-2 and +4/-4 and change the opacity to .2 and .1, so the shape is "more vibrating". – Dan H. Oct 31 '14 at 8:19
  • 1
    @DanH. I updated the answer with your suggestion. Thank you! – JLDiaz Oct 31 '14 at 9:09
  • 1
    To maximize the effect: \foreach \r/\o in {-5/05,-4/1,-3/2,-2/3,-1/4,1/4,2/3,3/2,4/1,5/05}{ \begin{scope}[transform canvas={rotate around={\r:(omega-center)}}] \draw[black, thick, draw opacity=0.\o] \myshape; \end{scope}} :) – Dan H. Oct 31 '14 at 9:25
4

For the record I post also my final version. Instead of rotating the additional layers as suggested by JLDiaz I decided to scale them. Here is the result. enter image description here

CODE:

\begin{tikzpicture}[scale=.5]
  \coordinate (origin) at (-4.5,-1.3);
  \coordinate (observer) at (-3,2.7);
  \coordinate (x) at ($(origin) + (1,0,0)$);
  \coordinate (y) at ($(origin) + (0,1,0)$);
  \coordinate (z) at ($(origin) + (0,0,1)$);
  \coordinate (sphere-center) at (-.5,.7);

  \coordinate (bounded-label) at (.5,4.5);
  \coordinate (unbounded-label) at (1.5,5.4);

  \coordinate (omega-center) at (0,0);
  \coordinate (omega0) at ($(omega-center)+(0:2.5cm)$);
  \coordinate (omega1) at ($(omega-center)+(40:2cm)$);
  \coordinate (omega2) at ($(omega-center)+(80:2.5cm)$);
  \coordinate (omega3) at ($(omega-center)+(120:2.5cm)$);
  \coordinate (omega4) at ($(omega-center)+(160:2.5cm)$);
  \coordinate (omega5) at ($(omega-center)+(200:2.5cm)$);
  \coordinate (omega6) at ($(omega-center)+(240:2cm)$);
  \coordinate (omega7) at ($(omega-center)+(280:2cm)$);
  \coordinate (omega8) at ($(omega-center)+(320:2cm)$);

  \coordinate (omega0-out) at (90:1cm);
  \coordinate (omega0-in) at (270:1cm);
  \coordinate (omega1-out) at (90:1cm);
  \coordinate (omega1-in) at (270:1cm);
  \coordinate (omega2-out) at (90:1cm);
  \coordinate (omega2-in) at (270:1cm);
  \coordinate (omega3-out) at (250:1cm);
  \coordinate (omega3-in) at (70:1cm);
  \coordinate (omega4-out) at (200:1.5cm);
  \coordinate (omega4-in) at (20:1cm);
  \coordinate (omega5-out) at (20:1cm);
  \coordinate (omega5-in) at (200:1cm);
  \coordinate (omega6-out) at (60:1cm);
  \coordinate (omega6-in) at (240:1cm);
  \coordinate (omega7-out) at (70:1cm);
  \coordinate (omega7-in) at (250:1cm);
  \coordinate (omega8-out) at (90:1cm);
  \coordinate (omega8-in) at (270:1cm);

  \coordinate (normal) at (290:.8cm);

  \shade[inner color=blue!50!white,outer color=white] (sphere-center) circle [x radius=6.5cm, y radius=5.5cm];
  \draw[blue, dashed] (sphere-center) circle [x radius=6cm, y radius=5cm];

  % Domain Omega
  \def\myshape{
    (omega0) .. controls +(omega0-out) and +(omega1-in) .. (omega1)
             .. controls +(omega1-out) and +(omega2-in) .. (omega2)
             .. controls +(omega2-out) and +(omega3-in) .. (omega3)
             .. controls +(omega3-out) and +(omega4-in) .. (omega4)
             .. controls +(omega4-out) and +(omega5-in) .. (omega5)
             .. controls +(omega5-out) and +(omega6-in) .. (omega6)
             .. controls +(omega6-out) and +(omega7-in) .. (omega7)
             .. controls +(omega7-out) and +(omega8-in) .. (omega8)
             .. controls +(omega8-out) and +(omega0-in) .. (omega0)
  }

  \shade[inner color=black!50!white,outer color=gray!50!white] \myshape;

  \tikzset{
    vibrate/.style = {red,
                      thick}
  }
  \begin{scope}[transform canvas={scale = 1.06}]
    \draw[vibrate, draw opacity=0.1] \myshape;
  \end{scope}
  \begin{scope}[transform canvas={scale = 1.04}]
    \draw[vibrate, draw opacity=0.3] \myshape;
  \end{scope}
  \begin{scope}[transform canvas={scale = 1.02}]
    \draw[vibrate, draw opacity=0.5] \myshape;
  \end{scope}

  \draw[red, thick] \myshape;

  \begin{scope}[transform canvas={scale = 0.98}]
    \draw[vibrate, draw opacity=0.5] \myshape;
  \end{scope}
  \begin{scope}[transform canvas={scale = 0.96}]
    \draw[vibrate, draw opacity=0.3] \myshape;
  \end{scope}
  \begin{scope}[transform canvas={scale = 0.94}]
    \draw[vibrate, draw opacity=0.1] \myshape;
  \end{scope}

  % Normal vector
  \draw[-latex,label=$\mathbf{n}$] (omega4) -- node[pos=0.4, right] {\scriptsize $\ve{n}$} +(normal);

  % Coordinate system
  \fill (origin) circle (1pt);

  \node[right] at (x) {\scriptsize $x$};
  \node[above] at (y) {\scriptsize $y$};
  \node[below] at (z) {\scriptsize $z$};

  \draw[-latex] (origin) -- (x);
  \draw[-latex] (origin) -- (y);
  \draw[-latex] (origin) -- (z);

  % Observer
  \node[above right] at (observer) {\scriptsize $\vr$};
  \fill (observer) circle (1pt);
  \draw[-latex] (origin) -- (observer);

  % Domain labels
  \node at (omega-center) {$\Omega_+$};
  \node[above right] at (omega1) {$\Gamma_v$};

  \node[above] at (unbounded-label) {$\Omega_U$};
  \node[above] at (bounded-label) {$\Omega_B$};
\end{tikzpicture}
  • In my opinion, it looks worse than his solution :( – Manuel Jan 26 '15 at 23:00

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.