0

I've been playing around with custom arcs, but I can't seem to figure out how to set the arc radius automatically. Goal is to create a node that bounds two semi-circles and gets wider as needed

Links to the desired image at at the end

https://i.stack.imgur.com/E4qag.jpg

\usepackage{xparse}
\NewDocumentCommand{\mynode}{%
O{}
m
m
m
O{}
}{
{
\node [#1] (#2)  at #3 {#4};

\def\ra{.3cm}

\draw [#5] (#2.north west) arc [ start angle=90, end angle=270, x radius=\ra, y radius=\ra ] ;

\draw [#5] (#2.north east)to [in=0,out=180] (#2.north west); \draw [#5] (#2.south east)to [in=0,out=180] (#2.south west);

\draw [#5] (#2.south east) arc [ start angle=270, end angle=450, x radius=\ra, y radius=\ra ] ;

} }

This is what I want to make

  • The linked image uses circular arcs: x radius = y radius. It is basically a rectangle with rounded corners. OTOH, if you want elliptical nodes, see https://tex.stackexchange.com/questions/399116/ideal-shape-of-elliptical-nodes?r=SearchResults&s=1|54.4383 – John Kormylo Mar 11 '22 at 03:25
  • Thank you. I really want the circular arcs. Just can’t use a macro to calculate their radii – Dean C Wills Mar 11 '22 at 03:35

1 Answers1

1

This uses \pgfextracty etc. to get the height of the node. I also combined all your draws into one path.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{xparse}
\newlength{\mydiameter}
\NewDocumentCommand{\mynode}{% #1 = node options (optional), #2 = node name, #3 = coordinates, #4 = text, #5 = draw options (optional)
O{}
m
m
m
O{}
}{%
{%
\node [#1] (#2)  at #3 {#4};

\pgfextracty{\mydiameter}{\pgfpointdiff{\pgfpointanchor{#2}{south}}{\pgfpointanchor{#2}{north}}}%

\draw [#5] (#2.north west) arc [ start angle=90, end angle=270, radius={0.5\mydiameter} ] -- (#2.south east) arc [ start angle=-90, end angle=90, radius={0.5\mydiameter} ] -- cycle; }% }

\begin{document} \begin{tikzpicture} \mynode{A}{(0,0)}{Test} \end{tikzpicture} \end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120