填充仅有一个交点的两条线之间的区域

填充仅有一个交点的两条线之间的区域

我正在尝试填充这两条仅连接一端的线之间的区域。

\documentclass{beamer}

\usetheme{Berkeley}%{Marburg}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{amsmath}
\usepackage{nicefrac}
\usepackage{pgfplots}% loads also tikz
\usepackage{multirow}
\pgfplotsset{compat=newest}% to avoid the pgfplots warning
\usetikzlibrary{intersections}
\usepgfplotslibrary{fillbetween}
\pgfdeclarelayer{pre main}

\begin{document}
\begin{frame}
        \begin{tikzpicture}[scale =1.3]
        \draw [step=.25,gray,very thin] (0,0)grid(5,5);
    
    
    \node [right] at (5.1,2.2) {\rotatebox{90}{\scriptsize Sense-Object $S$}};
    \node [below,left] at (2.8,-.3) {\scriptsize Sense-Object $R$};
    
    \node [align=right] at (5.6,4.8) {\scriptsize Origin for\\ \scriptsize Person $1$};
    \node [align=right] at (-.7,.7) {\scriptsize Origin for\\\scriptsize Person $2$};
    
    %initial endowment
    %\node [circle, fill=blue] at (2.5,3){};
    \fill[red] (.5,4.25) circle (1.5pt);
    \draw[red, thick, name path = A] plot [smooth] coordinates {(.5,4.25)(2.5,4.1)(4.75,3.05)};
    \draw[blue, thick, name path = B] plot [smooth] coordinates {(.5,4.25)(2.75,2.75)(5,2.37)};
    \fillbetween[of=A and B];
    \end{tikzpicture}
\end{frame}
    \end{document}

我只是想用部分透明的颜色填充红线和蓝线之间的区域。我希望填充刚好在红线的末端结束。

答案1

fillbetween只能在pgfplots环境中使用,因此这里必须添加\usetikzlibrary{pgfplots.fillbetween}。然后,稍微作弊一下(创建第三条路径,名为 B,以 x=4.75 结束),您会得到以下结果:

填充中间的 tikz

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz}
    \usetikzlibrary{patterns}
    \usepackage{amsmath}
    \usepackage{nicefrac}
    \usepackage{pgfplots}% loads also tikz
    \usepackage{multirow}
    \pgfplotsset{compat=newest}% to avoid the pgfplots warning
    \usetikzlibrary{intersections,pgfplots.fillbetween}
    \usepgfplotslibrary{fillbetween}
    \pgfdeclarelayer{pre main}

    \begin{document}
        \begin{tikzpicture}[scale =1.3]
        \draw [step=.25,gray,very thin] (0,0)grid(5,5);
    
    
    \node [right] at (5.1,2.2) {\rotatebox{90}{\scriptsize Sense-Object $S$}};
    \node [below,left] at (2.8,-.3) {\scriptsize Sense-Object $R$};
    
    \node [align=right] at (5.6,4.8) {\scriptsize Origin for\\ \scriptsize Person $1$};
    \node [align=right] at (-.7,.7) {\scriptsize Origin for\\\scriptsize Person $2$};
    
    %initial endowment
    %\node [circle, fill=blue] at (2.5,3){};
    \fill[red] (.5,4.25) circle (1.5pt);
    
    \draw[red, thick, name path = A] plot [smooth] coordinates {(.5,4.25)(2.5,4.1)(4.75,3.05)};
    \draw[blue, thick] plot [smooth] coordinates {(.5,4.25)(2.75,2.75)(5,2.37)};
    \path[name path = B] plot [smooth] coordinates {(.5,4.25)(2.75,2.75)(4.75,2.38)};
    
    
    \tikzfillbetween[of=A and B]{blue, opacity=0.2};
    \end{tikzpicture}

    \end{document}

答案2

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[red, thick] plot[smooth] coordinates {(.5,4.25)(2.5,4.1)(4.75,3.05)};
\draw[blue, thick] plot[smooth] coordinates {(.5,4.25)(2.75,2.75)(5,2.37)};
\clip (0,2) rectangle (4.75,5);
\fill[blue, opacity=0.2] plot[smooth] coordinates {(.5,4.25)(2.5,4.1)(4.75,3.05)} -- plot[smooth] coordinates {(5,2.37)(2.75,2.75)(.5,4.25)} -- cycle;
\end{tikzpicture}
\end{document}

中间填充红色和蓝色曲线

相关内容