In Vas tikz-3dplot

For some time, I have developed the tikz-3dplot package, a LaTeX package which implements TikZ/PGF to render three-dimensional vector-based graphics in TikZ.

Recently, this package was submitted to CTAN, where other LaTeX users can easily access it and learn how to contact me to provide feedback. Up until now, the package development was documented on my personal blog. Recently, I have been receiving increased user feedback and suggestions for the continued development of this package. It is apparent that, through the help of this feedback, this package will continue to develop, and there will be more entries as time goes on. This dedicated blog has been created, since it seemed more appropriate to focus the tikz-3dplot package development in its own place.

~ by Jeff Hein on 2010/01/25.

12 Responses to “In Vas tikz-3dplot”

1. The documentation on CTAN does not have correct cross references. Perhaps another LaTeX run is needed.

• Thanks for the feedback. The 2010-01-17 version was not correctly compiled. I recently submitted an updated version (2010-01-24) which should be fixed. If you are referring to the newer one, could you please give an example where you are seeing incorrect references?

2. Thanks very much for creating tikz-3dplot. I’ve found it very useful for preparing lecture notes and technical documentation. I hope that you are able to continue developing it.

I’m a little confused about the text in the manual for specifying the rotated coordinate system. The manual states (page 7):

– Rotate by angle γ about the world z axis,
– Rotate by angle β about the (unrotated) world y axis, and
– Rotate by angle α about the (unrotated) world z axis.

My interpretation of this text is that the new coordinate axes are rotated around the original (unrotated) axes at each rotation. But the picture created from following code rotates the new axes around the new (rotated) axes (as I think it should).

 \tdplotsetmaincoords{60}{120} \begin{tikzpicture}[scale=2,tdplot_main_coords] \tdplotsetrotatedcoords{45.0}{0.0}{0.0} \draw[tdplot_rotated_coords,dashed,red] (0.25,0.25,0) -- (0.5,0.25,0) -- (0.5,0.5,0) -- (0.25,0.5,0) -- cycle; \draw[tdplot_rotated_coords,thick,->,color=red] (0,0,0) -- (1.5,0,0) node[below]{$x$}; \draw[tdplot_rotated_coords,thick,thick,->,color=red] (0,0,0) -- (0,1.5,0) node[right]{$y$}; \draw[tdplot_rotated_coords,thick,thick,->,color=red] (0,0,0) -- (0,0,1.5) node[above right]{$z$}; % draw the main coordinate system axes \draw[thick,->] (0,0,0) -- (1.5,0,0) node[below left]{$x$}; \draw[thick,->] (0,0,0) -- (0,1.5,0) node[below right]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,1.5) node[above]{$z$};

 \begin{scope}[xshift=2.5cm] \tdplotsetrotatedcoords{45.0}{90.0}{0.0} \draw[tdplot_rotated_coords,dashed,green] (0.25,0.25,0) -- (0.5,0.25,0) -- (0.5,0.5,0) -- (0.25,0.5,0) -- cycle; \draw[tdplot_rotated_coords,thick,->,color=green] (0,0,0) -- (1.5,0,0) node[below]{$x$}; \draw[tdplot_rotated_coords,thick,thick,->,color=green] (0,0,0) -- (0,1.5,0) node[right]{$y$}; \draw[tdplot_rotated_coords,thick,thick,->,color=green] (0,0,0) -- (0,0,1.5) node[below right]{$z$}; % draw the main coordinate system axes \draw[thick,->] (0,0,0) -- (1.5,0,0) node[below left]{$x$}; \draw[thick,->] (0,0,0) -- (0,1.5,0) node[below right]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,1.5) node[above]{$z$}; \end{scope} 

 \begin{scope}[xshift=5cm] \tdplotsetrotatedcoords{45.0}{90.0}{90.0} \draw[tdplot_rotated_coords,dashed,blue] (0.25,0.25,0) -- (0.5,0.25,0) -- (0.5,0.5,0) -- (0.25,0.5,0) -- cycle; \draw[tdplot_rotated_coords,thick,->,color=blue] (0,0,0) -- (1.5,0,0) node[right]{$x$}; \draw[tdplot_rotated_coords,thick,thick,->,color=blue] (0,0,0) -- (0,1.5,0) node[above right]{$y$}; \draw[tdplot_rotated_coords,thick,thick,->,color=blue] (0,0,0) -- (0,0,1.5) node[below right]{$z$}; % draw the main coordinate system axes \draw[thick,->] (0,0,0) -- (1.5,0,0) node[below left]{$x$}; \draw[thick,->] (0,0,0) -- (0,1.5,0) node[below right]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,1.5) node[above]{$z$}; \end{scope} \end{tikzpicture} 

