1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
% Copyright 2019 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
\section{Three Dimensional Drawing Library}
\begin{tikzlibrary}{3d}
This package provides some styles and options for drawing three dimensional
shapes.
\end{tikzlibrary}
\subsection{Coordinate Systems}
\begin{coordinatesystem}{xyz cylindrical}
The |xyz cylindrical| coordinate system allows to you specify a point in
terms of cylindrical coordinates, sometimes also referred to as cylindrical
polar coordinates or polar cylindrical coordinates. It is very similar to
the |canvas polar| and |xy polar| coordinate systems with the difference
that you provide an elevation over the $xy$-plane using the |z| key.
%
\begin{key}{/tikz/cs/angle=\meta{degrees} (initially 0)}
The angle of the coordinate interpreted in the ellipse whose axes are
the $x$-vector and the $y$-vector.
\end{key}
%
\begin{key}{/tikz/cs/radius=\meta{number} (initially 0)}
A factor by which the $x$-vector and $y$-vector are multiplied prior to
forming the ellipse.
\end{key}
%
\begin{key}{/tikz/cs/z=\meta{number} (initially 0)}
Factor by which the $z$-vector is multiplied.
\end{key}
%
\begin{codeexample}[preamble={\usetikzlibrary{3d}}]
\begin{tikzpicture}[->]
\draw (0,0,0) -- (xyz cylindrical cs:radius=1);
\draw (0,0,0) -- (xyz cylindrical cs:radius=1,angle=90);
\draw (0,0,0) -- (xyz cylindrical cs:z=1);
\end{tikzpicture}
\end{codeexample}
%
\end{coordinatesystem}
\begin{coordinatesystem}{xyz spherical}
The |xyz spherical| coordinate system allows you to specify a point in
terms of spherical coordinates.
%
\begin{key}{/tikz/cs/radius=\meta{number} (initially 0)}
Factor by which the $x$-, $y$-, and $z$-vector are multiplied.
\end{key}
%
\begin{key}{/tikz/cs/latitude=\meta{degrees} (initially 0)}
Angle of the coordinate between the $y$- and $z$-vector, measured from
the $y$-vector.
\end{key}
%
\begin{key}{/tikz/cs/longitude=\meta{degrees} (initially 0)}
Angle of the coordinate between the $x$- and $y$-vector, measured from
the $y$-vector.
\end{key}
%
\begin{key}{/tikz/cs/angle=\meta{degrees} (initially 0)}
Same as |longitude|.
\end{key}
%
\begin{codeexample}[preamble={\usetikzlibrary{3d}}]
\begin{tikzpicture}[->]
\draw (0,0,0) -- (xyz spherical cs:radius=1);
\draw (0,0,0) -- (xyz spherical cs:radius=1,latitude=90);
\draw (0,0,0) -- (xyz spherical cs:radius=1,longitude=90);
\end{tikzpicture}
\end{codeexample}
%
\end{coordinatesystem}
\subsection{Coordinate Planes}
Sometimes drawing with full three dimensional coordinates is not necessary and
it suffices to draw in two dimensions but in a different coordinate plane. The
following options help you to switch to a different plane.
\subsubsection{Switching to an arbitrary plane}
\begin{key}{/tikz/plane origin=\meta{point} (initially {(0,0)})}
Origin of the plane.
\end{key}
\begin{key}{/tikz/plane x=\meta{point} (initially {(1,0)})}
Unit vector of the $x$-direction in the new plane.
\end{key}
\begin{key}{/tikz/plane y=\meta{point} (initially {(0,1)})}
Unit vector of the $y$-direction in the new plane.
\end{key}
\begin{key}{/tikz/canvas is plane}
Perform the transformation into the new canvas plane using the units above.
Note that you have to set the units \emph{before} calling
|canvas is plane|.
%
\begin{codeexample}[preamble={\usetikzlibrary{3d}}]
\begin{tikzpicture}[
->,
plane x={(0.707,-0.707)},
plane y={(0.707,0.707)},
canvas is plane,
]
\draw (0,0) -- (1,0);
\draw (0,0) -- (0,1);
\end{tikzpicture}
\end{codeexample}
%
\end{key}
\subsubsection{Predefined planes}
\begin{key}{/tikz/canvas is xy plane at z=\meta{dimension}}
A plane with
%
\begin{itemize}
\item |plane origin={(0,0,|\meta{dimension}|)}|,
\item |plane x={(1,0,|\meta{dimension}|)}|, and
\item |plane y={(0,1,|\meta{dimension}|)}|.
\end{itemize}
\end{key}
\begin{key}{/tikz/canvas is yx plane at z=\meta{dimension}}
A plane with
%
\begin{itemize}
\item |plane origin={(0,0,|\meta{dimension}|)}|,
\item |plane x={(0,1,|\meta{dimension}|)}|, and
\item |plane y={(1,0,|\meta{dimension}|)}|.
\end{itemize}
\end{key}
\begin{key}{/tikz/canvas is xz plane at y=\meta{dimension}}
A plane with
%
\begin{itemize}
\item |plane origin={(0,|\meta{dimension}|,0)}|,
\item |plane x={(1,|\meta{dimension}|,0)}|, and
\item |plane y={(0,|\meta{dimension}|,1)}|.
\end{itemize}
\end{key}
\begin{key}{/tikz/canvas is zx plane at y=\meta{dimension}}
A plane with
%
\begin{itemize}
\item |plane origin={(0,|\meta{dimension}|,0)}|,
\item |plane x={(0,|\meta{dimension}|,1)}|, and
\item |plane y={(1,|\meta{dimension}|,0)}|.
\end{itemize}
\end{key}
\begin{key}{/tikz/canvas is yz plane at x=\meta{dimension}}
A plane with
%
\begin{itemize}
\item |plane origin={(|\meta{dimension}|,0,0)}|,
\item |plane x={(|\meta{dimension}|,1,0)}|, and
\item |plane y={(|\meta{dimension}|,0,1)}|.
\end{itemize}
\end{key}
\begin{key}{/tikz/canvas is zy plane at x=\meta{dimension}}
A plane with
%
\begin{itemize}
\item |plane origin={(|\meta{dimension}|,0,0)}|,
\item |plane x={(|\meta{dimension}|,0,1)}|, and
\item |plane y={(|\meta{dimension}|,1,0)}|.
\end{itemize}
\end{key}
\subsection{Examples}
\begin{codeexample}[preamble={\usetikzlibrary{3d}}]
\begin{tikzpicture}[z={(10:10mm)},x={(-45:5mm)}]
\def\wave{
\draw[fill,thick,fill opacity=.2]
(0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0)
sin (5,1) cos (6,0) sin (7,-1) cos (8,0)
sin (9,1) cos (10,0)sin (11,-1)cos (12,0);
\foreach \shift in {0,4,8}
{
\begin{scope}[xshift=\shift cm,thin]
\draw (.5,0) -- (0.5,0 |- 45:1cm);
\draw (1,0) -- (1,1);
\draw (1.5,0) -- (1.5,0 |- 45:1cm);
\draw (2.5,0) -- (2.5,0 |- -45:1cm);
\draw (3,0) -- (3,-1);
\draw (3.5,0) -- (3.5,0 |- -45:1cm);
\end{scope}
}
}
\begin{scope}[canvas is zy plane at x=0,fill=blue]
\wave
\node at (6,-1.5) [transform shape] {magnetic field};
\end{scope}
\begin{scope}[canvas is zx plane at y=0,fill=red]
\draw[help lines] (0,-2) grid (12,2);
\wave
\node at (6,1.5) [rotate=180,xscale=-1,transform shape] {electric field};
\end{scope}
\end{tikzpicture}
\end{codeexample}
\begin{codeexample}[preamble={\usetikzlibrary{3d}}]
\begin{tikzpicture}
\begin{scope}[canvas is zy plane at x=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is zx plane at y=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\end{tikzpicture}
\end{codeexample}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "pgfmanual-pdftex-version"
%%% End:
|