经过多次尝试,我取得了不错的成绩
\documentclass[border=8mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\tikz \draw[dashed] plot [smooth cycle] coordinates {(1,1.5)(3.5,0.9)(4.8,0)(6,1.3)(7.2,2)(7.5,3.5)(6,4)(4,5)(2.6,3.5)(1,3)} node at (2,1.6) {$B_r(x)$};
\fill[lightgray] (-4,3) circle[radius=12mm] node [text=black,yshift=20mm] {$U$};
\fill (-4,3) circle[radius=1mm] node [above,font=\small] {$c$};
\draw (-4,3) -- node [above,font=\small] {$r$} (-2.8,3);
\end{tikzpicture}
\end{document}
问题是我无法创建如下图所示的箭头曲线
\draw[->] (1) to [out=315, in=315, looseness=2.5] (2);
谢谢您的帮助
答案1
使用 是个好主意smooth cycle
,但极坐标可能更容易模仿形状。不要绘制圆形,而是将其设为 ,node
这样您就可以绘制到其边界。bend left
的选项draw
可以制作弯曲的箭头。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[dashed, fill=gray!10] plot [smooth cycle, tension=.8] coordinates {(0:2.8)(30:4)(60:3)(100:3.5)(135:3)(205:3.5)(270:1.4)(315:2.8)} ;
\node[draw, dashed, fill=gray!50, circle, minimum size=20mm, label={[label distance=5mm]105:$U$}](C) at (0,0) {};
\fill (0,0) circle[radius=2pt] node[above] {$c$};
\draw (C.center) -- node[below] {$r$} (C.0);
\node (B) at (205:2.5){$B_r(x)$};
\draw[->] (B) to[bend left=45] (C.180);
\end{tikzpicture}
\end{document}
答案2
改编
- 不要
\tikz
在里面使用tikzpicture
- 给 B_r 节点命名,
(br)
以便稍后用于箭头 - 定义一个
\coordinate (c)
圆 - 绘制箭头:
\draw[->] (br) to [out=90, in=160, looseness=1.5] ($(c)+(160:10mm)$);
- 使用选项
fill=lightgray!30
为形状着色
代码
\documentclass[border=8mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\draw[dashed, fill=lightgray!30] plot [smooth cycle] coordinates {(1,1.5)(3.5,0.9)(4.8,0)(6,1.3)(7.2,2)(7.5,3.5)(6,4)(4,5)(2.6,3.5)(1,3)};
\node (br) at (2,1.6) {$B_r(x)$};
\coordinate (c) at (5,2.3);
\fill[lightgray] (c) circle[radius=10mm] node [text=black, yshift=10mm] {$U$};
\fill (c) circle[radius=1mm] node [above, font=\small] {$c$};
\draw (c) -- node [above, font=\small] {$r$} ++(10mm,0);
\draw[->] (br) to [out=90, in=160, looseness=1.5] ($(c)+(160:10mm)$);
\end{tikzpicture}
\end{document}
结果
答案3
这是一种实现此目的的方法,它可以重用部分代码。
一些评论:
区域 U 比较棘手。我试过了,to[out=..,in=..]
但最终代码并不好。所以我分配了新的坐标和tension=1
。
我将部分(而非全部)格式语句移至(重构)样式部分。这样,您只需在一个位置进行更改,例如颜色。如果您考虑使用填充图案(这在当今可能不是一个好主意),也可以将它们放在此处。
\begin{tikzpicture}[
>={Triangle},% arrow tip; try als {Stealth} etc.
arr/.style={->,line width=1.5pt},% arrows style
UF/.style={dashed,fill=gray!20},% style of U-area
CF/.style={color=black!60, fill=white!65, very thick},
]
箭头做得相当简单,但to[bend left]
也可以起到作用:
\draw[arr] (B) to [out=80,in=140] +(30:2.2);
想像一下之前那里有一条直线;终点是我任意设置的,因为选择的路径使圆不属于节点:
\draw[arr] (B) -- +(30:2.2);
如果它是节点的形状,您可以使用 (M)、(M.west)、(M.120) 等位置,它将在所述位置结束。
\documentclass[10pt,border=3mm,tikz]{standalone}
%\usepackage{tikz}% already loaded, see class
\usetikzlibrary{arrows.meta}% has many nice arrow tips
\begin{document}
\begin{tikzpicture}[
>={Triangle},% arrow tip; try als {Stealth} etc.
arr/.style={->,line width=1.5pt},% arrows style
UF/.style={dashed,fill=gray!20},% style of U-area
CF/.style={color=black!60, fill=white!65, very thick},
]
% ~~~ area U ~~~~~~~~~~~~~~~~~~~
\draw[UF] plot [smooth cycle,tension=1]
coordinates {(0.5,.5)(0,2)(1.5,3)(2.5,5)(5,4)(7,3)(6,.5)(4,.5)}
node at (3,4) {$U$};;
% ~~~ circle ~~~~~~~~~~~
\coordinate (M) at (4,2);% saves typing
\filldraw[CF] (M) circle (1);
\draw[fill=black,line width=1.2pt] (M) circle (1mm)
node [yshift=3mm] {$c$} --
node[yshift=+2mm,xshift=0mm] {$r$} +(1,0);
% ~~~ B ~~~~~~~~~~~~~~
\node (B) at (1,1) {$B_r(x)$};
% ~~~ arrow ~~~~~~~~~
\draw[arr] (B) to [out=80,in=140] +(30:2.2);
\end{tikzpicture}
\end{document}
PS:这是一个将样式更改为这样的示例:
\begin{tikzpicture}[
>={Triangle},% arrow tip; try als {Stealth} etc.
arr/.style={->,line width=1.5pt,blue},% arrows style
UF/.style={dashed,fill=gray!10},% style of U-area
CF/.style={color=black!60, fill=gray!65, very thick},
]