The first rotation (red) rotates the x- and y-axes around the unrotated z-axis by 45 degrees. The second rotation (green), rotates the new (rotated) x- and z-axes around the new (rotated) y-axis by 90 degrees. The third rotation (blue) rotates the new (rotated) x- and y-axes around the new (rotated) z-axis by 90 degrees.

It seem to me that text (“(unrotated) world _ axis”) in the manual is confusing. Is it incorrect, or am I just interpreting it incorrectly?

Gordon

3. Hi Gordon,

Regarding your concern about the documentation, you would be correct if the rotations are performed as you describe them. But note that the order of rotations are not the same as the order of parameters in the definition of the \tdplotsetrotatedcoords command.

According to the documentation, this command takes three variables, in the order of alpha, beta, and gamma. The rotation is performed in the order of gamma, beta, then alpha, which is the opposite order that is shown in the command.

In your first graph, you rotate by 0 degrees about the (main) z axis, then 0 about the (main) y axis, and then 45 about the (main) z axis.

In your second graph, you rotate by 0 degrees about the (main) z axis, then 90 about the (main) y axis, and then 45 about the (main) z axis.

In your third graph, you rotate by 90 degrees about the (main) z axis, then 90 about the (main) y axis, and then 45 about the (main) z axis.

I seem to recall some proof from my undergraduate mechanics class that showed how a rotation (alpha, beta, gamma) about the main axes is equivalent to a rotation (gamma, beta, alpha) about the rotated axes.

I hope this clears things up!

Jeff

4. Ah! Thanks very much for clearing that up for me. I completely missed the order of rotations, but should have realized it from Equation 2.3.

I’ve never done a class on solid mechanics, so I didn’t know that rotation (alpha, beta, gamma) about the main axes is equivalent to a rotation (gamma, beta, alpha) about the rotated axes. That’s a nice piece of information to know.

5. In Section 4.3 of the manual, you mention that you hadn’t been able to use the (undocumented) 3D library xyz spherical coordinate system. It turns out the problem is that some code is missing from the 3D library. See this thread for the fix.

6. Thanks for the update. I’ll see if I can get it working, and add some notes to the documentation if I have any success.

• I’ve been playing around with the tikz spherical coordinate system, and I don’t understand what is going on in the following picture (maybe I’m doing something wrong). I’m using four different coordinate schemes to plot a circle in 3D space. The methods should all put the circle at the same point, but they don’t. The pgf commands method (adapted from the manual) and the undocumented 3D library (xyz spherical) put the circle in a different spot to the tikz-3dplot and rectangular coordinate methods.

