我是 TikZ 包的新手,我需要制作这个图像:
在 TikZ 中。
现在我已经完成了这个,但是在制作上面那种箭头时遇到了麻烦。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,arrows,calc}
\begin{document}
\tikzset{
big dot/.style={
circle, inner sep=0pt,
minimum size=3mm, fill=gray
},
line/.style={
draw,
line width=1.4pt
},
input/.style={
draw,
trapezium,
trapezium left angle=60,
trapezium right angle=120,
line width=1.2pt,
fill={rgb:black,1;white,2}
},
obstacle/.style={
draw,
trapezium,
trapezium left angle=120,
trapezium right angle=60,
line width=1.2pt,
fill={rgb:black,1;white,2}
}
}
\begin{tikzpicture}
\node[input](goal1) at (0,0) {GOAL};
\node[input](goal2) at (4,0) {GOAL};
\node[obstacle](obstacle1) at (0,-1.5) {OBSTACLE};
\node[input](goal3) at (1.5,-3) {GOAL};
\node[input](goal4) at (4,-3) {GOAL};
\draw[line] (goal1.east) -- (goal2.west);
\end{tikzpicture}
\end{document}
答案1
arrows.meta
使用CVS 版本的 TikZ 的新库可以很容易地做到这一点(参见如何安装当前版本的 TikZ?)。
不幸的是,我无法创建填充箭头尖stealth
(可以使用markings
库创建,方法是先添加一个大的黑色尖,然后在黑色尖上画一个较小的箭头)和之前的内容|
。作为参考,我使用了:
arrowS/.style={postaction=decorate,decoration={name=markings, arrow/.list={#1}}},
/pgf/decoration/arrow/.style args={#1:#2-#3}{mark=at position #1 with {\arrow[#2]{#3}}}
可以用作
arrowS={+-0.01pt:scale=1.7-stealth, +-1.5pt:yellow-stealth}
适用于我的 CVS 版本,但|
没有显示。稳定2.10
版本|
可以使用,但黑色stealth
尖端没有缩放。
您需要在这里做出妥协,不使用该arrows.meta
库。
这flash
只是由markings
库绘制的,当然,您可以调整值。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric,arrows.meta,decorations.markings}
\tikzset{
big dot/.style={circle, draw, inner sep=0pt, minimum size=3mm, fill=yellow},
input/.style={draw, trapezium, trapezium left angle=60, trapezium right angle=120,
line width=1.2pt, fill={rgb:black,1;white,2}},
obstacle/.style={draw, trapezium, trapezium left angle=120, trapezium right angle=60,
line width=1.2pt, fill={rgb:black,1;white,2}},
flash/.style args={#1:#2}{postaction=decorate,decoration={name=markings,
mark=at position #1 with {%
\draw[fill=#2, line width=.75\pgflinewidth, line cap=round, line join=round]
(+\pgflinewidth,+7\pgflinewidth) -- ++ ( left:+2\pgflinewidth)
-- (+-4\pgflinewidth,+-\pgflinewidth) -- ++ (right:+5\pgflinewidth)
-- (+-\pgflinewidth,+-7\pgflinewidth) -- ++ (right:+2\pgflinewidth)
-- (+4\pgflinewidth,\pgflinewidth) -- ++ (left:+5\pgflinewidth) -- cycle;}}}
}
\begin{document}
\begin{tikzpicture}[very thick,
StealthFill/.tip={Stealth[line width=1pt, scale=1.5]}, arrows={[round]}]
\node[input] (goal1) at (0,0) {GOAL};
\node[input] (goal2) at (4,0) {GOAL};
\node[obstacle] (obstacle1) at (0,-1.5) {OBSTACLE};
\node[input] (goal3) at (1.5,-3) {GOAL};
\node[input] (goal4) at (4,-3) {GOAL};
\path (goal2) -- node[big dot] (bigdot) {} (goal4);
\path[line width=1.4pt, line cap=rect]
(goal1) edge[flash=.5:red] (goal2)
(bigdot) edge (goal3.north)
edge (goal4)
edge[-{StealthFill[fill=yellow]}] (goal2)
[bend left=10, StealthBar/.style={-{Bar[sep=2] StealthFill[fill=#1]}}]
(goal2) edge[StealthBar=green] (obstacle1)
(obstacle1) edge[StealthBar=red] (goal2);
\end{tikzpicture}
\end{document}