You can fix this simply by adding ++
to the first coordinate in the insert path
key of elliparc
.

MWE:
\documentclass[tikz,margin=2mm]{standalone}
\usepackage{tikz}
\usepackage{amssymb}
\tikzset{elliparc/.style args={#1:#2:#3}{%
insert path={++(#1:#3) arc (#1:#2:#3)}}}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate=0]
\draw[dashed] (0,0) [elliparc=0:180:1cm and .5cm];
\draw (0,0) [elliparc=-180:0:1cm and .5cm];
\draw[dashed] (0,3) [elliparc=0:180:1cm and .5cm];
\draw (0,3) [elliparc=-180:0:1cm and .5cm];% working
\draw (1,0) -- ++(0,3);
\draw (-1,0) -- ++(0,3);
\path (0,0) -- node[pos=0.5,above] {$r$} ++(1,0);
\draw[thin,color=brown] (0,0) -- ++(0,3.05);
\draw[thin,color=brown] (0,0) -- ++(1,0);
\path (0,0) -- node[pos=0.5,above,sloped] {$h$} ++(0,3.05);
\end{scope}
\end{tikzpicture}
\end{document}
Just for fun I also edited your definition of \centerarc
such that the optional first argument is really optional, and it does not need the calc
library anymore, because that seemed a bit overkill.
\makeatletter
\def\centerarci[#1](#2) (#3:#4:#5)% Syntax: [draw options] (center) (initial angle:final angle:radius)
{\draw[#1] (#2) ++(#3:#5) arc (#3:#4:#5);}
\def\centerarc{\@ifnextchar[{\centerarci}{\centerarci[]}}
\makeatother
MWE with \centerarc
and drawing the cylinder with both options:
\documentclass[tikz,margin=2mm]{standalone}
\usepackage{tikz}
\usepackage{amssymb}
\makeatletter
\def\centerarci[#1](#2) (#3:#4:#5)% Syntax: [draw options] (center) (initial angle:final angle:radius)
{\draw[#1] (#2) ++(#3:#5) arc (#3:#4:#5);}
\def\centerarc{\@ifnextchar[{\centerarci}{\centerarci[]}}
\makeatother
\tikzset{elliparc/.style args={#1:#2:#3}{%
insert path={++(#1:#3) arc (#1:#2:#3)}}}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate=0]
\draw[dashed] (0,0) [elliparc=0:180:1cm and .5cm];
\draw (0,0) [elliparc=-180:0:1cm and .5cm];
\draw[dashed] (0,3) [elliparc=0:180:1cm and .5cm];
\draw (0,3) [elliparc=-180:0:1cm and .5cm];% working
\draw (1,0) -- ++(0,3);
\draw (-1,0) -- ++(0,3);
\path (0,0) -- node[pos=0.5,above] {$r$} ++(1,0);
\draw[thin,color=brown] (0,0) -- ++(0,3.05);
\draw[thin,color=brown] (0,0) -- ++(1,0);
\path (0,0) -- node[pos=0.5,above,sloped] {$h$} ++(0,3.05);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[rotate=0]
\centerarc[dashed](0,0) (0:180:1cm and 0.5cm);
\centerarc(0,0) (-180:0:1cm and 0.5cm);
\centerarc[dashed](0,3) (0:180:1cm and 0.5cm);
\centerarc(0,3) (-180:0:1cm and 0.5cm);
\draw (1,0) -- ++(0,3);
\draw (-1,0) -- ++(0,3);
\path (0,0) -- node[pos=0.5,above] {$r$} ++(1,0);
\draw[thin,color=brown] (0,0) -- ++(0,3.05);
\draw[thin,color=brown] (0,0) -- ++(1,0);
\path (0,0) -- node[pos=0.5,above,sloped] {$h$} ++(0,3.05);
\end{scope}
\end{tikzpicture}
\end{document}
\tikz\draw (3,0) arc [start angle=0, end angle=80, x radius=3, y radius=1];
?\draw (3,0) ++ ({3*cos(80)},{1*sin(80)}) arc (80:180:3 and 1);
for an arc with center at(3,0)
, start angle of80
, end angle of180
, x radius of3
and y radius of1
. Compare with\draw[dashed,gray] (3,0) circle (3 and 1);
to see the complete ellipse.\tikzset{elliparc/.style args={#1:#2:#3}{insert path={(#1:#3) arc (#1:#2:#3)}}}
to\tikzset{elliparc/.style args={#1:#2:#3}{insert path={++(#1:#3) arc (#1:#2:#3)}}}
. Notice the++
at the start ofinsert path
, which indicates that you use the last point as reference position.