Any idea what is going on?

 \documentclass[letterpaper,12pt]{article} \usepackage[x11names,rgb]{xcolor} \usepackage{tikz} \usepackage{tikz-3dplot} \usepackage{amsmath} \oddsidemargin 0in \evensidemargin 0in \topmargin 0in \headheight 0in \headsep 0in \textheight 9in \textwidth 6.5in

 % Use pgf commands for spherical coordinates \makeatletter \define@key{sphericalkeys}{radius}{\def\myradius{#1}} \define@key{sphericalkeys}{longitude}{\def\mylongitude{#1}} \define@key{sphericalkeys}{latitude}{\def\mylatitude{#1}} \tikzdeclarecoordinatesystem{spherical}% {% \setkeys{sphericalkeys}{#1}% \pgfpointspherical{\mylongitude}{\mylatitude}{\myradius} } % Use undocumneted tikz 3D library \usetikzlibrary{3d} % fix 3d library (http://groups.google.com/group/comp.text.tex/browse_thread/thread/ab6b859c9bb6eaab/60b3c671094d445c?lnk=gst&q=3d+tikz#60b3c671094d445c) \makeatletter \pgfset{/tikz/cs/radius/.store in=\tikz@cs@radius} \makeatother \begin{document} \pagestyle{empty} \vspace*{\fill} \begin{center} \tdplotsetmaincoords{60}{120} \begin{tikzpicture}[scale=2.5,tdplot_main_coords] % Point P \pgfmathsetmacro{\Px}{1.0} \pgfmathsetmacro{\Py}{1.0} \pgfmathsetmacro{\Pz}{1.0} \pgfmathsetmacro{\Prho}{sqrt(\Px^2+\Py^2+\Pz^2)} \pgfmathsetmacro{\Pphi}{atan(\Py/\Px)} \pgfmathsetmacro{\Ptheta}{atan(sqrt(\Px^2+\Py^2)/\Pz)} \tdplotsetcoord{P}{\Prho}{\Ptheta}{\Pphi} % tikz-3dplot \draw[->] (0,0,0) -- (P) node[pos=0.1,right=4pt] {$\rho_0$}; \draw[dashed] (0,0,0) -- (Pxy) -- (P); \tdplotdrawarc[->]{(0,0,0)}{0.5}{0}{\Pphi}{below}{$\phi_0$} \draw[fill] (P) circle (0.25mm) node[right] {$(\rho_0,\phi_0,\theta_0)$}; % pgf commands (see definition above) \draw[fill,red] (spherical cs:radius=\Prho,longitude=\Pphi,latitude=\Ptheta) circle (0.25mm) node[right] {$(\rho_0,\phi_0,\theta_0)$}; % rectangular coordinates \draw[fill,green] (\Px,\Py,\Pz) circle (0.25mm); % undocumented tikz 3D library \draw[fill,blue] (xyz spherical cs:longitude=\Pphi,latitude=\Ptheta,radius=\Prho) circle (0.25mm) node[right] {$(\rho_0,\phi_0,\theta_0)$}; \tdplotsetthetaplanecoords{\Pphi} \tdplotdrawarc[tdplot_rotated_coords,->]{(0,0,0)}{0.5}{0}{\Ptheta}{right}{$\theta_0$} \draw[thick,->] (0,0,0) -- (1.5,0,0) node[anchor=north east]{$x$}; \draw[thick,->] (0,0,0) -- (0,1.5,0) node[anchor=north west]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$}; \end{tikzpicture} \end{center} \vspace*{\fill} 

\end{document} 

• Ah! I get it now. Longitude and latitude are really… longitude and latitude, and not theta and phi. It looks like longitude is measured from the positive y axis.

 \documentclass[letterpaper,12pt]{article} \usepackage[x11names,rgb]{xcolor} \usepackage{tikz} \usepackage{tikz-3dplot} \usepackage{amsmath} \oddsidemargin 0in \evensidemargin 0in \topmargin 0in \headheight 0in \headsep 0in \textheight 9in \textwidth 6.5in

 % Use pgf commands for spherical coordinates \makeatletter \define@key{sphericalkeys}{radius}{\def\myradius{#1}} \define@key{sphericalkeys}{longitude}{\def\mylongitude{#1}} \define@key{sphericalkeys}{latitude}{\def\mylatitude{#1}} \tikzdeclarecoordinatesystem{spherical}% {% \setkeys{sphericalkeys}{#1}% \pgfpointspherical{\mylongitude}{\mylatitude}{\myradius} } % Use undocumneted tikz 3D library \usetikzlibrary{3d} % fix 3d library (http://groups.google.com/group/comp.text.tex/browse_thread/thread/ab6b859c9bb6eaab/60b3c671094d445c?lnk=gst&q=3d+tikz#60b3c671094d445c) \makeatletter \pgfset{/tikz/cs/radius/.store in=\tikz@cs@radius} \makeatother \begin{document} \pagestyle{empty} \vspace*{\fill} \begin{center} \tdplotsetmaincoords{60}{120} \begin{tikzpicture}[scale=2.5,tdplot_main_coords] % Point P \pgfmathsetmacro{\Px}{1.0} \pgfmathsetmacro{\Py}{1.0} \pgfmathsetmacro{\Pz}{1.0} \pgfmathsetmacro{\Prho}{sqrt(\Px^2+\Py^2+\Pz^2)} \pgfmathsetmacro{\Pphi}{atan(\Py/\Px)} \pgfmathsetmacro{\Ptheta}{atan(sqrt(\Px^2+\Py^2)/\Pz)} \tdplotsetcoord{P}{\Prho}{\Ptheta}{\Pphi} \foreach \theta in {0,10,20,30,40,50,60,70,80,90} \draw[fill,red] (xyz spherical cs:longitude=0,latitude=\theta,radius=1) circle (1pt) node[above right] {\theta}; \foreach \phi in {0,10,20,30,40,50,60,70,80,90} \draw[fill,green] (xyz spherical cs:longitude=\phi,latitude=0,radius=1) circle (1pt) node[below] {\phi}; \draw[thick,->] (0,0,0) -- (1.5,0,0) node[anchor=north east]{$x$}; \draw[thick,->] (0,0,0) -- (0,1.5,0) node[anchor=north west]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$}; \end{tikzpicture} \end{center} \vspace*{\fill} 

\end{document}