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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
|
%% tikz-3dplot_documentation.tex
%% Copyright 2010 Jeffrey D. Hein
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Jeffrey D. Hein.
%
% This work consists of the files tikz-3dplot.sty and tikz-3dplot_documentation.tex
%Description
%-----------
%tikz-3dplot_documentation.tex - documentation for tikz-3dplot.sty: package for plotting three dimensional axes and coordinates in TikZ. The user can specify orientation of the display, and also define rotated coordinate systems within the 3d display coordinate system.
%Created 2009-11-07 by Jeff Hein. Last updated: 2010-01-17
%----------------------------------------------------------
%Requirements
%------------
%This requires the tikz package.
%Update Notes
%------------
%As of Jan 17, 2010, this package has been renamed from ``3dplot'' to ``tikz-3dplot''.
\documentclass[10pt,letterpaper,oneside]{memoir}
\usepackage{tikz} %for TikZ graphics
\usepackage{tikz-3dplot} %for tikz-3dplot functionality
\usepackage{amsmath} %for align equation environment
\usepackage{url}
%\usepackage{hyperref}
\pgfrealjobname{tikz-3dplot_documentation}
\input{tikz-3dplot_documentation_figures.tex}
\newcommand{\tikzname}{Ti\emph{k}Z}
\newcommand{\tdplot}{\texttt{tikz-3dplot}}
\title{The \texttt{\tdplot} Package}
\author{Jeff Hein}
\newcommand{\tdplotlocation}{\url{http://www.ctan.org}}
\settocdepth{subsection}
\setsecnumdepth{subsection}
\maxsecnumdepth{subsection}
\settocdepth{subsection}
\maxtocdepth{subsection}
%**************** Example Box *********************
\definecolor{shadecolor}{rgb}{0.90,0.90,0.90}
%this defines an environment for presenting code in an indented, shaded, verbatim, multipage region. Requires framed, alltt, and color environments, and \definecolor{shadecolor}{rgb}{0.90,0.90,0.90}
%this sets the verbatim font and size, based on the memoir class usage
\setverbatimfont{\normalfont\ttfamily\footnotesize}
%this turns tabs on in the verbatim environment
\tabson[4]
%this sets the frequency of line numbers displayed in a boxedverbatim environment
%\linenumberfrequency{1}
%this sets the font size of line numbers in a boxedverbatim environment
\linenumberfont{\normalfont\ttfamily\tiny}
%this positions line numbers outside the box of a boxedverbatim environment
%\bvnumbersoutside
%this turns off the box of a boxedverbatim environment
\nobvbox
\begin{document}
\frontmatter
\pagestyle{empty}
\maketitle
\begin{figure}[h]
\begin{center}
\tdplotmainfig
\threedsurfaceplot
\threedalphabetagamma
%A 3d coordinate system rendered in \tikzname using the \tdplot\ package. The user can specify the display perspective by specifying angles $\theta_d$ and $\phi_d$, which rotate the coordinate frame from the ``standard'' display position where $x$ points to the right, $y$ points up.
\end{center}
\end{figure}
\cleardoublepage
{
Document Version History
\begin{description}
\item[2009-11-09] Initial release
\item[2009-11-21] Added spherical polar parametric surface plotting functionality with the \verb|\tdplotsphericalsurfaceplot| command.
\item[2009-12-04] Touched up on a few drawing issues in \verb|\tdplotsphericalsurfaceplot|, and added the \verb|\tdplotshowargcolorguide| command.
\item[2010-01-17] Changed package name from \texttt{3dplot} to \texttt{\tdplot}, and updated document accordingly.
\end{description}
\vfill
\parindent=0pt
Copyright 2009 by Jeff Hein
\medskip
Permission is granted to distribute and/or modify \emph{both
the documentation and the code} under the conditions of the LaTeX
Project Public License, either version 1.3 of this license or (at
your option) any later version. The latest version of this license is in
http://www.latex-project.org/lppl.txt
\clearpage
}
%copyright page, ripped from PGF manual
%{
% \vbox{}
% %\vskip0pt plus 1fill
% %Für meinen Vater, damit er noch viele schöne \TeX-Graphiken
% erschaffen kann.
% %\vskip1em
% %\hfill\emph{Till}
% \vskip0pt plus 3fill
%
% \parindent=0pt
% Copyright 2009 by Jeff Hein
%
% \medskip
% Permission is granted to copy, distribute and/or modify \emph{the documentation}
% under the terms of the \textsc{gnu} Free Documentation License, Version 1.2
% or any later version published by the Free Software Foundation;
% with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
% %A copy of the license is included in the section entitled \textsc{gnu}
% Free Documentation License.
%
% \medskip
% Permission is granted to copy, distribute and/or modify \emph{the
% code of the package} under the terms of the \textsc{gnu} Public License, Version 2
% or any later version published by the Free Software Foundation.
% %A copy of the license is included in the section entitled \textsc{gnu}
% Public License.
%
% \medskip
% Permission is also granted to distribute and/or modify \emph{both
% the documentation and the code} under the conditions of the LaTeX
% Project Public License, either version 1.3 of this license or (at
% your option) any later version. %A copy of the license is included in
% the section entitled \LaTeX\ Project Public License.
%
% \vbox{}
% \clearpage
%}
\pagenumbering{roman}
\tableofcontents
\cleardoublepage
\pagenumbering{arabic}
\mainmatter
\chapter{Introduction}\label{cha:intro}
\section{Overview of the \tdplot\ Package}
The \tdplot\ package offers commands and coordinate tranformation styles for \tikzname, providing relatively straightforward tools to draw three-dimensional coordinate systems and simple three-dimensional diagrams. The package is currently in its infancy, and is subject to change. Comments or suggetions are encouraged.
This document describes the basics of the \tdplot\ package and provides information about the various available commands. Examples are given where possible.
\subsection{What \tdplot\ is}
\tdplot\ provides commands to easily specify coordinate transformations for \tikzname, allowing for relatively easy plotting. I needed to draw accurate 3d vector images for a physics thesis, and this package was developed to meet this need.
In a recent addition, the \verb|\tdplotsphericalsurfaceplot| renders three dimensional surfaces, where both the radius and the surface fill hue can be expressed as user-specified functions of $\theta$ and $\phi$. This command is discussed in Section \ref{sec:spherical_surface_plot}.
\begin{figure}[h]
\begin{center}
\threedconventions
\end{center}
\caption{\tdplot\ coordinate and positive angle convention.}\label{fig:conventions}
\end{figure}
In \tdplot, a right-handed coordinate system convention is used. In addition, all positive angles constitute a right-hand screw sense of rotation (see Figure \ref{fig:conventions}). This means that a positive rotation about a given axis refers to a clockwise rotation when viewing along the direction the axis, or counterclockwise when viewing against the direction of the axis.
\subsection{What \tdplot\ is not}
\tdplot\ does not, in general, consider polygons, surfaces, or object opacity. The one exception is the \verb|\tdplotsphericalsurfaceplot| command, specifically designed to render spherical polar surfaces. The \verb|\tdplotsphericalsurfaceplot| command is discussed in Section \ref{sec:spherical_surface_plot}.
Tools like Sketch by Gene Ressler are better suited for more rigorous surface rendering. These can be found at \url{http://www.frontiernet.net/~eugene.ressler/}
\subsection{Similar Work}
To my knowledge, there is no other package available which allows straightforward rendering of 3d coordinates in \tikzname, directly in a \LaTeX\ document. Since this project is in its infancy, this may be subject to change based on feedback.
\subsubsection{Sketch}
The Sketch project can provide three-dimensional rendering of axes, points, and lines, but (as far as I understand the program) cannot draw arcs without using a series of line segments. Further, Sketch requires an external program to render the image, while \tdplot\ can be developed and maintained right in a \LaTeX\ document.
\subsubsection{\TeX ample.net}
There are a variety of \tikzname\ examples listed at \url{http://www.texample.net/tikz/examples}. Some of these examples gave me inspiration to make this package. Some examples of note include the following:
\begin{itemize}
\item 3D cone
\begin{description}
\item[Author:] Eugene Ressler
\item[url:] \url{http://www.texample.net/tikz/examples/3d-cone/}
\item[Notes:] This demonstrates the use of Sketch in TikZ figures.
\end{description}
\item Annotated 3D box
\begin{description}
\item[Author] Alain Matthes
\item[url] \url{http://www.texample.net/tikz/examples/annotated-3d-box/}
\item[Notes] This example demonstrates the direct use of coordinate transformations, as well as performing math directly within coordinates.
\end{description}
\item Cluster of atoms
\begin{description}
\item[Author] Agustin E. Bolzan
\item[url] \url{http://www.texample.net/tikz/examples/clusters-of-atoms/}
\item[Notes] This uses shifts and slants rather than rotations to render an isometric look.
\end{description}
\item Plane partition
\begin{description}
\item[Author] Jang Soo Kim
\item[url] \url{http://www.texample.net/tikz/examples/plane-partition/}
\item[Notes] This example draws solid surfaces with coordinate axes defined by rotations around the \tikzname\ standard coordinate frame.
\end{description}
\item Spherical and cartesian grids
\begin{description}
\item[Author] Marco Miani
\item[url] \url{http://www.texample.net/tikz/examples/spherical-and-cartesian-grids/}
\item[Notes] This example renders arcs and lines in three dimensions using explicit calculations. It takes into account the opacity of the spherical example, by showing hidden lines behind the sphere as dashed lines.
\end{description}
\item Stereographic and cylindrical map projections
\begin{description}
\item[Author] Thomas M. Trzeciak
\item[url] \url{http://www.texample.net/tikz/examples/map-projections/}
\item[Notes] This example illustrates the use of coordinate transformations to draw planes and arcs for spherical coordinates.
\end{description}
\end{itemize}
\section{Installing the \tdplot\ Package}
Get a copy of \tdplot\ from \tdplotlocation. Place the style file in the same directory as your \LaTeX\ project. In your preamble, add the following line:
%
\begin{shaded}
\begin{verbatim}
\include{tikz-3dplot}
\end{verbatim}
\end{shaded}
Make sure this line is written after all other required packages.
\subsection{\tdplot\ Requirements}
To use this package, the following other packages must be loaded in the preamble first:
\begin{itemize}
\item \tikzname
\item \texttt{ifthen} (for the \texttt{tdplotsphericalsurfaceplot} command)
\end{itemize}
\subsection{\tdplot\ Package Options}
Currently there are no options available for the \tdplot\ package.
\section{Using the \tdplot\ Package}
\tdplot\ provides styles and commands which are useful in a \texttt{tikzpicture} environment. These commands and styles are described in Chapter \ref{cha:using_tdplot}.
\chapter{Overview of 3d in \tdplot}\label{cha:overview3d}
\section{\tikzname\ 3d Plotting} \label{sec:tikzplotting}
When setting up a tikzpicture or a drawing style, the $x$, $y$, and $z$ axes can be specified directly in terms of the original coordinate system. The following example shows how a \texttt{tikzpicture} environment can be configured to use customized axes.
\begin{shaded}
\begin{verbatim}
\begin{tikzpicture}[%
x={(\raarot cm,\rbarot cm)},%
y={(\rabrot cm, \rbbrot cm)},%
z={(\racrot, \rbcrot cm)}]
\end{verbatim}
\end{shaded}
In this example, the terms \verb|\raarot| and so on specify how the coordinates are represented in the original \tikzname\ coordinate system, and are calculated by the \tdplot\ package. Note that units are explicitly required so \tikzname\ understands that these are absolute coordinates, not scales on the existing axis. See the PGF manual Version 2.00, section 21.2 on pages 217-218 for details on \tikzname\ coordinate transformations.
\section{The \tdplot\ Main Coordinate System}\label{sec:main_theory}
\tdplot\ offers two coordinate systems, namely the \emph{main} coordinate system $(x,y,z)$, and the \emph{rotated} coordinate system $(x',y',z')$. The latter system is described in Section \ref{sec:rotated_theory}.
As the name suggests, the main coordinate system provides a user-specified transformation to render 3d points in a \texttt{tikzpicture} environment. The orientation of the main coordinate system is defined by the angles $\theta_{d}$ and $\phi_{d}$. In the unrotated ($\theta_{d} = \phi_{d} = 0$) position, the $xy$ plane of the main coordinate system coincides with the default orientation for a \texttt{tikzpicture} environment, while $z$ points ``out of the page''.
%
The coordinate system is positioned by the following operations:
%
\begin{itemize}
\item Rotate the coordinate system about the body $x$ axis by the amount $\theta_d$, and
\item Rotate the coordinate system about the (rotated) body $z$ axis by the amount $\phi_d$.
\end{itemize}
In this rotation sense, the $z$ axis will always point in the vertical page direction. This transformation is given by the rotation matrix $R_d(\theta_d,\phi_d)$, as
%
\begin{align}\begin{split}
R^d(\theta_d,\phi_d) &= R^{z'}(\phi_d)R^{x}(\theta_d)\\
&= \begin{pmatrix}
\cos\phi_d & -\sin\phi_d & 0\\
\sin\phi_d & \cos\phi_d & 0\\
0 & 0 & 1
\end{pmatrix}
\begin{pmatrix}
1 & 0 & 0\\
0 & \cos\theta_d & -\sin\theta_d\\
0 & \sin\theta_d & \cos\theta_d\\
\end{pmatrix}\\
&= \begin{pmatrix}
\cos\phi_d & \sin\phi_d & 0\\
-\cos\theta_d\sin\phi_d & \cos\theta_d\cos\phi_d & -\sin\theta_d\\
\sin\theta_d\sin\phi_d & -\sin\theta_d\cos\phi_d & \cos\theta_d\\
\end{pmatrix}
\end{split}\end{align}
\begin{figure}[b]
\begin{center}
\threedcoord{0}{0}
\threedcoord{10}{50}
\threedcoord{30}{110}
\threedcoord{40}{150}
\threedcoord{60}{170}
\threedcoord{90}{180}
\end{center}
\caption{Examples of coordinate systems for various choices of $\theta_d$ and $\phi_d$.}
\end{figure}
Using this matrix, the \tikzname\ coordinate transformation can be applied as described in Section \ref{sec:tikzplotting} by the various matrix elements, as
%
\begin{align}\begin{split}
x &= (R^d_{1,1}, R^d_{2,1})\\
y &= (R^d_{1,2}, R^d_{2,2})\\
z &= (R^d_{1,3}, R^d_{2,3})
\end{split}\end{align}
Note that the third row of the rotation matrix is not needed for this transformation, since a screen coordinate is a 2d value. Once the transformed axes have been established, any 3d coordinate specified in \tikzname\ will adhere to the transformation, yeilding a 3d representation. Lines and nodes can readily be drawn by using these 3d coordinates.
This coordinate transformation is accessible through \tdplot\ using the command \texttt{tdplotsetmaincoords}, as described in Chapter \ref{cha:using_tdplot}.
\section{The \tdplot\ Rotated Coordinate System}\label{sec:rotated_theory}
Along with the main coordinate system, described in Section \ref{sec:main_theory}, \tdplot\ offers a \emph{rotated} coordinate system that is defined with respect to the main coordinate system. This system can be rotated to any position using Euler rotations, and can be translated so the origin of the rotated coordinate system sits on an arbitrary point in the main coordinate system.
Three rotations can be performed to give any arbitrary orientation of a rotated coordinate system. By convention, the following rotations are chosen:
%
\begin{itemize}
\item Rotate by angle $\gamma$ about the world $z$ axis,
\item Rotate by angle $\beta$ about the (unrotated) world $y$ axis, and
\item Rotate by angle $\alpha$ about the (unrotated) world $z$ axis.
\end{itemize}
These rotations are shown in Figure \ref{fig:euler_angles}.
\begin{figure}[h]
\begin{center}
\threedalphabetagamma
\end{center}
\caption{Positioning the rotated coordinate frame $(x', y', z')$ using Euler angles $(\alpha, \beta, \gamma)$.}\label{fig:euler_angles}
\end{figure}
This rotation matrix $D(\alpha,\beta,\gamma)$ is given by
%
\begin{align}\begin{split}
D(\alpha,\beta,\gamma) &= R^z(\alpha)R^y(\beta)R^z(\gamma)\\
&= \begin{pmatrix}
\cos\alpha & -\sin\alpha & 0\\
\sin\alpha & \cos\alpha & 0\\
0 & 0 & 1\\
\end{pmatrix}
\begin{pmatrix}
\cos\beta & 0 & \sin\beta \\
0 & 1 & 0 \\
-\sin\beta & 0 & \cos\beta\\
\end{pmatrix}
\begin{pmatrix}
\cos\gamma & -\sin\gamma & 0\\
\sin\gamma & \cos\gamma & 0\\
0 & 0 & 1\\
\end{pmatrix}\\
&= \begin{pmatrix}
\cos\alpha\cos\beta\cos\gamma - \sin\alpha\sin\gamma & -\cos\alpha\cos\beta\sin\gamma - \sin\alpha\cos\beta & \cos\alpha\sin\beta\\
\sin\alpha\cos\beta\cos\gamma + \cos\alpha\sin\gamma & -\sin\alpha\cos\beta\sin\gamma + \cos\alpha\cos\gamma & \sin\alpha\sin\beta\\
-\sin\beta\cos\gamma & \sin\beta\sin\gamma & \cos\beta
\end{pmatrix}
\end{split}\end{align}
To define the rotated coordinate frame, this rotation matrix is applied after rotation matrix $R^d(\theta_d,\phi_d)$ used to define the main coordinate frame. The full transformation for the rotated coordinate frame is then given by
%
\begin{align}
R'^d(\theta_d,\phi_d,\alpha,\beta,\gamma) &= D(\alpha,\beta,\gamma)R^d(\theta_d,\phi_d)
\end{align}
Using this matrix, the \tikzname\ coordinate transformation can be applied as described in Section \ref{sec:tikzplotting} by the various matrix elements, as
%
\begin{align}\begin{split}
x' &= (R'^d_{1,1}, R'^d_{2,1})\\
y' &= (R'^d_{1,2}, R'^d_{2,2})\\
z' &= (R'^d_{1,3}, R'^d_{2,3})
\end{split}\end{align}
This coordinate transformation is accessible through \tdplot\ using the command \texttt{tdplotsetrotatedcoords}, as described in Chapter \ref{cha:using_tdplot}.
\begin{figure}[h]
\begin{center}
\threedrotcoordsystem
\end{center}
\caption{The rotated coordinate frame $(x', y', z')$ displayed within the main coordinate frame $(x,y,z)$. Both are completely specified by user-defined angles: $(\theta_d, \phi_d)$ for the main coordinate frame, and $(\alpha, \beta, \gamma)$ for the rotated coordinate frame.}
\end{figure}
\section{Arcs in 3d, and the ``Theta Plane''}
Arcs can be drawn in \tikzname\ using commands described in the PGF manual Version 2.00, section 2.10 on pages 25-26. However, the arc commands accept 2d coordinates, and thus can only be drawn in the $xy$ plane.
To draw an arc in any position other than within the $xy$ plane of the main coordinate frame, the rotated coordinate frame must be used, where the $x'y'$ plane lies in the desired orientation within the main coordinate frame. Such an arc is needed, for example, when illustrating the polar angle $\theta$ of some vector. This $\theta$ arc exists in a plane which contains the $z$ axis, and is rotated about the $z$ axis by the angle $\phi$ from the $xz$ plane. For lack of a better name, this plane is referred to as the ``theta plane'' within a given coordinate system.
\begin{figure}[h]
\begin{center}
\threedthetaarc
\end{center}
\caption{Drawing arcs outside the $xy$ plane by using a rotated coordinate frame in the ``theta plane'' of the main coordinate frame.}
\end{figure}
As described in Chapter \ref{cha:using_tdplot}, \tdplot\ offers the commands \texttt{tdplotsetthetaplanecoords} and \texttt{tdplotsetrotatedthetaplanecoords} to easily configure the rotated coordinate frame to lie within the desired theta plane.
\chapter{Using the \tdplot\ Package} \label{cha:using_tdplot}
The \tdplot\ package was developed to handle the number crunching described in Chapter \ref{cha:overview3d}, and provide a relatively simple and straightforward frontend for users.
The main and rotated coordinate frames are configured by using commands described in Section \ref{sec:tdplotcommands}. These commands generate \tikzname\ styles which can be used either in defining the \texttt{tikzpicture} environment, or directly in any \tikzname\ command. The styles are described further in Section \ref{sec:tikzstyles}.
\section{The \tdplot\ \tikzname\ Styles} \label{sec:tikzstyles}
\subsection{\texttt{tdplot\_main\_coords}}
The \verb|tdplot_main_coords| style stores the coordinate transformation required to generate the main coordinate system. This style can either be used when the \texttt{tikzpicture} environment is started, or when an individual \tikzname\ plotting command is used.
\subsection{\texttt{tdplot\_rotated\_coords}}
The \verb|tdplot_rotated_coords| style stores the coordinate transformation (translation and rotation) required to generate the rotated coordinate system within the main coordinate system. This style can either be used when the \texttt{tikzpicture} environment is started, or when an individual \tikzname\ plotting command is used.
\subsection{\texttt{tdplot\_screen\_coords}}
The \verb|tdplot_screen_coords| style provides the standard, unrotated \tikzname\ coordinate frame. This is useful to escape out of the user-defined 3d coordinates used at the beginning of the \texttt{tikzpicture} environment, and place something on an absolute scale in the figure. Tables, legends, and captions contained within the same figure as a 3d plot can make use of this style.
\section{The \tdplot\ Commands} \label{sec:tdplotcommands}
This section lists the various commands provided by the \tdplot\ package. Examples are provided where it is useful.
\subsection{Coordinate Configuration Commands}
\subsubsection{\texttt{tdplotsetmaincoords}}
\begin{description}
\item[Description:] Generates the style \verb|tdplot_main_coords| which provides the coordinate transformation for the main coordinate frame, based on a user-specified orientation $(\theta_d,\phi_d)$. $\theta_d$ denotes the rotation around the $x$ axis, while $\phi_d$ denotes the rotation around the $z$ axis. Note that $(0,0)$ is the default orientation, where $x$ points right, $y$ points up, and $z$ points ``out of the page''.
\item[Syntax:] \verb|\tdplotsetmaincoords{| $\theta_d$ \verb|}{| $\phi_d$ \verb|}|
\item[Parameters:]~
\begin{description}
\item[$\theta_d$] The angle (in degrees) through which the coordinate frame is rotated about the $x$ axis.
\item[$\phi_d$] The angle (in degrees) through which the coordinate frame is rotated about the $z$ axis.
\end{description}
\item[Example:] ~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\end{tikzpicture}
\end{verbatim}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\end{tikzpicture}
\end{shaded}
\end{description}
\subsubsection{\texttt{tdplotsetrotatedcoords}}
\begin{description}
\item[Description:] Generates the style \verb|tdplot_rotated_coords| which provides the coordinate transformation for rotated coordinate frame within the current main coordinate frame, based on user-specified Euler angles $(\alpha,\beta,\gamma)$. Rotations use the $z(\alpha)y(\beta)z(\gamma)$ convention of Euler rotations, where the system is rotated by $\gamma$ about the $z$ axis, then $\beta$ about the (world) $y$ axis, and then $\alpha$ about the (world) $z$ axis.
\item[Syntax:] \verb|\tdplotsetrotatedcoords{|$\alpha$\verb|}{|$\beta$\verb|}{|$\gamma$\verb|}|
\item[Parameters:]~
\begin{description}
\item[$\alpha$] The angle (in degrees) through which the rotated frame is rotated about the world $z$ axis.
\item[$\beta$] The angle (in degrees) through which the rotated frame is rotated about the world $y$ axis.
\item[$\gamma$] The angle (in degrees) through which the rotated frame is rotated about the world $z$ axis.
\end{description}
\item[Example:] ~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetrotatedcoords{60}{40}{30}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(.7,0,0) node[anchor=north]{$x'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(0,.7,0) node[anchor=west]{$y'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(0,0,.7) node[anchor=south]{$z'$};
\end{tikzpicture}
\end{verbatim}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetrotatedcoords{60}{40}{30}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (.7,0,0) node[anchor=north]{$x'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (0,.7,0) node[anchor=west]{$y'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (0,0,.7) node[anchor=south]{$z'$};
\end{tikzpicture}
\end{shaded}
\end{description}
\subsubsection{\texttt{tdplotsetrotatedcoordsorigin}}
\begin{description}
\item[Description:] Sets the origin of the rotated coordinate system specified by \verb|tdplot_rotated_coords| using a user-defined point. This point can be either a literal or predefined point.
\item[Syntax:] \verb|\tdplotsetrotatedcoordsorigin{point}|
\item[Parameters:]~
\begin{description}
\item[\texttt{point}] A point predefined using the \tikzname\ \verb|\coordinate| command.
\end{description}
\item[Example:] ~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetrotatedcoords{60}{40}{30}
\coordinate (Shift) at (0.5,0.5,0.5);
\tdplotsetrotatedcoordsorigin{(Shift)}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(.7,0,0) node[anchor=north]{$x'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(0,.7,0) node[anchor=west]{$y'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(0,0,.7) node[anchor=south]{$z'$};
\end{tikzpicture}
\end{verbatim}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetrotatedcoords{60}{40}{30}
\coordinate (Shift) at (0.5,0.5,0.5);
\tdplotsetrotatedcoordsorigin{(Shift)}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (.7,0,0) node[anchor=north]{$x'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (0,.7,0) node[anchor=west]{$y'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (0,0,.7) node[anchor=south]{$z'$};
\end{tikzpicture}
\end{shaded}
\end{description}
\subsubsection{\texttt{tdplotresetrotatedcoordsorigin}}
\begin{description}
\item[Description:] Resets the origin of the rotated coordinate system back to the origin of the main coordinate system.
\item[Syntax:] \verb|\tdplotresetrotatedcoordsorigin|
\item[Parameters:] None
\end{description}
\subsubsection{\texttt{tdplotsetthetaplanecoords}}
\begin{description}
\item[Description:] Generates a rotated coordinate system such that the $x'y'$ plane is coplanar to a plane containing the polar angle $\theta$ projecting from the main coordinate system $z$ axis. This coordinate system is particularly useful for drawing within this ``theta plane'', as \tikzname\ draws arcs in the $xy$ plane. As with \texttt{tdplotsetrotatedcoords}, this coordinate system is accessible through the \verb|tdplot_rotated_coords| style. Note that any rotated coordinate frame offset previously set by \texttt{tdplotsetrotatedcoordsorigin} is automatically reset when this command is used.
\item[Syntax:] \verb|\tdplotsetthetaplanecoords{|$\phi$\verb|}|
\item[Parameters:]~
\begin{description}
\item[$\phi$] The angle (in degrees) through which the ``theta plane'' makes with the $xz$ plane of the main coordinate system.
\end{description}
\item[Example:]~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetcoord{P}{.8}{50}{70}
%draw a vector from origin to point (P)
\draw[-stealth,color=red] (O) -- (P);
%draw projection on xy plane, and a connecting line
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
\tdplotsetthetaplanecoords{70}
\draw[tdplot_rotated_coords,color=blue,thick,->] (0,0,0)
-- (.2,0,0) node[anchor=east]{$x'$};
\draw[tdplot_rotated_coords,color=blue,thick,->] (0,0,0)
-- (0,.2,0) node[anchor=north]{$y'$};
\draw[tdplot_rotated_coords,color=blue,thick,->] (0,0,0)
-- (0,0,.2) node[anchor=west]{$z'$};
\end{tikzpicture}
\end{verbatim}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetcoord{P}{.8}{50}{70}
\coordinate (O) at (0,0,0);
%draw a vector from origin to point (P)
\draw[-stealth,color=red] (O) -- (P);
%draw projection on xy plane, and a connecting line
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
\tdplotsetthetaplanecoords{70}
\draw[tdplot_rotated_coords,color=blue,thick,->] (0,0,0)
-- (.2,0,0) node[anchor=east]{$x'$};
\draw[tdplot_rotated_coords,color=blue,thick,->] (0,0,0)
-- (0,.2,0) node[anchor=north]{$y'$};
\draw[tdplot_rotated_coords,color=blue,thick,->] (0,0,0)
-- (0,0,.2) node[anchor=west]{$z'$};
\end{tikzpicture}
\end{shaded}
\end{description}
\subsubsection{\texttt{tdplotsetrotatedthetaplanecoords}}
\begin{description}
\item[Description:] Just like \texttt{tdplotsetthetaplanecoords}, except this works for the rotated coordinate system. Generates a rotated coordinate system such that the $x'-y'$ plane is coplanar to a plane containing the polar angle $\theta'$ projecting from the current rotated coordinate system $z'$ axis. Note that the current rotated coordinate system is overwritten by this theta plane coordinate system after the command is completed.
\item[Syntax:] \verb|\tdplotsetrotatedthetaplanecoords{|$\phi'$\verb|}|
\item[Parameters:]~
\begin{description}
\item[$\phi'$] The angle (in degrees) through which the ``theta plane'' makes with the $x'-z'$ plane of the current rotated coordinate system.
\end{description}
\item[Example:]~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\coordinate (Shift) at (2,2,2);
\tdplotsetrotatedcoords{-20}{10}{0}
\tdplotsetrotatedcoordsorigin{(Shift)}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0)
-- (1,0,0) node[anchor=south east]{$x'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0)
-- (0,1,0) node[anchor=west]{$y'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0)
-- (0,0,1) node[anchor=south]{$z'$};
\tdplotsetrotatedthetaplanecoords{30}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0)
-- (.5,0,0) node[anchor=south east]{$x''$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0)
-- (0,.5,0) node[anchor=west]{$y''$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0)
-- (0,0,.5) node[anchor=south]{$z''$};
\end{tikzpicture}
\end{verbatim}
\ifpdf
\beginpgfgraphicnamed{Figures/exampleshowargcolorguide}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\coordinate (Shift) at (2,2,2);
\tdplotsetrotatedcoords{-20}{10}{0}
\tdplotsetrotatedcoordsorigin{(Shift)}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (1,0,0) node[anchor=south east]{$x'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (0,1,0) node[anchor=west]{$y'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z'$};
\tdplotsetrotatedthetaplanecoords{30}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (.5,0,0) node[anchor=south east]{$x''$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (0,.5,0) node[anchor=west]{$y''$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) -- (0,0,.5) node[anchor=south]{$z''$};
\end{tikzpicture}
\endpgfgraphicnamed
\fi
\end{shaded}
\end{description}
\subsection{Point Calculation Commands}
\subsubsection{\texttt{tdplotsetcoord}}
\begin{description}
\item[Description:] Generates a coordinate of specified name, along with coordinates for the $x-$, $y-$, $z-$, $xy-$, $xz-$, and $yz-$ projections of the coordinate, based on user-specified spherical coordinates. Note that this coordinate only works in the main coordinate system. All points in the rotated coordinate system must be specified as literal points.
\item[Syntax:] \verb|\tdplotsetcoord{point}{|$r$\verb|}{|$\theta$\verb|}{|$\phi$\verb|}|
\item[Parameters:]~
\begin{description}
\item[\texttt{point}] The name of the point to be assigned. Note that the $()$ parentheses must be excluded.
\end{description}
\item[Example:] ~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[scale=2,tdplot_main_coords]
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{.8}{55}{60}
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\draw[-stealth,color=red] (O) -- (P);
\draw[dashed, color=red] (O) -- (Px);
\draw[dashed, color=red] (O) -- (Py);
\draw[dashed, color=red] (O) -- (Pz);
\draw[dashed, color=red] (Px) -- (Pxy);
\draw[dashed, color=red] (Py) -- (Pxy);
\draw[dashed, color=red] (Px) -- (Pxz);
\draw[dashed, color=red] (Pz) -- (Pxz);
\draw[dashed, color=red] (Py) -- (Pyz);
\draw[dashed, color=red] (Pz) -- (Pyz);
\draw[dashed, color=red] (Pxy) -- (P);
\draw[dashed, color=red] (Pxz) -- (P);
\draw[dashed, color=red] (Pyz) -- (P);
\end{tikzpicture}
\end{verbatim}
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[scale=2,tdplot_main_coords]
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{.8}{55}{60}
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\draw[-stealth,color=red] (O) -- (P);
\draw[dashed, color=red] (O) -- (Px);
\draw[dashed, color=red] (O) -- (Py);
\draw[dashed, color=red] (O) -- (Pz);
\draw[dashed, color=red] (Px) -- (Pxy);
\draw[dashed, color=red] (Py) -- (Pxy);
\draw[dashed, color=red] (Px) -- (Pxz);
\draw[dashed, color=red] (Pz) -- (Pxz);
\draw[dashed, color=red] (Py) -- (Pyz);
\draw[dashed, color=red] (Pz) -- (Pyz);
\draw[dashed, color=red] (Pxy) -- (P);
\draw[dashed, color=red] (Pxz) -- (P);
\draw[dashed, color=red] (Pyz) -- (P);
\end{tikzpicture}
\end{shaded}
\end{description}
\subsection{Drawing Commands}
Along with all the conventional \tikzname\ drawing commands, the following \tdplot\ commands can be used.
\subsubsection{\texttt{tdplotdrawarc}}
\begin{description}
\item[Description:] Draws an arc in the $xy$ (or optionally $x'y'$) plane starting from the specified polar angle $\phi$, of specified radius and angular length, at specified center point, and labels the arc with specified node text and options. By default, draws in the main coordinate frame, but can draw in the rotated coordinate frame by specifying \verb|tdplot_rotated_coords| in the option field.
\item[Syntax:] \verb|\tdplotdrawarc[coordinate system, draw styles]{center}{r}|\\\verb|{angle start}{angle end}{label options}{label}|
\item[Parameters:]~
\begin{description}
\item[(\textit{Optional}) coordinate system,draw styles] Optional argument containing the name of the coordinate system to use (default is main coordinate system), and any optional draw styles.
\item[center] Center point through which to draw the arc. If using the rotated coordinate system, this must be a literal value.
\item[angle start] the initial angle (in degrees) through which to draw. 0 points along the $x$ (or $x'$) axis.
\item[angle end] the final angle (in degrees) through which to draw.
\item[label options] any style options for a \tikzname \verb|\node| object. If none, make sure to leave a blank delimiter \verb|{}| in its place.
\item[label] any text for the \tikzname\ \verb|\node| which appears at the center of the arc. If none, make sure to leave a blank delimiter \verb|{}| in its place.
\end{description}
\item[Example:]~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{60}{110}
%
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{30}
\pgfmathsetmacro{\phivec}{60}
%
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\coordinate (O) at (0,0,0);
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\draw[-stealth,color=red] (O) -- (P);
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
\tdplotdrawarc{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
\tdplotsetthetaplanecoords{\phivec}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{0}%
{\thetavec}{anchor=south west}{$\theta$}
\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
\draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
\tdplotsetrotatedcoords{\phivec}{\thetavec}{0}
\tdplotsetrotatedcoordsorigin{(P)}
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (.5,0,0) node[anchor=north west]{$x'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (0,.5,0) node[anchor=west]{$y'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (0,0,.5) node[anchor=south]{$z'$};
\draw[-stealth,color=blue,tdplot_rotated_coords] (0,0,0) -- (.2,.2,.2);
\draw[dashed,color=blue,tdplot_rotated_coords] (0,0,0) -- (.2,.2,0);
\draw[dashed,color=blue,tdplot_rotated_coords] (.2,.2,0) -- (.2,.2,.2);
\tdplotdrawarc[tdplot_rotated_coords,color=blue]{(0,0,0)}{0.2}{0}%
{45}{anchor=north west,color=black}{$\phi'$}
\tdplotsetrotatedthetaplanecoords{45}
\tdplotdrawarc[tdplot_rotated_coords,color=blue]{(0,0,0)}{0.2}{0}%
{55}{anchor=south west,color=black}{$\theta'$}
\end{tikzpicture}
\end{verbatim}
\tdplotsetmaincoords{60}{110}
%
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{30}
\pgfmathsetmacro{\phivec}{60}
%
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\coordinate (O) at (0,0,0);
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\draw[-stealth,color=red] (O) -- (P);
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
\tdplotdrawarc{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
\tdplotsetthetaplanecoords{\phivec}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
\draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
\tdplotsetrotatedcoords{\phivec}{\thetavec}{0}
\tdplotsetrotatedcoordsorigin{(P)}
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (.5,0,0) node[anchor=north west]{$x'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (0,.5,0) node[anchor=west]{$y'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (0,0,.5) node[anchor=south]{$z'$};
\draw[-stealth,color=blue,tdplot_rotated_coords] (0,0,0) -- (.2,.2,.2);
\draw[dashed,color=blue,tdplot_rotated_coords] (0,0,0) -- (.2,.2,0);
\draw[dashed,color=blue,tdplot_rotated_coords] (.2,.2,0) -- (.2,.2,.2);
\tdplotdrawarc[tdplot_rotated_coords,color=blue]{(0,0,0)}{0.2}{0}{45}{anchor=north west,color=black}{$\phi'$}
\tdplotsetrotatedthetaplanecoords{45}
\tdplotdrawarc[tdplot_rotated_coords,color=blue]{(0,0,0)}{0.2}{0}{55}{anchor=south west,color=black}{$\theta'$}
\end{tikzpicture}
\end{shaded}
\end{description}
%make more!
%\subsubsection{}
%\begin{description}
% \item[Description:]
% \item[Syntax:]
% \item[Parameters:]
% \begin{description}
% \item[]
% \end{description}
%\end{description}
\subsection{The \texttt{tdplotsphericalsurfaceplot} Command}\label{sec:spherical_surface_plot}
The \verb|\tdplotsphericalsurfaceplot| command is quite complicated, and it seemed appropriate to occupy its own section. This command was developed to provide a method of rendering complex polar functions, $z = z(\theta,\phi)$, where the magnitude of the function is expressed by the radius, and the phase of the function is expressed by the hue.
\begin{align}\begin{split}
r &= \left|z(\theta,\phi)\right|\\
hue &= \mathrm{Arg}\left[z(\theta,\phi)\right]
\end{split}\end{align}
\subsubsection{How \texttt{tdplotsphericalsurfaceplot} Works}
To achieve the illusion of 3d surface with proper depth perception, the \tdplot\ package divides the drawing task into smaller sections. This division provides a cheap and dirty way of ensuring the surface on the far side of the viewing perspective is drawn first, ensuring proper opacity and object occlusion.
For a given perspective assigned by the main coordinate frame, a ``view orientation'' can be defined, giving the angles $(\theta_{view},\phi_{view})$ that describe the orientation of the view. These angles determine how to dubdivide the surface rendering process. The following divisions are made:
%
\begin{itemize}
\item Divide the surface into ``front'' and ``back'', where the back is drawn before the front.
\item Subdivide into ``left'' and ``right''
\item Subdivide further into ''top'' and ''bottom''
\end{itemize}
The entire back half is drawn before the front front half. For each half, the entire left or right side is drawn. For each side, the theta angles are drawn for each angle of phi. When on the back half, the theta angle is swept from $\theta_{view}$ toward the poles. When on the front half, the theta angle is swept from the poles toward $\theta_{view}$.
To improve the illusion of proper depth perception, a set of commands can be specified to render the $x$, $y$, and $z$ axis. While drawing the surface, the user-specified instructions is performed at the appropriate time, ensuring the axes pass through the surface of the object in an expected manner.
\subsubsection{Using \texttt{tdplotsphericalsurfaceplot}}
\begin{description}
\item[Description:] Draws a user-specified spherical polar function, with user-specified fill hues. Angular range to be displayed is specified with the \verb|\tdplotsetpolarplotrange| command.
\item[Syntax:] \verb|\tdplotsphericalsurfaceplot[fill color style]{theta steps}{phi steps}{function}|\\\verb|{line color}{fill color}{x axis}{y axis}{z axis}|
\item[Parameters:]~
\begin{description}
\item[(\emph{Optional}) fill color style] Specifies whether \texttt{fill color} is a function of \verb|\tdplottheta| and \verb|\tdplotphi|, or a direct \tikzname\ color. Set to \texttt{parametricfill} to enable functional coloring.
\item[theta steps] The number of steps used to render the surface along the $\theta$ direction. For best results, this number should not be smaller than 12, and should be a factor of 360.
\item[phi steps] The number of steps used to render the surface along the $\phi$ direction. For best results, this number should not be smaller than 12, and should be a factor of 360.
\item[function] A mathematical expression, containing the variables \verb|\tdplottheta| and \verb|\tdplotphi|, used to define the radius of the surface for given angles. Note that the absolute value of the function is plotted.
\item[line color] \tikzname\ color expression for surface lines.
\item[fill color] When the option \textit{parametricfill} is used then this can be some mathematical expression containing \verb|\tdplottheta| and \verb|\tdplotphi|. If not, then this can be any \tikzname\ expression for color. Note that if the function specified by \texttt{function} is negative, a shift of 180 is applied to the color. Bonus points to anyone who can guess why I chose to do this! If you don't like it, then make sure \texttt{function} is always positive.
\item[x axis] Any draw commands used to render an $x$ axis.
\item[y axis] Any draw commands used to render an $y$ axis.
\item[z axis] Any draw commands used to render an $z$ axis.
\end{description}
\item[Example:]~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{70}{135}
\begin{tikzpicture}[scale=2,line join=bevel,tdplot_main_coords,%
fill opacity=.5]
\tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
{sin(\tdplottheta)*cos(\tdplottheta)}{black}{\tdplotphi}%
{\draw[color=black,thick,->] (0,0,0)
-- (1,0,0) node[anchor=north east]{$x$};}%
{\draw[color=black,thick,->] (0,0,0)
-- (0,1,0) node[anchor=north west]{$y$};}%
{\draw[color=black,thick,->] (0,0,0)
-- (0,0,1) node[anchor=south]{$z$};}%
\end{tikzpicture}
\begin{tikzpicture}[scale=2,line join=bevel,tdplot_main_coords,%
fill opacity=.7]
\tdplotsphericalsurfaceplot{72}{24}%
{0.5*cos(\tdplottheta)^2}{black}{red!80!black}%
{\draw[color=black,thick,->] (0,0,0)
-- (1,0,0) node[anchor=north east]{$x$};}%
{\draw[color=black,thick,->] (0,0,0)
-- (0,1,0) node[anchor=north west]{$y$};}%
{\draw[color=black,thick,->] (0,0,0)
-- (0,0,1) node[anchor=south]{$z$};}%
\end{tikzpicture}
\end{verbatim}
\ifpdf
\beginpgfgraphicnamed{Figures/examplesurfaceplot}
\tdplotsetmaincoords{70}{135}
\begin{tikzpicture}[scale=2,line join=bevel,tdplot_main_coords, fill opacity=.5]
\tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
{sin(\tdplottheta)*cos(\tdplottheta)}{black}{\tdplotphi}%
{\draw[color=black,thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};}%
{\draw[color=black,thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};}%
{\draw[color=black,thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};}%
\end{tikzpicture}
\begin{tikzpicture}[scale=2,line join=bevel,tdplot_main_coords, fill opacity=.7]
\tdplotsphericalsurfaceplot{72}{24}%
{0.5*cos(\tdplottheta)^2}{black}{red!80!black}%
{\draw[color=black,thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};}%
{\draw[color=black,thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};}%
{\draw[color=black,thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};}%
\end{tikzpicture}
\endpgfgraphicnamed
\fi
\end{shaded}
\end{description}
\subsubsection{The \texttt{tdplotsetpolarplotrange} Command}
\begin{description}
\item[Description:] Defines the range of angles to be displayed when using \verb|\tdplotsphericalsurfaceplot|
\item[Syntax:] \verb|\tdplotsetpolarplotrange{lowertheta}{uppertheta}{lowerphi}{upperphi}|
\item[Parameters:]~
\begin{description}
\item[lowertheta] The lower limit for \verb|\tdplottheta|, in degrees.
\item[uppertheta] The upper limit for \verb|\tdplottheta|, in degrees.
\item[lowerphi] The lower limit for \verb|\tdplotphi|, in degrees.
\item[upperphi] The upper limit for \verb|\tdplotphi|, in degrees.
\end{description}
\item[Example:]~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=2,line join=bevel,tdplot_main_coords,%
fill opacity=.5]
\tdplotsetpolarplotrange{90}{180}{180}{360}
\tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
{.5}{black}{\tdplotphi + 3*\tdplottheta}%
{\draw[color=black,thick,->] (0,0,0)
-- (1,0,0) node[anchor=north east]{$x$};}%
{\draw[color=black,thick,->] (0,0,0)
-- (0,1,0) node[anchor=north west]{$y$};}%
{\draw[color=black,thick,->] (0,0,0)
-- (0,0,1) node[anchor=south]{$z$};}%
\end{tikzpicture}
\end{verbatim}
\ifpdf
\beginpgfgraphicnamed{Figures/examplesurfaceplotrange}
\tdplotsetmaincoords{70}{135}
\begin{tikzpicture}[scale=2,line join=bevel,tdplot_main_coords, fill opacity=.5]
\tdplotsetpolarplotrange{90}{180}{180}{360}
\tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
{.5}{black}{\tdplotphi + 3*\tdplottheta}%
{\draw[color=black,thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};}%
{\draw[color=black,thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};}%
{\draw[color=black,thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};}%
\end{tikzpicture}
\endpgfgraphicnamed
\fi
\end{shaded}
\end{description}
\subsubsection{The \texttt{tdplotresetpolarplotrange} Command}
\begin{description}
\item[Description:] Resets the range of angles to the default full range when using \verb|\tdplotsphericalsurfaceplot|
\item[Syntax:] \verb|\tdplotresetpolarplotrange|
\end{description}
\subsubsection{The \texttt{tdplotshowargcolorguide} Command}
\begin{description}
\item[Description:] Draws a color guide table which associates the hue of a parametric polar plot with an angle. Guide is drawn at user-specified coordinates with user-specified size.
\item[Syntax:] \verb|\tdplotshowargcolorguide{x position}{y position}{x size}{y size}|
\item[Parameters:]~
\begin{description}
\item[x position] The x screen coordinate to place the lower-left corner of the guide.
\item[y position] The y screen coordinate to place the lower-left corner of the guide.
\item[x size] The width of the color guide.
\item[y size] The height of the color guide.
\end{description}
\item[Example:] ~
\begin{shaded}
\begin{verbatim}
\tdplotsetmaincoords{40}{0}
\begin{tikzpicture}[scale=2,line join=bevel,tdplot_main_coords,%
fill opacity=1]
\tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
{sqrt(15/2)/2*sin(\tdplottheta)^2}{black}%
{2*\tdplotphi - 6 * \tdplottheta}{}{}{}%
\tdplotshowargcolorguide{3}{-.2}{.1}{1}
\end{tikzpicture}
\end{verbatim}
\ifpdf
\beginpgfgraphicnamed{Figures/exampleshowargcolorguide}
\tdplotsetmaincoords{40}{0}
\begin{tikzpicture}[scale=2,line join=bevel,tdplot_main_coords, fill opacity=1]
\tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
{sqrt(15/2)/2*sin(\tdplottheta)^2}{black}{2*\tdplotphi - 6 * \tdplottheta}{}{}{}%
\tdplotshowargcolorguide{3}{-.2}{.1}{1}
\end{tikzpicture}
\endpgfgraphicnamed
\fi
\end{shaded}
\end{description}
\subsection{Miscellaneous Math Commands}
The following commands are used to streamline the \tdplot\ calculations in the background. There is generally no need to use these directly, but may be useful on their own for any desired calculations.
\subsubsection{\texttt{tdplotsinandcos}}
\begin{description}
\item[Description:] Determines the sine and cosine of the specified angle, and stores in specified macros.
\item[Syntax:] \verb|\tdplotsinandcos{sintheta}{costeta}{theta}|
\item[Parameters:]~
\begin{description}
\item[\texttt{sintheta}] A macro (eg. \verb|\sintheta|) to store the sine of \texttt{theta}.
\item[\texttt{costheta}] A macro (eg. \verb|\costheta|) to store the cosine of \texttt{theta}.
\item[\texttt{theta}] An angle (in degrees) to calculate. Can be a macro or literal value.
\end{description}
\end{description}
\subsubsection{\texttt{tdplotmult}}
\begin{description}
\item[Description:] Determines the product of two specified values, and stores the result in the specified macro.
\item[Syntax:] \verb|\tdplotmult{result}{multiplicand}{multiplicator}|
\item[Parameters:]~
\begin{description}
\item[\texttt{result}] A macro (eg. \verb|\result|) to store the product of \texttt{multiplicand * multiplicator}.
\item[\texttt{multiplicand}] The multiplicand of the product. Can be a macro or literal value.
\item[\texttt{multiplicator}] The multiplicator of the product. Can be a macro or literal value.
\end{description}
\end{description}
\subsubsection{\texttt{tdplotdiv}}
\begin{description}
\item[Description:] Determines the quotient of two specified values, and stores the result in the specified macro.
\item[Syntax:] \verb|\tdplotdiv{result}{dividend}{divisor}|
\item[Parameters:]~
\begin{description}
\item[\texttt{result}] A macro (eg. \verb|\result|) to store the quotient of \texttt{dividend / divisor}.
\item[\texttt{dividend}] The dividend of the quotient. Can be a macro or literal value.
\item[\texttt{divisor}] The divisor of the quotient. Can be a macro or literal value.
\end{description}
\end{description}
\chapter{Known Issues}
There are various issues that have been found while developing the \tdplot\ package. Some of these are currently open problems which will hopefully be resolved. Feedback and suggestions are welcome.
\section{Predefined Points Don't Work in Rotated Frame}
When a coordinate is defined using the \tikzname\ command \verb|\coordinate|, it will be transformed by the transformation specified at the beginning of the \texttt{tikzpicture} environment. These coordinates will not work for transformations applied at the actual \verb|\draw| command.
This problem seems to be inherant with \tikzname\ itself. By way of example, the following code is taken right from the PGF manual Version 2.00, section 21.2 on page 218:
\begin{shaded}
\begin{verbatim}
Case A:
%this one works fine using literal coordinates
\begin{tikzpicture}[smooth]
\draw plot coordinates{(1,0)(2,0.5)(3,0)(3,1)};
\draw[x={(0cm,1cm)},y={(1cm,0cm)},color=red]
plot coordinates{(1,0)(2,0.5)(3,0)(3,1)};
\end{tikzpicture}
Two distinct paths shown. All is good.
Case B:
%this one does not work using predefined coordinates
\begin{tikzpicture}[smooth]
\coordinate (A) at (1,0);
\coordinate (B) at (2,0.5);
\coordinate (C) at (3,0);
\coordinate (D) at (3,1);
\draw plot coordinates{(A)(B)(C)(D)};
\draw[x={(0cm,1cm)},y={(1cm,0cm)},color=red] plot coordinates{(A)(B)(C)(D)};
\end{tikzpicture}
Both paths draw overtop each other, and the coordinates are not transformed!
\end{verbatim}
Case A:
%this one works fine using literal coordinates
\begin{tikzpicture}[smooth]
\draw plot coordinates{(1,0)(2,0.5)(3,0)(3,1)};
\draw[x={(0cm,1cm)},y={(1cm,0cm)},color=red] plot coordinates{(1,0)(2,0.5)(3,0)(3,1)};
\end{tikzpicture}
Two distinct paths shown. All is good.
Case B:
%this one does not work using predefined coordinates
\begin{tikzpicture}[smooth]
\coordinate (A) at (1,0);
\coordinate (B) at (2,0.5);
\coordinate (C) at (3,0);
\coordinate (D) at (3,1);
\draw plot coordinates{(A)(B)(C)(D)};
\draw[x={(0cm,1cm)},y={(1cm,0cm)},color=red] plot coordinates{(A)(B)(C)(D)};
\end{tikzpicture}
Both paths draw overtop each other, and the coordinates are not transformed!
\end{shaded}
\section{\texttt{node} Command and \texttt{shift=(P)} Issues}
When placing a node in a shifted coordinate frame, the \verb|\node| command will not position properly. As a workaround, the \verb|\draw| command must be used to position the node. By way of example.
\begin{shaded}
\begin{verbatim}
Case A:
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\coordinate (P) at (3,3,3);
\tdplotsetrotatedcoords{0}{0}{0}
\tdplotsetrotatedcoordsorigin{(P)}
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (.5,0,0) node[anchor=north]{$x'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (0,.5,0) node[anchor=south west]{$y'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (0,0,.5) node[anchor=south east]{$z'$};
\node[tdplot_rotated_coords] at (30:.5){$\theta_{bad}$};
\draw[tdplot_rotated_coords] (0,0,0) + (30:.5) node{$\theta_{good}$};
\end{tikzpicture}
Here, the rotated coordinate frame is shifted by amount (P) within the main%
coordinate frame. The node labelled $\theta_{bad}$ does not accept any%
positioning coordinates.
Case B:
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
% \coordinate (P) at (3,3,3);
\tdplotsetrotatedcoords{0}{0}{0}
% \tdplotsetrotatedcoordsorigin{(P)}
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (.5,0,0) node[anchor=north]{$x'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (0,.5,0) node[anchor=south west]{$y'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0)
-- (0,0,.5) node[anchor=south east]{$z'$};
\node[tdplot_rotated_coords] at (30:.5){$\theta_{bad}$};
\draw[tdplot_rotated_coords] (0,0,0) + (30:.5) node{$\theta_{good}$};
\end{tikzpicture}
Here, the shift is removed from the rotated coordinate frame. The %
previously failing \verb|\node| command works properly.
\end{verbatim}
Case A:
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\coordinate (P) at (3,3,3);
\tdplotsetrotatedcoords{0}{0}{0}
\tdplotsetrotatedcoordsorigin{(P)}
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (.5,0,0) node[anchor=north]{$x'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (0,.5,0) node[anchor=south west]{$y'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (0,0,.5) node[anchor=south east]{$z'$};
\node[tdplot_rotated_coords] at (30:.5){$\theta_{bad}$};
\draw[tdplot_rotated_coords] (0,0,0) + (30:.5) node{$\theta_{good}$};
\end{tikzpicture}
Here, the rotated coordinate frame is shifted by amount (P) within the main coordinate frame. The node labelled $\theta_{bad}$ does not accept any positioning coordinates.
Case B:
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
% \coordinate (P) at (3,3,3);
\tdplotsetrotatedcoords{0}{0}{0}
% \tdplotsetrotatedcoordsorigin{(P)}
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (.5,0,0) node[anchor=north]{$x'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (0,.5,0) node[anchor=south west]{$y'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (0,0,.5) node[anchor=south east]{$z'$};
\node[tdplot_rotated_coords] at (30:.5){$\theta_{bad}$};
\draw[tdplot_rotated_coords] (0,0,0) + (30:.5) node{$\theta_{good}$};
\end{tikzpicture}
Here, the shift is removed from the rotated coordinate frame. The previously failing \verb|\node| command works properly.
\end{shaded}
\section{PGF \texttt{xyz spherical} Coordinate System}
I have recently heard about the \texttt{xyz spherical} coordinate system offered by PGF. Unfortunately, when I try to use it, I get compile errors. I haven't spent much time looking into it though, so I'm probably just doing something silly.
\begin{shaded}
\begin{verbatim}
\draw[-stealth,color=orange] (0,0,0)
-- (xyz spherical cs:radius=.5,longitude=60,latitude=120);
%this gives the following compile error using MikTeX 2.8:
% Undefined control sequence. <argument> \tikz@cs@radius.
\end{verbatim}
\end{shaded}
\chapter{TODO list}
This chapter contains notes and jots of ideas of things to do which can expand or improve the \tdplot package.
\begin{itemize}
\item Figure out how to work in a variable scope that doesn't interfere with other packages
\item Find a way to check if TikZ is loaded, and give a compile error if necessary
\item Find a way to use predefined coordinates in rotated or translated coordinate frames, instead of just literal coordinates
\item Generalize matrix math if such a package exists
\item Look into using TikZ spherical polar coordinates explicitly to streamline coordinate definitions
\end{itemize}
\end{document}
|