3

This is the mwe; Left side is what I want, but how to connect properly on the right side?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \draw [help lines] (0,0) grid (4,4);
    \draw[rounded corners, fill=cyan!20] (4,2) arc [start angle=45, end angle=135, radius=2.828] arc [start angle=-131.81, end angle=-48.19, radius=3] -- cycle;
\end{tikzpicture}
\end{document}
 

rendered image

3

2 Answers 2

5

The problem here is that you are trying to round a corner in a path with two points that are very close to each other:

  • The end point of the second arc
  • The cycle point that close your path.

When I compile your code, I abtain an awful glitch:

enter image description here

I suggest here an alternative the solution based on cutting one of the arcs by the middle with an auxiliary path that find the middle point:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{ext.topaths.arcthrough}
\begin{tikzpicture}[x=1cm,y=1cm]
    \draw [help lines] (0,0) grid (4,6);
    \draw[rounded corners, fill=cyan!20] 
    (4,2) arc [start angle=45, end angle=135, radius=2.828] 
    arc [start angle=-131.81, end angle=-48.19, radius=3] -- cycle ;
    
    \begin{scope}[yshift=2cm]
      % Auxiliar path to calculate coordinate (A)
      \path   
      (4,2) 
      arc [start angle=45, end angle=135, radius=2.828] 
      node[pos=0.5, circle, fill=red, inner sep=1pt] (A) {} 
      ;

      \draw[rounded corners, fill=cyan!20] 
      (A) 
      arc [start angle=90, end angle=135, radius=2.828] 
      arc [start angle=-131.81, end angle=-48.19, radius=3] 
      arc [start angle=45, end angle=90, radius=2.828] 
      ;
    \end{scope}

\end{tikzpicture}
\end{document}  

enter image description here

1
  • really simpler and better idea; Thanks.
    – LL L
    Commented Jan 20 at 9:00
4

fig

With some mathematics... I tried to use useful names for the variables: radius, side of the equilateral triangle (since the initial angle is \asrt=45), and various angles. If it is not clear, let me know.

Remark I updated the code; there are three variables: the radius \r, the initial angle \asrt, and the correcting angle \adif needed to obtain the rounded corners. Note that the rounded corners does not work correctly if \adif=3 for example.

The code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, math}
\begin{document}

\begin{tikzpicture}[%
  evaluate={%
    \r = 2.8;
    \asrt = 45;
    \aend = 180 -\asrt;
    \adif = 5;
    \s = \r*sin(\asrt);
  }]
  \draw [help lines] (-2, -2) grid (2, 2);
  \draw[blue] (-2.5, 0) -- (2.5, 0);
  
  \draw[red, rounded corners, fill=cyan!20]
  ($(0, -\s) +(\asrt +\adif: \r)$)
  arc (\asrt +\adif:\aend -\adif: \r)
  -- ($(0, \s) +(-\aend +\adif: \r)$)
  arc (-\aend +\adif:-\asrt -\adif: \r) -- cycle;
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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