箭头迷失在环内

箭头迷失在环内

我有这个代码:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage[margin=.5cm]{geometry}

\begin{document}
    \thispagestyle{empty}
    \begin{tikzpicture}[scale=2]
        \draw[gray!20,dashed] (-4,-4) grid (4,4);
        \draw[-latex] (-4.2,0)--(4.3,0) node[right] () {\footnotesize $x$};
        \foreach \i in {-4,...,-1,1,2,...,4}
            \draw (\i,-0)--(\i,-0.1) node[below] () {\footnotesize \i};
        \draw[-latex] (0,-4.2)--(0,4.3) node[above] () {\footnotesize $y$};
        \foreach \i in {-4,...,-1,1,2,...,4}
            \draw (0,\i)--(-.1,\i) node[left] () {\footnotesize \i};
        \draw (-.2,-.2) node () {\footnotesize $O$};
        \begin{scope}
            \clip (0,0) circle(4);
            \foreach \a in {45,135,225,315}{
            \draw[cyan,fill] plot[domain=-2:2,smooth,rotate=\a] (\x,{\x*\x+1});
            \draw[-latex,magenta,line width=2pt,rotate=\a] (1,0)--(4,0);
            }
        \end{scope}
        \draw[magenta] (0,0) circle(1);
        \draw[magenta] (0,0) circle(4);
        
    \end{tikzpicture}

输出如下:

在此处输入图片描述

为什么我丢失了第一支洋红色箭头?

编辑如果我采纳 Jasper 的建议并尝试将箭头画出范围之外:

\draw[-latex,magenta,line width=2pt] (.707,.707)--(2.828,2.828);

我有箭头!但这不是解决问题的好方法。我们可能在循环中遇到了问题tikz foreach

答案1

循环中的最后一个区域绘制在第一个箭头的上方。这可能就是您想要的:

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[gray!20, dashed] (-4,-4) grid (4,4);
\draw[-latex] (-4.2,0)--(4.3,0) node[right]{\footnotesize $x$};
\foreach \i in {-4,...,-1,1,2,...,4}
\draw (\i,-0)--(\i,-0.1) node[below]{\footnotesize \i};
\draw[-latex] (0,-4.2)--(0,4.3) node[above]{\footnotesize $y$};
\foreach \i in {-4,...,-1,1,2,...,4}
\draw (0,\i)--(-.1,\i) node[left]{\footnotesize \i};
\draw (-.2,-.2) node{\footnotesize $O$};
\begin{scope}
\clip (0,0) circle(4);
\foreach \a in {45,135,225,315}{
\fill[cyan] plot[domain=-2:2, smooth, rotate=\a] (\x,{\x*\x+1});
\draw[-latex, magenta, ultra thick, rotate=\a] (0,1)--(0,4); %This is changed to point same way as the fill
}
\end{scope}
\draw[magenta] (0,0) circle(1);
\draw[magenta] (0,0) circle(4);
\end{tikzpicture}
\end{document}

带填充区域和箭头的圆形图

答案2

\foreach \a in {45}{
                \draw[cyan,fill] plot[domain=-2:2,smooth,rotate=\a] (\x,{\x*\x+1});
                \draw[-latex,magenta,line width=2pt,rotate=\a] (1,0)--(4,0);
                }

在此处输入图片描述

\foreach \a in {45}{
            \draw[cyan,fill] plot[domain=-2:2,smooth,rotate=-90+\a] (\x,{\x*\x+1});
            \draw[-latex,magenta,line width=2pt,rotate=\a] (1,0)--(4,0);
            }

在此处输入图片描述

完整代码

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage[margin=.5cm]{geometry}

\begin{document}
    \thispagestyle{empty}
    \begin{tikzpicture}[scale=2]
        \draw[gray!20,dashed] (-4,-4) grid (4,4);
        \draw[-latex] (-4.2,0)--(4.3,0) node[right] () {\footnotesize $x$};
        \foreach \i in {-4,...,-1,1,2,...,4}
            \draw (\i,-0)--(\i,-0.1) node[below] () {\footnotesize \i};
        \draw[-latex] (0,-4.2)--(0,4.3) node[above] () {\footnotesize $y$};
        \foreach \i in {-4,...,-1,1,2,...,4}
            \draw (0,\i)--(-.1,\i) node[left] () {\footnotesize \i};
        \draw (-.2,-.2) node () {\footnotesize $O$};
        \begin{scope}
            \clip (0,0) circle(4);
            \foreach \a in {45,135,225,315}{
            \draw[cyan,fill] plot[domain=-2:2,smooth,rotate=-90+\a] (\x,{\x*\x+1});
            \draw[-latex,magenta,line width=2pt,rotate=\a] (1,0)--(4,0);
            }
        \end{scope}
        \draw[magenta] (0,0) circle(1);
        \draw[magenta] (0,0) circle(4);
        
    \end{tikzpicture}

    \end{document}

在此处输入图片描述

答案3

我不太喜欢以下解决方案,但看起来@JasperHabicht 关于剪辑作为副作用的说法是正确的:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage[margin=.5cm]{geometry}

\begin{document}
    \thispagestyle{empty}
    \begin{tikzpicture}[scale=2]
        \draw[gray!20,dashed] (-4,-4) grid (4,4);
        \draw[-latex] (-4.2,0)--(4.3,0) node[right] () {\footnotesize $x$};
        \foreach \i in {-4,...,-1,1,2,...,4}
            \draw (\i,-0)--(\i,-0.1) node[below] () {\footnotesize \i};
        \draw[-latex] (0,-4.2)--(0,4.3) node[above] () {\footnotesize $y$};
        \foreach \i in {-4,...,-1,1,2,...,4}
            \draw (0,\i)--(-.1,\i) node[left] () {\footnotesize \i};
        \draw (-.2,-.2) node () {\footnotesize $O$};
        \begin{scope}
            \clip (0,0) circle(4);
            \foreach \a in {45,135,225,315}{
            \draw[cyan,fill] plot[domain=-2:2,smooth,rotate=\a] (\x,{\x*\x+1});
            }
            \foreach \a in {45,135,225,315}{
            \draw[-latex,magenta,line width=2pt,rotate=\a] (1,0)--(4,0);
            }
        \end{scope}
        \draw[magenta] (0,0) circle(1);
        \draw[magenta] (0,0) circle(4);

    \end{tikzpicture}
\end{document}

相关内容