So recently I started getting my feet wet with drawing 3D drawings. I'm trying to draw a 3d drawing with the tikz 3d library. But I'm facing some problems.
mainly commands like circle
, arc
, and rectangle
don't seem to work in the third dimension, which makes sense, since they work in the plane. To work around this, the pgf manual specifies that you can simply select a plane, and where on the normal vector you want to be, and then draw on that plane. In the pgfmanual (3.1.6a section 40.3) they do this in the scope
environment. The problem with this is that you cannot then draw outside the plane.
So I was wondering if there was some way to select a plane for commands like circle
, arc
, and rectangle
without entering a scope. The idea is that I would like to integrate these commands into a larger draw or fill command, for example by changing the coordinate system in the middle of a path:
\draw (0,0,0) -- ++(1,0,0) arc [yzplane at x=1, start angle=0, end angle = 180, radius=1] -- cycle;
My concrete problem is shown below. I have placed a circle on the yz
plane, and I want that to be the circle of a cone. I can then draw lines to the edges of this circle, but I cannot figure out how to shade it in.
Below you see my attempt at getting this circle shaded, but as you can see, it's placing the arc
in the xy
plane instead of the yz
plane.
Is there a way to get around this using the 3d
tikzlibrary? Is there away to get around it using tikz-3dplot
?
\documentclass{standalone}
\usepackage\[T1\]{fontenc}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{3d,calc,positioning}
\begin{document}
\begin{tikzpicture}\[z={(90:10mm)},x={(190:10mm)},y ={(-45:10mm)}\]
\def\circleplace{-2};
\def\circleSize{0.4}
\coordinate(coneTop) at (0,0,0);
\begin{scope}\[canvas is yz plane at x=\circleplace\]
\draw (0,0) circle (\circleSize);
\draw\[thick, dashed\] (135:\circleSize) arc \[start angle = 135, end angle = 315, radius=\circleSize\];
\end{scope}
\filldraw\[fill = red, fill opacity = 0.2\] (coneTop) -- (\circleplace,{\circleSize*cos(135)},{\circleSize*sin(135)}) arc \[start angle= 135, delta angle = 180, radius = 0.4\] -- cycle;
\draw\[dashed\] (\circleplace,{\circleSize*cos(135)},{\circleSize*sin(135)}) arc \[start angle= 135, delta angle = -180, radius = 0.4\];
\draw (coneTop) -- (\circleplace,{\circleSize*cos(135)},{\circleSize*sin(135)});
\draw (coneTop) -- (\circleplace,{\circleSize*cos(315)},{\circleSize*sin(315)});
\draw (1,0,0) -- ++(1,0,0) node\[anchor=south\]{$x$};
\draw (1,0,0) -- ++(0,1,0) node\[anchor=south\]{$y$};
\draw (1,0,0) -- ++(0,0,1) node\[anchor=south\]{$z$};
\end{tikzpicture}
\end{document}