在 TikZ 中绘制环形和矩形之间的重叠?

在 TikZ 中绘制环形和矩形之间的重叠?

矩形和环形

我正在尝试重新创建发布的图像。到目前为止,我已经设法在第一象限中绘制了一个环,但我很难让矩形重叠并突出显示该区域。换句话说,我想在第一象限中绘制一个环,并将矩形重叠到环上并突出显示封闭区域。我不太熟悉 TikZ,但这对我的论文来说是必要的。有人可以给我指点一下吗?:)

编辑:到目前为止我的代码如下

\begin{tikzpicture}
\draw (-.5,0)--(3.5,0) node[right]{$\mathrm{Re}$}; 
\draw (0,-.5)--(0,3.5) node[above]{$\mathrm{Im}$};
\filldraw[fill=black, fill opacity=.2] (2.5,0) arc [radius=2.5, start angle=0, delta angle=90]
              -- (0,3) arc [radius=3, start angle=90, delta angle=-90]
              -- cycle;
\draw[fill=black,fill opacity=0.2] (0.8,2.9) rectangle (2.8,1.1);
\draw (0.8,2.9) node [above]{$\beta$};
\draw (2.85,1) node [right]{$\alpha$};
\end{tikzpicture}

答案1

这是我的方法,可能还有其他方法

\documentclass{standalone}

\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-.5,0)--(3.5,0) node[right]{$\mathrm{Re}$}; 
\draw (0,-.5)--(0,3.5) node[above]{$\mathrm{Im}$};

% for some more tidy code
\coordinate (T1) at (2.5,0);
\coordinate (T2) at (0,3);

\draw
(T1) arc [radius=2.5, start angle=0, delta angle=90]
-- (T2) arc [radius=3, start angle=90, delta angle=-90]
coordinate[pos=.18] (T3) % define points on curve
coordinate[pos=.75] (T4)
-- cycle;

% draw the points if you need to see them
\fill (T3) circle (1pt);
\fill (T4) circle (1pt);

% trick use clip to limit the area we are filling
\begin{scope}
  \clip
  (T1) arc [radius=2.5, start angle=0, delta angle=90]
  -- (T2) arc [radius=3, start angle=90, delta angle=-90]
  -- cycle;
  \clip
  (T3) rectangle (T4);
  \draw[fill=black,fill opacity=0.2]
  (T3) rectangle (T4);

\end{scope}

% redraw the edges
\draw (T3) rectangle (T4);


\draw (T3) node [above]{$\beta$};
\draw (T4) node [right]{$\alpha$};
\end{tikzpicture}
\end{document}

答案2

这也值得元帖子解决方案,仅用于比较(并且因为使用 MP 绘制坐标几何比担心 CV 更好)。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    path xx, yy, box, annulus, shaded_area;
    numeric u; u = 1cm;

    xx = (left -- 6 right) scaled u;
    yy = xx rotated 90;

    z1 = (4, 2) scaled u;
    z2 = (2, 5) scaled u;

    box = unitsquare xscaled (x1-x2) yscaled (y2-y1) shifted (x2, y1);
    annulus = quartercircle scaled 2 abs z1 --
      reverse quartercircle scaled 2 abs z2 -- cycle;

    % for i=1 upto length(annulus): dotlabel.top(decimal i, point i of annulus); endfor

    shaded_area = buildcycle(subpath (0, 2) of annulus, 
                             subpath (4, 2) of box, 
                             subpath (3, 5) of annulus,
                             subpath (2, 0) of box);

    fill shaded_area withcolor 7/8 [blue, white];

    draw box;
    draw annulus;

    drawarrow xx;
    drawarrow yy;

    dotlabel.rt("$\alpha$", z1);
    dotlabel.top("$\beta$", z2);

    draw (down--up) scaled 3 shifted (x1, 0); 
    draw (down--up) scaled 3 shifted (x2, 0); 
    draw (left--right) scaled 3 shifted (0, y1); 
    draw (left--right) scaled 3 shifted (0, y2); 

    label.bot("$a$", (x1, -3)); label.lft("$b$", (-3, y1));
    label.bot("$c$", (x2, -3)); label.lft("$d$", (-3, y2));

endfig;
\end{mplibcode}
\end{document}

这已被包裹起来,luamplib因此您可以编译它lualatex或研究如何使其适应普通 MP。

相关内容