我正在尝试撰写一份关于我在某些分析过程中使用的一些设备的报告,如下图所示:
我尝试重新创建它tikz
,这是我迄今为止的尝试
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% draw main body
\fill[gray!40!black!20](0,0) rectangle (5cm,7.5cm);
% draw bottom
\fill[red!80!black!70](0,0) rectangle (5cm,2cm);
% draw top
\draw[fill = blue](0,6) rectangle (5cm,7.5cm);
% draw circles at top of diagram
\fill[cyan!70!white](1.5,7)circle(0.5cm);
\fill[cyan!70!white](3.5,7)circle(0.5cm);
% draw lines
\draw (1,7.5)--(0.5,9);
\draw (2,7.5)--(2.5,9);
\draw (3,7.5)--(2.5,9);
\draw (4,7.5)--(4.5,9);
\end{tikzpicture}
\end{document}
导致:
说实话,这很糟糕。我正在努力寻找一种方法来 (1) 生成图表的顶部,即顶部部分,并使其看起来像光束正在远离光源。我该怎么做?
此外,我意识到我必须对此进行大量调整才能使其看起来更接近原始图表,但我想先从整理主要细节开始。有人能建议我如何使我的尝试看起来更接近图表吗?请记住,我的tikz
技能非常有限。
答案1
这种类型的图表可能在 Inkscape 等软件中绘制更高效,但只要有一点耐心,完全可以在 TikZ 中完成。
为了传达光束远离光源的讯息,我建议使用shade
,如下所示。代码远非最佳,特别是在可维护性方面,但重要部分已经存在。欢迎随时改进。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[thick]
% grey metallic part
\def\xgrey{1.2}
\def\ygrey{0}
\def\hgrey{1}
\shadedraw[%
draw = black,%
left color = gray!20,%
right color = gray!90,%
rounded corners = 1,
] (-\xgrey,\ygrey) rectangle (\xgrey,{\ygrey+\hgrey});
% red part
\def\yred{-.5}
\def\hred{.5}
\shadedraw[%
draw = black,%
left color = red!20,%
right color = red!90,%
rounded corners = 1,
] (-\xgrey,\yred) rectangle (\xgrey,{\yred+\hred});
\def\yred{-.5}
\def\hred{.5}
\def\redratio{1.1}
\shade[%
left color = blue!20,%
right color = blue!90,%
opacity=.2,
rounded corners = 1,
] (-\xgrey,\yred) rectangle (\xgrey,{\yred+\hred});
\draw [rounded corners = 1,
] (-{\redratio*\xgrey},\yred) rectangle ({\redratio*\xgrey},{\yred+\hred});
% blue part
\begin{scope}[scale=1.8,shift={(0,1)}]
\shadedraw[%
left color = blue!20,%
right color = blue!90,%
rounded corners=3,
] (-.11,0)
-- (.11,0)
-- (.76,-.2)
-- (.78,-.53)
-- (-.78,-.53)
-- (-.76,-.2)
-- cycle;
\draw[rounded corners=1] (-.78,-.53) rectangle (.78,-.58);
\shadedraw[%
left color = blue!20,%
right color = blue!90,%
rounded corners=1,
] (-.11,0) -- (.11,0) -- (.11,.-.53) -- (-.11,.-.53) -- cycle;
\end{scope}
% ellipses and beams
\def\rayyangle{15}
\def\yray{3}
\def\hray{4}
\def\a{.4}
\def\b{.1}
\def\afactor{1.2}
\def\bfactor{1.5}
\newcommand\stuffray[1]{
\draw[rotate={#1},fill=gray!90,thin] ellipse ({\a*\afactor} and {\b*\bfactor});
\draw[rotate={#1},fill=gray!20,thin] ellipse ({\a} and {\b});
\path[%
rotate={#1},
shade,%
bottom color = gray!20,%
top color = gray!1,%
opacity=.5,
] (-\a,0)
-- (-\a,{\hray})
-- (\a,{\hray})
-- (\a,0)
-- cycle;
\draw[black,very thin,rotate={#1},opacity=.1] (-\a,0) -- (-\a,{\hray});
\draw[black,very thin,rotate={#1},opacity=.1] (\a,0) -- (\a,{\hray});
}
\def\xrayshift{.72}
\def\yrayshift{1.45}
\begin{scope}[shift={(-\xrayshift,\yrayshift)}]
\stuffray{\rayyangle}
\end{scope}
\begin{scope}[shift={(\xrayshift,\yrayshift)}]
\stuffray{-\rayyangle}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
这可能是一个开始,但是,正如上面的评论所述,我认为使用 Inkscape 等绘制它可能会更有效率。
\documentclass{standalone}
\usepackage{tikz}
\def\beamr{0.5}
\def\beamlen{3}
\def\width{2.3}
\def\topwidth{3}
\def\toptopwidth{0.5}
\def\topheighta{0.8}
\def\topheightb{1.0}
\def\midwidth{0.4}
\newcommand\drawbeam{
\draw[draw=black!75, fill=black, fill opacity=0.2]
(-\beamr, 0) -- (-\beamr, \beamlen) -- (\beamr, \beamlen) -- (\beamr, 0);
\draw[draw=black!75, fill=white]
(0, 0) ellipse ({\beamr} and 0.1);
}
\begin{document}
\begin{tikzpicture}
\clip (-2, -3) rectangle (2, 2);
\fill[black!5] (-2, -3) rectangle (2, 2);
\begin{scope}[yshift=-75]
\shadedraw[draw=black, left color=red!20, right color=red!90, rounded corners=1]
({-0.5*\width},0) rectangle ({0.5*\width},1);
\end{scope}
\begin{scope}[yshift=-50]
\shadedraw[draw=black, left color=gray!10, right color=gray!90]
({-0.5*\width},0) rectangle ({0.5*\width},1);
\end{scope}
\begin{scope}[yshift=-26]
\shadedraw[draw=black, left color=blue!20, right color=blue!60, rounded corners=4]
({-0.5*\topwidth},0) -- ({0.5*\topwidth},0) -- ({0.5*\topwidth},\topheighta) -- ({0.5*\toptopwidth},\topheightb)
-- ({-0.5*\toptopwidth}, \topheightb) -- (-0.5*\topwidth,\topheighta) -- cycle;
\end{scope}
\begin{scope}[rotate=10, xshift=-20]
\drawbeam
\end{scope}
\begin{scope}[rotate=-10, xshift=20]
\drawbeam
\end{scope}
\begin{scope}[yshift=-26]
\shadedraw[draw=black, left color=blue!60, right color=blue!90, rounded corners=2]
(-0.5*\midwidth,0) rectangle (0.5*\midwidth,\topheightb);
\end{scope}
\end{tikzpicture}
\end{document}