只是一个简单的问题。我正在尝试在 tikz 中填充抛物线形状。我设法让它水平工作。但是,当我垂直执行相同的方法时。有一个我无法解决的奇怪变形。图片如下!
这是创建该图像的代码:
\documentclass{article}
\usepackage{hyperref}
\usepackage[usenames,dvipsnames,x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows,snakes,shapes}
\begin{document}
\begin{figure}[h] \label{Interesting_Pic}
\begin{tikzpicture}
\begin{scope}
%Grid and outer layers
\draw[black, very thick] (4,-0.5) rectangle (9,4.5);
\draw[black, very thick] (4.5,0) rectangle (8.5,4);
\draw[step=5mm,black] (4.5,0) grid (8.5,4);
%diagonal lines in corner
\draw[fill=lime] (4,-0.5) -- (4.5,0);
\draw[fill=lime] (4,4.5) -- (4.5,4);
\draw[fill=lime] (9,-0.5) -- (8.5,0);
\draw[fill=lime] (8.5,4) -- (9,4.5);
%Labels lines in corners
\fill[font=\footnotesize]
(4,-0.5) node [left] {$A_{4}$}
(4,4.5) node [left] {$A_{1}$}
(9,-0.5) node [right] {$A_{3}$}
(9,4.5) node [right] {$A_{2}$};
%Draw parabola bends
\draw[bend left,->] (4.5,0) to node [auto] {} (8.5,0);
\draw[bend right,->] (4.5,0) to node [auto] {} (4.5,4);
\draw[bend left,->] (8.5,0) to node [auto] {} (8.5,4);
\draw[bend left,->] (8.5,4) to node [auto] {} (4.5,4);
%Colour in parabola areas
\draw[fill=white] (8.5,0) -- (4.5,0) parabola bend (6.5,0.6) (8.5,0);
\draw[fill=white] (8.5,0) -- (8.5,4) to node (7.1,2) {} (8.5,0);
\draw[fill=white] (4.5,0) parabola bend (5.1,2) (4.5,4) -- (4.5,0);
\draw[fill=white] (4.5,4) -- (8.5,4) parabola bend (6.5,3.4) (4.5,4);
\end{scope}
\end{tikzpicture}
\caption{An interesting diagram...}
\end{figure}
\end{document}
我对左侧和右侧尝试了两种不同的方法(如下方的 %right side 和 %left side 线所示),但都没有正常工作。
我试图对顶部和底部的曲线做同样的事情,但使用同样的方法会反转抛物线弯曲(如左图所示)。有人知道如何使左侧和右侧与顶部和底部相同吗?
干杯!:)
编辑:添加了完整的代码,因此它将创建上面的图像!
答案1
您之前在绘图中使用过bend left
/ ,再次使用它,效果很好。例如bend right
\draw[fill=white] (8.5,0) to[bend right] (4.5,0);
此图显示了原始代码的输出,其中有一些样式更改。蓝色箭头由 组成bend left
,红色虚线由 组成parabola bend
。它们不是 100% 等效,但非常接近。
说到箭头,你想把它们弄大一点吗(它们几乎看不见)?还是把它们全部去掉?
其他一些评论:
- 软件包
hyperref
通常应该延迟加载,请参阅哪些包应该在 hyperref 之后加载而不是之前加载? - 正如我在评论中提到的,您需要将放在
\label
之后\caption
,否则交叉引用将不起作用,请参阅为什么环境的标签必须出现在标题之后? - 您的
scope
环境实际上没有做任何有用的事情。 - 我
\centering
之前还加过\begin{tikzpicture}
- 在以 开头的块中
%Draw Pin-Cushion Distortion
,每行都有一个空节点,这是不需要的。 - 当您在角之间绘制线条时,您还会看到
fill=lime
。您是否打算用 填充任何区域lime
,或者这只是您忘记删除的内容?
话虽如此,这是一个完整的示例。使用命名坐标有时很有用,我重写了代码以显示使用此类坐标的一种方法。当然,您不必使用它。
\documentclass{article}
\usepackage[usenames,dvipsnames,x11names]{xcolor}
\usepackage{tikz}
\usepackage{hyperref}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture} %detector on right (Pin-Cushion distorted)
\begin{scope}[every label/.style={font=\footnotesize}]
% coordinates at outer corners
\coordinate [label=left:$A_1$] (A1) at (4,4.5);
\coordinate [label=right:$A_2$] (A2) at (9,4.5);
\coordinate [label=right:$A_3$] (A3) at (9,-0.5);
\coordinate [label=left:$A_4$] (A4) at (4,-0.5);
\end{scope}
% inner corners, relative to outer corners
\path (A1) ++(0.5,-0.5) coordinate (B1);
\path (A2) ++(-0.5,-0.5) coordinate (B2);
\path (A3) ++(-0.5,0.5) coordinate (B3);
\path (A4) ++(0.5,0.5) coordinate (B4);
%Grid and outer layers of detector
\draw[black, very thick] (A4) rectangle (A2);
\draw[black, very thick] (B4) rectangle (B2);
\draw[step=5mm,black] (B4) grid (B2);
%Anode wiring
\foreach \i in {1,...,4}
\draw (A\i) -- (B\i);
% draw and fill bendy lines
\draw[bend left,fill=white] (B4) to (B3);
\draw[bend right,fill=white] (B4) to (B1);
\draw[bend left,fill=white] (B3) to (B2);
\draw[bend left,fill=white] (B2) to (B1);
\end{tikzpicture}
\caption{An interesting diagram...}
\label{PCDistort}
\end{figure}
\end{document}
答案2
可以水平绘制抛物线弯曲,然后旋转它。我已经命名了坐标,以方便操作:
\documentclass{article}
\usepackage{hyperref}
\usepackage[usenames,dvipsnames,x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows,snakes,shapes}
\begin{document}
\begin{tikzpicture}
% Coordinates
\coordinate (sw) at (4.5, 0);
\coordinate (ne) at ([shift=(sw)] 4, 4);
\coordinate (nw) at (sw |- ne);
\coordinate (se) at (sw -| ne);
\coordinate[label=left:$A_1$] (A1) at ([shift=(nw)] -.5, .5);
\coordinate[label=right:$A_2$] (A2) at ([shift=(ne)] .5, .5);
\coordinate[label=right:$A_3$] (A3) at ([shift=(se)] .5, -.5);
\coordinate[label=left:$A_4$] (A4) at ([shift=(sw)] -.5, -.5);
% Grid and outer layers of detector
\draw[black, very thick] (A1) rectangle (A3);
\draw[black, very thick] (sw) rectangle (ne);
\draw[step=5mm,black] (sw) grid (ne);
% Anode wiring
\draw (A1) -- (nw);
\draw (A2) -- (ne);
\draw (A3) -- (se);
\draw (A4) -- (sw);
%Colour in distorted areas
\draw[fill=white] (sw) parabola bend +(2, .6) (se) -- cycle;
\draw[fill=white] (nw) parabola bend +(2, -.6) (ne) -- cycle;
\begin{scope}[shift=(sw), rotate=90]
\draw[fill=white] (0,0) parabola bend +(2, -.6) ++(4, 0) -- cycle;
\end{scope}
\begin{scope}[shift=(se), rotate=90]
\draw[fill=white] (0,0) parabola bend +(2, .6) ++(4, 0) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}