Tikzpicture - finish drawing a curved line for a cake slice
If you use tikz-3dplot
, you do not have to guess the curves, and you can adjust the view angles at will.
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{75}{60}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[canvas is xy plane at z=0,name prefix=bot-]
\draw (0,0) coordinate (O) -- (4,0) coordinate (A) arc (0:60:4) coordinate
(B);
\end{scope}
\begin{scope}[canvas is xy plane at z=2,name prefix=top-]
\draw[fill=blue!20] (0,0) coordinate (O) -- (4,0) coordinate (A) arc (0:60:4) coordinate
(B) -- cycle;
\end{scope}
\draw foreach \X in {O,A,B}
{(bot-\X) -- (top-\X)};
\end{tikzpicture}
\end{document}
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\foreach \X in {89,88,...,60,61,62,...,88}
{\tdplotsetmaincoords{70+10*sin(6*\X)}{\X}
\pgfmathsetmacro{\xmin}{0}
\pgfmathsetmacro{\xmax}{0}
\pgfmathsetmacro{\ymin}{0}
\pgfmathsetmacro{\ymax}{0}
\begin{tikzpicture}[tdplot_main_coords]
\ifdefined\figbb\relax
\path \figbb;
\fi
\begin{scope}[canvas is xy plane at z=0,name prefix=bot-]
\draw (0,0) coordinate (O) -- (4,0) coordinate (A) arc (0:60:4) coordinate
(B);
\end{scope}
\begin{scope}[canvas is xy plane at z=2,name prefix=top-]
\draw[fill=blue!20] (0,0) coordinate (O) -- (4,0) coordinate (A) arc (0:60:4) coordinate
(B) -- cycle;
\end{scope}
\draw foreach \X in {O,A,B} {(bot-\X) -- (top-\X)};
\path let \p1=(current bounding box.south west),
\p2=(current bounding box.north east)
in \pgfextra{%
\pgfmathsetmacro{\xmin}{min(\x1,\xmin)}
\pgfmathsetmacro{\xmax}{max(\x2,\xmax)}
\pgfmathsetmacro{\ymin}{min(\y1,\ymin)}
\pgfmathsetmacro{\ymax}{max(\y2,\ymax)}
\xdef\xmin{\xmin pt}
\xdef\xmax{\xmax pt}
\xdef\ymin{\ymin pt}
\xdef\ymax{\ymax pt}
};
\end{tikzpicture}}
\makeatletter
\edef\figbb{(\xmin,\ymin) rectangle (\xmax,\ymax)}
\immediate\write\@mainaux{\xdef\string\figbb{\figbb}\relax}
\makeatother
\end{document}
If you want to allow for arbitrary view angles, you need to distinguish some cases as in this answer which provides you with the rest of the (cheese) cake (except for the piece stolen by the mouse;-).
Like this ?
To avoid having to manually calculate the coordinates of the points, I use the relative positioning of the points with the syntax --++
.
This syntax indicates that to obtain the coordinates of the next point, we add the preceding point (0,-1.24)
(4.23,-1.55) --++ (0,-1.24)
is equivalent to
(4.23,-1.55) -- (4.23,-2.79)
indeed 4.23 + 0 = 4.23
and -1.55 + (-1.24) = -2.79
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[thick,color=black,fill=gray!30] (0,0) -- (-20:4.5) arc(-20:-50:4.5) -- cycle;
\draw[thick,color=black,yshift=-1.24cm] (-20:4.5) arc(-20:-50:4.5) -- (0,0);
\draw[thick,color=black] (4.23,-1.55) --++ (0,-1.24);
\draw[thick,color=black] (2.9,-3.43) --++ (0,-1.24);
\draw[thick,color=black] (0,0) --++ (0,-1.24);
\end{tikzpicture}
\end{document}
One more example: In the drawing, angles are considered in reverse order. For vertical lines, the coordinate is defined, so that only one coordinate now is necessary to determine of height of slice:
\documentclass[tikz, margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[
every path/.style = {thick, line join=round} % style of lines
]
\draw[fill=gray!30] (0, 0) -- (-50:4.5) coordinate (a1) arc(-50:-20:4.5) coordinate (a2) -- cycle;
\draw (0,0) -- (0,-2) % determine height of slice
-- ++(-50:4.5) coordinate (b1) arc(-50:-20:4.5) coordinate (b2);
\draw (a1) -- (b1) (a2) -- (b2);
\end{tikzpicture}
\end{document}