我为 TikZ 中的一张图片编写了以下代码。这是一篇声学文章的插图。它应该给人一种边界曲线在振动的印象。我将非常感激有关如何实现这一点的建议。谢谢。
\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}
答案1
这里有一个想法。在原始形状上方绘制略微旋转且透明的相同形状:
\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}
根据 Dan H. 在评论中给出的想法,可以通过添加更多层来增加“更多振动”。我认为在这种情况下,附加层应该比主层更薄。例如:
% 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}
结果:
答案2
为了记录,我还发布了我的最终版本。我没有像 JLDiaz 建议的那样旋转附加层,而是决定缩放它们。结果如下。
代码:
\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}