0

I would like to display a Polar Grid instead of the cartesian axes (see lines 9 and 10). The following code creates a custom plot (not over the addplot command of pgfplots package). With what needs the lines 9 and 10 to be replaced in order to have a Polar Grid? Limacon

Code:

\documentclass[tikz,border=3mm]{standalone}
\newif\iftikzepitrochoidhasxis
\tikzepitrochoidhasxistrue
\tikzset{pics/epitrochoid/.style={code={%
  \tikzset{epitrochoid/.cd,#1}
  \def\pv##1{\pgfkeysvalueof{/tikz/epitrochoid/##1}}
  \pgfmathsetmacro{\mymax}{2*max(abs(\pv{r}),abs(\pv{d}))+abs(\pv{R})+0.5}
  \iftikzepitrochoidhasxis
   \draw[-stealth] (-\mymax,0) -- (\mymax,0) node[below left]{$x$};
   \draw[-stealth] (0,-\mymax) -- (0,\mymax) node[below left]{$y$};
  \else 
   \path (-\mymax,-\mymax) rectangle (\mymax,\mymax);
  \fi 
  \draw[blue,semithick] circle[radius=\pv{R}];
  \draw[semithick] ({deg(\pv{t})}:{abs(\pv{r})+abs(\pv{R})}) coordinate (c) circle[radius=\pv{r}];
  \pgfmathtruncatemacro\itest{(\pv{t}>0?1:0)}
  \ifnum\itest=1
   \pgfmathsetmacro{\isamples}{5+2*(\pv{R}+\pv{r})*int(\pv{t})}
   \draw[red,thick] plot[smooth,samples=\isamples,domain=0:\pv{t},variable=\t,smooth]
    ({(\pv{R}+\pv{r})*cos(deg(\t))-\pv{d}*cos((\pv{R}+\pv{r})*deg(\t)/\pv{r})},
     {(\pv{R}+\pv{r})*sin(deg(\t))-\pv{d}*sin((\pv{R}+\pv{r})*deg(\t)/\pv{r})})
     node[circle,inner sep=1.2pt,fill](e){};
    \draw  (c) node[circle,inner sep=1.2pt,fill]{}  -- (e); 
   \fi
}},
epitrochoid/.cd,R/.initial=3,r/.initial=1,d/.initial=0.5,t/.initial=1,
    axis/.is if=tikzepitrochoidhasxis,axis/.default=true}
\begin{document}
\foreach \Time in {0,0.1,...,6.2}
{\begin{tikzpicture}
 \pic{epitrochoid={t=\Time}};
\end{tikzpicture}}
\end{document}

2 Answers 2

1
\documentclass[tikz,border=3mm]{standalone}
\newif\iftikzepitrochoidhasxis
\tikzepitrochoidhasxistrue
\tikzset{pics/epitrochoid/.style={code={%
  \tikzset{epitrochoid/.cd,#1}
  \def\pv##1{\pgfkeysvalueof{/tikz/epitrochoid/##1}}
  \pgfmathsetmacro{\mymax}{2*max(abs(\pv{r}),abs(\pv{d}))+abs(\pv{R})+0.5}
  \iftikzepitrochoidhasxis
   \draw[-stealth] (-\mymax,0) -- (\mymax,0) node[below left]{$x$};
   \draw[-stealth] (0,-\mymax) -- (0,\mymax) node[below left]{$y$};
    %Circles 
    \foreach \r in {1, 2,...,7}
      \draw[thin, gray] (0,0) circle (\r);    
    \foreach \r in {0.5, 1.5,...,7}
      \draw[thin, gray] (0,0) circle (\r);
    %1° Rays
    \foreach \a in {0, 1,...,359}
      \draw[gray] (\a:7.7) -- (\a:8);
    %5° Rays
    \foreach \a in {0, 5,...,359}
      \draw[gray] (\a:7.5) -- (\a:8);      
    %15° Rays
    \foreach \a in {0, 15,...,359}
      \draw[gray] (\a:1) -- (\a:8); 
    %30° Rays
    \foreach \a in {0, 30,...,359}
      \draw[gray] (0, 0) -- (\a:8);
    %Radius labels (background filled white)
    \foreach \r in {1, 2,...,7}
      \draw (\r,0) node[inner sep=1pt,below=3pt,rectangle,fill=white] {$\r$};
    %Main rays
    \foreach \a in {0, 90,...,359}
      \draw[gray] (0, 0) -- (\a:8);
    %Angle labels  
    \foreach \a in {0, 15,...,359}
      \draw (\a: 8.5) node {$\a^\circ$};
    %Central point
    \draw[fill=red] (0,0) circle(0.7mm);
  \else 
   \path (-\mymax,-\mymax) rectangle (\mymax,\mymax);
  \fi 
  \draw[blue,semithick] circle[radius=\pv{R}];
  \draw[semithick] ({deg(\pv{t})}:{abs(\pv{r})+abs(\pv{R})}) coordinate (c) circle[radius=\pv{r}];
  \pgfmathtruncatemacro\itest{(\pv{t}>0?1:0)}
  \ifnum\itest=1
   \pgfmathsetmacro{\isamples}{5+2*(\pv{R}+\pv{r})*int(\pv{t})}
   \draw[red,thick] plot[smooth,samples=\isamples,domain=0:\pv{t},variable=\t,smooth]
    ({(\pv{R}+\pv{r})*cos(deg(\t))-\pv{d}*cos((\pv{R}+\pv{r})*deg(\t)/\pv{r})},
     {(\pv{R}+\pv{r})*sin(deg(\t))-\pv{d}*sin((\pv{R}+\pv{r})*deg(\t)/\pv{r})})
     node[circle,inner sep=1.2pt,fill](e){};
    \draw  (c) node[circle,inner sep=1.2pt,fill]{}  -- (e); 
   \fi
}},
epitrochoid/.cd,R/.initial=3,r/.initial=1,d/.initial=0.5,t/.initial=1,
    axis/.is if=tikzepitrochoidhasxis,axis/.default=true}
\begin{document}
\foreach \Time in {0,0.1,...,6.2}
{\begin{tikzpicture}
 \pic{epitrochoid={t=\Time}};
\end{tikzpicture}}
\end{document}

enter image description here

\documentclass[tikz,border=3mm]{standalone}
\newif\iftikzepitrochoidhasxis
\tikzepitrochoidhasxistrue
\tikzset{pics/epitrochoid/.style={code={%
  \tikzset{epitrochoid/.cd,#1}
  \def\pv##1{\pgfkeysvalueof{/tikz/epitrochoid/##1}}
  \pgfmathsetmacro{\mymax}{2*max(abs(\pv{r}),abs(\pv{d}))+abs(\pv{R})+0.5}
  \iftikzepitrochoidhasxis
    %Circles 
    \foreach \r in {1, 3, ..., 7}
      \draw[thin, gray] (0,0) circle (\r);  
      \draw[thin, black] (0,0) circle (7);      
    %30° Rays
    \foreach \a in {0, 30,...,359}
      \draw[gray] (0, 0) -- (\a:7);
    %Main rays
    \foreach \a in {0, 90,...,359}
      \draw[gray] (0, 0) -- (\a:7);
    %Angle labels  
    \foreach \a in {0, 30,...,359}
      \draw (\a: 7.5) node {$\a^\circ$};
  \else 
   \path (-\mymax,-\mymax) rectangle (\mymax,\mymax);
  \fi 
  \draw[blue,semithick] circle[radius=\pv{R}];
  \draw[semithick] ({deg(\pv{t})}:{abs(\pv{r})+abs(\pv{R})}) coordinate (c) circle[radius=\pv{r}];
  \pgfmathtruncatemacro\itest{(\pv{t}>0?1:0)}
  \ifnum\itest=1
   \pgfmathsetmacro{\isamples}{5+2*(\pv{R}+\pv{r})*int(\pv{t})}
   \draw[red,thick] plot[smooth,samples=\isamples,domain=0:\pv{t},variable=\t,smooth]
    ({(\pv{R}+\pv{r})*cos(deg(\t))-\pv{d}*cos((\pv{R}+\pv{r})*deg(\t)/\pv{r})},
     {(\pv{R}+\pv{r})*sin(deg(\t))-\pv{d}*sin((\pv{R}+\pv{r})*deg(\t)/\pv{r})})
     node[circle,inner sep=1.2pt,fill](e){};
    \draw  (c) node[circle,inner sep=1.2pt,fill]{}  -- (e); 
   \fi
}},
epitrochoid/.cd,R/.initial=3,r/.initial=1,d/.initial=0.5,t/.initial=1,
    axis/.is if=tikzepitrochoidhasxis,axis/.default=true}
\begin{document}
\foreach \Time in {0,0.1,...,6.2}
{\begin{tikzpicture}
 \pic{epitrochoid={t=\Time}};
\end{tikzpicture}}
\end{document}

enter image description here

1
  • Thank you very much. It would be great if we can draw the Polar Grid (less detailed) as shown in the following link: [link]i.stack.imgur.com/F28I5.jpg
    – John
    Jan 4, 2021 at 8:37
0

Thanks to @sergiokapone solution, a less detailed Polar Grid looks as follow:

\documentclass[tikz,border=3mm]{standalone}
\newif\iftikzepitrochoidhasxis
\tikzepitrochoidhasxistrue
\tikzset{pics/epitrochoid/.style={code={%
  \tikzset{epitrochoid/.cd,#1}
  \def\pv##1{\pgfkeysvalueof{/tikz/epitrochoid/##1}}
  \pgfmathsetmacro{\mymax}{2*max(abs(\pv{r}),abs(\pv{d}))+abs(\pv{R})+0.5}
  \iftikzepitrochoidhasxis
   %%%\draw[-stealth] (-\mymax,0) -- (\mymax,0) node[below left]{$x$};
   %%%\draw[-stealth] (0,-\mymax) -- (0,\mymax) node[below left]{$y$};
    %Circles
    \draw[thick, black] (0,0) circle (4);   
    \foreach \r in {1, 2,...,3}
      \draw[thin, gray] (0,0) circle (\r);    
%    \foreach \r in {0.5, 1.5,...,7}
%      \draw[thin, gray] (0,0) circle (\r);
    %1° Rays
%    \foreach \a in {0, 1,...,359}
%      \draw[gray] (\a:7.7) -- (\a:8);
    %5° Rays
%    \foreach \a in {0, 5,...,359}
%      \draw[gray] (\a:7.5) -- (\a:8);      
    %15° Rays
%    \foreach \a in {0, 15,...,359}
%      \draw[gray] (\a:1) -- (\a:8); 
    %30° Rays
    \foreach \a in {0, 30,...,359}
      \draw[gray] (0, 0) -- (\a:4);
    %Radius labels (background filled white)
    \foreach \r in {1, 2,...,3}
      \draw (\r,0) node[inner sep=1pt,below=3pt,rectangle,fill=white] {$\r$};
    %Main rays
    \foreach \a in {0, 90,...,359}
      \draw[gray] (0, 0) -- (\a:4);
    %Angle labels  
    \foreach \a in {0, 30,...,359}
      \draw (\a: 4.5) node {$\a^\circ$};
    %Central point
    \draw[fill=red] (0,0) circle(0.7mm);
  \else 
   \path (-\mymax,-\mymax) rectangle (\mymax,\mymax);
  \fi 
  \draw[blue,semithick] circle[radius=\pv{R}];
  \draw[semithick] ({deg(\pv{t})}:{abs(\pv{r})+abs(\pv{R})}) coordinate (c) circle[radius=\pv{r}];
  \pgfmathtruncatemacro\itest{(\pv{t}>0?1:0)}
  \ifnum\itest=1
   \pgfmathsetmacro{\isamples}{5+2*(\pv{R}+\pv{r})*int(\pv{t})}
   \draw[red,thick] plot[smooth,samples=\isamples,domain=0:\pv{t},variable=\t,smooth]
    ({(\pv{R}+\pv{r})*cos(deg(\t))-\pv{d}*cos((\pv{R}+\pv{r})*deg(\t)/\pv{r})},
     {(\pv{R}+\pv{r})*sin(deg(\t))-\pv{d}*sin((\pv{R}+\pv{r})*deg(\t)/\pv{r})})
     node[circle,inner sep=1.2pt,fill](e){};
    \draw  (c) node[circle,inner sep=1.2pt,fill]{}  -- (e); 
   \fi
}},
epitrochoid/.cd,R/.initial=3,r/.initial=1,d/.initial=0.5,t/.initial=1,
    axis/.is if=tikzepitrochoidhasxis,axis/.default=true}
\begin{document}
%%%\foreach \Time in {0,0.1,...,6.2}
{\begin{tikzpicture}
 \pic{epitrochoid={t=4.2,R=1,r=1,d=1}};
\end{tikzpicture}}
\end{document}

And gives the following graph: enter image description here

1
  • @sergiokapone. Thank you very much and my best wishes for the year 2021!
    – John
    Jan 4, 2021 at 9:11

You must log in to answer this question.

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