我想在名为“障碍”的矩形周围画一条“盘蛇”。矩形由节点“O”组成。我无法弄清楚,因为我是 tikz 新手。有人能给我一些好的建议吗?提前谢谢
以下是代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{snakes}
\begin{document}
\begin{tikzpicture}
\tikzstyle{block} = [draw,rounded corners,thin,fill= gray!20, rectangle, thick,align=center]
% Draw axes
% \node (0,0)(a) {$\theta$}
\draw [<->,thick] (0,2) node (yaxis) [above] {$y$}
|- (2,0) node (xaxis) [right] {$x$};
%\draw [gray](0,0)+(0.5,0)arc(0:45:0.5);
%\path (0,0)++ (22.5:0.7)node{$\theta$};
% Draw two intersecting lines
\draw (1.2,1.2)coordinate(a_2);
%Draw vehicle
\draw [rotate =20](a_2)+(0.5,0)coordinate(V_c)node[block,minimum width=28,minimum height=18, rotate=20](a){};
\draw[snake=coil,](a)++(45:3)node[block,rotate=45,segment aspect=10,,minimum height=50,font =\large](O){Obstacle};
%Draw body axis
\draw [->,rotate =20,thick] (V_c) -- ++(0,0.7)node[rotate=20](yaxis)[above]{$y_{b}$};
% \draw [->,rotate =45,thick] (V_c)++(-0.22,0.5) -- ++(0,0.7)node[rotate=45](yaxis)[above]{$v_{y}$};
\draw [->,rotate =20,thick] (V_c) -- ++(0.8,0)node[rotate=20](yaxis)[below]{$x_{b}$};
%draw Dimension of distance to obstacle
\draw[dashed,rotate=45] (a.22) -- (O);
\draw[snake=brace,raise snake=2pt,gap around snake =2pt,rotate=45] (a.22) -- (O);%for curly bracket
\path (V_c)+(0.5,0)--coordinate(L)(O);
\draw [rotate =45] (L)+(0.1,0.5) node[rotate=45]{$L_i$};
\draw[->](a.10)--+(45:0.5)node[rotate=45,below]{$v$};
\end{tikzpicture}
\end{document}
答案1
一般来说,为了达到这些目的,必须使用所谓的晚期选择(请参阅 pgfmanual 上的 16.14 后期代码和后期选项)。这是利用以下概念的证明append after command
:
\documentclass[border=10pt,tikz,png]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{block/.style={draw,rounded corners,thin,fill= gray!20,rectangle,thick,align=center}}
\tikzset{decorate this node/.style={
append after command={
\pgfextra{
\draw[decoration type,decorate,#1](\tikzlastnode.south west)rectangle(\tikzlastnode.north east);
}
}
},
decoration type/.style={
decoration={coil,raise=4pt,amplitude=1pt,segment length=6pt}
}
}
\begin{document}
\begin{tikzpicture}
\node[block,rotate=45,segment aspect=10,minimum height=50,font =\large,decorate this node={rotate=45}] (O) at(0,0) {Obstacle};
\end{tikzpicture}
\end{document}
结果:
一些评论
该snakes
库已被 取代decorations
。此外,我根据以下要求将弃用的库tikzstyle
替换为tikzset
应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?。
最后,对于风格decorate this node
,请小心保持与应用于节点的转换的一致性:请参阅rotate=45
传递给风格的选项。