\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw [thick] plot[smooth, tension=.7] coordinates {(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5) (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1) (-4,2.5)};
\draw (-1,0)[thick,scale=0.8] plot[smooth, tension=.7] coordinates {(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5) (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1) (-4,2.5)};
\end{tikzpicture}
\end{document}
答案1
与 David 的原理相同回答. 可以使用选项将线条绘制为双线double
。线条之间的空白由选项配置double distance
。
该图是封闭的,但它被绘制为以同一点结束和开始的开放图。这会导致在此点出现不必要的伪影。删除重复的点和选项smooth cycle
可以解决此问题。
例子:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw [
double=white,
double distance=20pt,
thick,
] plot[smooth cycle, tension=.7] coordinates {
(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5)
(0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1)
};
\end{tikzpicture}
\end{document}
这种方法的缺点是线条之间的空间明确地用白色绘制,如上图所示。
答案2
一种方法是不绘制两条路径,而是绘制两条不同厚度的路径
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw [line width=10pt] plot[smooth, tension=.7] coordinates {(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5) (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1) (-4,2.5)};
\draw [line width=5pt, white] plot[smooth, tension=.7] coordinates {(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5) (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1) (-4,2.5)};
\end{tikzpicture}
\end{document}
答案3
只要你的曲线足够平滑,没有尖角,你就可以利用 Metapost 的direction
功能来实现这一点。在这里我使用了元帖子包装成luamplib
因此使用 进行编译lualatex
。与使用粗笔绘图并擦除中间相比,其优势在于,您可以像我所展示的那样使用不同的笔或图案。
变量名scc
是为了提醒我它是一条平滑的闭合曲线……
\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
path scc, inner, outer;
scc = ( (-4.0, 2.5) ..
(-3.0, 3.0) ..
(-2.0, 2.8) ..
(-0.8, 2.5) ..
(-0.5, 1.5) ..
( 0.5, 0.0) ..
( 0.0,-2.0) ..
(-1.5,-2.5) ..
(-4.0,-2.0) ..
(-3.5,-0.5) ..
(-5.0, 1.0) ..
cycle ) scaled 1cm;
drawarrow scc;
s = 1/16;
inner = for t=s step s until length(scc):
unitvector direction t of scc scaled 6 rotated -90 shifted point t of scc ..
endfor cycle;
outer = for t=s step s until length(scc):
unitvector direction t of scc scaled 6 rotated +90 shifted point t of scc ..
endfor cycle;
draw inner dashed evenly withcolor 2/3 blue;
draw outer dashed withdots withcolor 1/2 red;
endfig;
\end{mplibcode}
\end{document}
请注意,如果原始路径逆时针运行,则需要反转旋转的符号才能正确获得内路径和外路径。