0

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}

enter image description here

1

What you want to achieve can be done by using symbolic coordinates. You can access them from within the scope that brings you in the plane.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}[z={(90:10mm)},x={(190:10mm)},y ={(-45:10mm)},line cap=round,line join=round]
 \path (0,0,0) coordinate (O) (1,0,0) coordinate (X);
 \begin{scope}[canvas is yz plane at x=0]
  \draw (O) -- (X) arc[start angle=0, end angle = 180, radius=1] -- cycle;
 \end{scope}
\end{tikzpicture}
\end{document}

Notice that you can change the coordinate systems in a path.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}[z={(90:10mm)},x={(190:10mm)},y ={(-45:10mm)},line cap=round,line join=round]
 \draw (0,0,0) -- ++(1,0,0) [canvas is yz plane at x=0]
 arc[start angle=0, end angle = 180, radius=1] -- cycle;
\end{tikzpicture}
\end{document}

There are situations in which you do not want to have the projections that come with the 3d library's styles, in which case you can set up your own [yzplane] that can gets injected in a path.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}[z={(90:10mm)},x={(190:10mm)},y ={(-45:10mm)},line cap=round,line join=round]
 \path[overlay] (0,0,0) coordinate (O) (1,0,0) coordinate (ex)
  (0,1,0) coordinate (ey) (0,0,1) coordinate (ez);
 \tikzset{yz plane/.style={x={(ey)},y={(ez)}}} 
 \draw (0,0,0) -- ++(1,0,0) [yz plane]
 arc[start angle=0, end angle = 180, radius=1] -- cycle;
\end{tikzpicture}
\end{document}

This means that when using tikz-3dplot you can insert [tdplot_main_coords] or [tdplot_screen_coords], say, within a path to switch to a new coordinate system in the middle of a path.

4
  • Thanks a lot, this was really helpful ;-) Now I like 3d again 8-) If I want to draw more in 3d space after [yz plane] should I simply define \tikzset{xyz space/.style={x={(ex)},y={(ey)},z={(ez)}}} and call [xyz space] before running the next draw command? – Thorbjørn E. K. Christensen Nov 13 '20 at 18:08
  • 1
    @ThorbjørnE.K.Christensen Yes, precisely. Please note that tikz-3dplot has tdplot_rotated_coords for this, but it is sometimes more convenient to define (ex) and so on by hand. That is, if you know how to install orthographic projections, you do not necessarily need tikz-3dplot, you can also use the tpp library to install a view (without really using the perspective features). – user228539 Nov 13 '20 at 21:37
  • Hello again. It seems like the style [yz plane] does not work with the rectangle command while [canvas is yz plane at x=\x] does seem to work. Do you know why that is? – Thorbjørn E. K. Christensen Nov 17 '20 at 18:14
  • @ThorbjørnE.K.Christensen Yes. yz plane only transforms a coordinate system but not a projection. You can find \pgftransformtriangle in the 3d library which accomplishes the latter. – user228539 Nov 17 '20 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.