TikZ 中图形的填充区域

TikZ 中图形的填充区域

我已经弄清楚如何制作图表并绘制它们。现在我不知道如何标记中间的三角形(虚线右侧,两条红线之间)。

\begin{tikzpicture}[scale=2.5]
%Axis
\draw [<->,thick] (0,1.25) node (yaxis) [above] {$y$}
|- (5,0) node (xaxis) [right] {$x$};

\draw [color=red, thick] (0,1.20) node[left,color=black] {$40$} -- (4.95,0) node[below,color=black] {$160$};
\draw [color=red] (0,0.60) node[left,color=black] {$20$} -- (5,0.60);
\node at (4,0.70) {$MC$};
\node at (1,1.10) {$MR$};
\draw [color=black, dashed] (1.2375,0.9) -- (0,0.9)  node[left,color=black] {$p^*$};
\draw [color=black, dashed] (1.2375,0.9) -- (1.2375,0)  node[below,color=black] {$q^*$};
\draw [color=blue] (0,1.20) -- (2.575,0) node[below,color=black] {$80$};
\end{tikzpicture}

在此处输入图片描述

答案1

你喜欢吗:

在此处输入图片描述

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{backgrounds,intersections}

    \begin{document}
\begin{tikzpicture}[scale=2.5]
%Axis
\draw [<->,thick] (0,1.25) node (yaxis) [above] {$y$}
|- (5,0) node (xaxis) [right] {$x$};

\draw [color=red,thick,
       name path=A] (0,1.20) node[left,color=black] {$40$} -- (4.95,0) node[below,color=black] {$160$};
\draw [color=red,name path=B] (0,0.60) node[left,color=black] {$20$} -- (5,0.60);
\node at (4,0.70) {$MC$};
\node at (1,1.10) {$MR$};
\draw [color=black, dashed,
       name path=C] (0,0.9)     node[left] {$p^*$}  -|
                            (1.2375,0)  node[below] {$q^*$};
\draw [color=blue] (0,1.20) -- (2.575,0) node[below,color=black] {$80$};
%
    \begin{scope}[scale=0.4]
\coordinate[name intersections={of= A and B,by=x1}];
\coordinate[name intersections={of= A and C,by=x2}];
\coordinate[name intersections={of= B and C,by=x3}];
\scoped[on background layer]
\fill[gray!30] (x1) -- (x2) -- (x3) -- cycle;
    \end{scope}    
\end{tikzpicture}
    \end{document}

我使用交叉库来确定线交叉点的坐标,然后在背景层上绘制填充。

相关内容