4

My Goal

I'm trying to make a shape in TikZ like the one depicted in the following sketch:

Annulus with rectangle at base, as described in following paragraph, but with dashed arrows and text annotations for dimensions

It's the union of an annulus and a rectangle, with the region shaded and outlined. The annulus has a given inner radius and outer radius. The rectangle, located at the bottom of the annulus and with its left side aligned with the center of the annulus, has a height equal to the width of the annulus and some length that is some value up to the outer radius of the annulus).

My Work So Far

\documentclass[tikz]{standalone}

% Definitions
\newcommand*{\innerRadius}{3cm}
\newcommand*{\outerRadius}{4cm}
\newcommand*{\footLength}{2.4cm}

\begin{document}
\begin{tikzpicture}

% Draw the ring
\draw[fill=gray!30,even odd rule]  (0,0) circle (\outerRadius)
                                   (0,0) circle (\innerRadius);
% Draw the rectangle
\draw[fill=gray!30] (0,-\outerRadius) rectangle (\footLength,-\innerRadius);

\end{tikzpicture}
\end{document}

This produces the following:

Similar to above picture, minus arrows and annotations, and the rectangle outline covers the annulus outline

The problem with my code is that the rectangle's outline covers the annulus.

My Question

How can I make the desired figure in TikZ such that the outline is around the entire region rather than having the rectangle's outline be separate from the annulus's outline?

Bonus Points (not necessary!)

If the outer radius is large and the inner radius of the annulus is only slightly less, and if the rectangle is wide enough (e.g. 5 cm, 4 cm and 3.5 cm, respectively) then the outer edge of the annulus will intersect the top of the rectangle rather than its right side, as shown below. In this case, I don't like that the right side of the foot does not reach the annulus. Modeling the intended figure with an annulus and a rectangle is insufficient in this special case.

Almost looks like a letter Q. See description of this figure above.

If possible, I'd love to have a solution that raises the right side of the rectangle up to meet the outer edge of the annulus. In this case, a rectangle would no longer be sufficient: a rectangle should not reach higher than the inner radius of the annulus on the left, but the right side needs to reach from the bottom to the outer radius on the right. This would give me more flexibility with my diagram's dimensions and would give me more insight into how TikZ works. However, I do not expect to need this, so this would be for my curiosity. I would be grateful for any solution, with or without this extension!

1 Answer 1

7

The standard case is very simple.

\documentclass[tikz]{standalone}

% Definitions
\newcommand*{\innerRadius}{3cm}
\newcommand*{\outerRadius}{4cm}
\newcommand*{\footLength}{2.4cm}
\begin{document}
\begin{tikzpicture}
% Draw the thing
\draw[fill=gray!30,even odd rule]  
    (0,-\outerRadius) arc[start angle=270,end angle={-90+asin(\footLength/\outerRadius)},radius=\outerRadius]
    |- cycle                                  
    (0,0) circle[radius=\innerRadius];
% double-check that it works
% \draw[dashed] (0,-\outerRadius) rectangle (\footLength,-\innerRadius);
\end{tikzpicture}
\end{document}

For the general case, i.e. to include the "bonus" situation I'd use a pic.

\documentclass[tikz]{standalone}
\newcommand*{\innerRadius}{3cm}
\newcommand*{\outerRadius}{4cm}
\newcommand*{\footLength}{2.4cm}
\tikzset{pics/my pic/.style={code={
 \pgfmathtruncatemacro{\itest}{\footLength>\outerRadius}
 \ifnum\itest=0
  \pgfmathsetmacro{\myangle}{asin(\footLength/\outerRadius)}
  \pgfmathtruncatemacro{\itest}{(1-cos(\myangle))*\outerRadius>\outerRadius-\innerRadius}
 \fi
 \ifnum\itest=0
   \draw[fill=gray!30,even odd rule]  
    (0,-\outerRadius) arc[start angle=270,end angle={-90+\myangle},radius=\outerRadius]
    |- cycle                                  
    (0,0) circle[radius=\innerRadius];
 \else
  \pgfmathsetmacro{\myangle}{acos(\innerRadius/\outerRadius)}
   \draw[fill=gray!30,even odd rule]  
    (0,-\outerRadius) arc[start angle=270,end angle={-90+\myangle},radius=\outerRadius]
    -- (\footLength,-\innerRadius)
    |- cycle                                  
    (0,0) circle[radius=\innerRadius];
 \fi    
}}}
\begin{document}
\begin{tikzpicture}
 \pic{my pic};
\end{tikzpicture}
\renewcommand*{\footLength}{3.5cm}
\begin{tikzpicture}
 \pic{my pic};
\end{tikzpicture}
\end{document}

enter image description here

4
  • 1
    Your solution works perfectly for both the cases asked by OP, thanks to the even-odd rule. Obviously, one should not set the footlength greater than the outer radius.
    – SebGlav
    Commented Mar 14, 2021 at 16:44
  • 1
    @SebGlav Yes, in the first solution there is this limitation but with the pic that I just added you can go to greater footlengths.
    – user237299
    Commented Mar 14, 2021 at 16:47
  • 1
    You're right, but I think that it's not what OP asked. Anyway, your second option is quite interesting to have in this post, as a reference.
    – SebGlav
    Commented Mar 14, 2021 at 16:49
  • Correct: the second "general" solution isn't what I asked, but it is neat! The first solution solves my basic and bonus-case problems. Thanks! Take my upvote and solution rep! :-)
    – jvriesem
    Commented Mar 14, 2021 at 18:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .