Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to create a simple spherical quadrant grid using the tikz-3dplot package. The longitudinal grid lines look fine but when I try to create the latitudinal lines I get really strange results that I don't understand. I was expecting to see a series of latitude arcs rotating around the x-axis (so they're not quite the same as latitude lines). Instead, it appears that my attempt to rotate around the x-axis is rotating around all three axes. I'm not sure what I'm doing wrong.

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\begin{document}
\tdplotsetmaincoords{60}{155}
\usetikzlibrary{3d}

\begin{tikzpicture}[scale=5,tdplot_main_coords]
\tikzstyle{grid}=[thin,color=red,tdplot_rotated_coords]

\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (-1,0,0);
\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$};

\foreach \rot in {0, 30, 60, 90} {
    \tdplotsetrotatedcoords{\rot}{0}{0};
    \tdplotdrawarc[grid]{(0,0,0)}{1}{0}{180}{}{};
}

\foreach \rot in {-90, -60, -30, 0, 30, 60, 90} {
    \tdplotsetrotatedcoords{\rot}{90}{0};
    \tdplotdrawarc[grid]{(0,0,0)}{1}{90}{180}{}{};
}

\end{tikzpicture}
\end{document}

Results shown in QTikz

Edit:

After more investigation it appears that attempting to rotate around the x-axis actually rotates around the z-axis, as can be clearly seen in this image. Placing the \rot in the x- or z-position has the same effect.

Image with only x rotated and shortened arcs.

share|improve this question
    
For the code formatting it is best to select the code and hit the {} symbol which will apply the code formatting (which is just indentation) rather then enter HTML. Also, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This is especially important for tikz as there are numerous libraries. –  Peter Grill Mar 23 '13 at 22:35
    
Oops that's embarrassing, I normally do include a complete example but I forgot to include my QTikz template. The code should now work with pdflatex. –  Andrew Myers Mar 23 '13 at 22:41
add comment

3 Answers

This really seems to be a bug, rotations about the y and z axis work as expected, but around the x axis appears to be also to rotate about the z axis. So I think it would be best if you filed a bug report. If you can't wait for it to be fixed, you could use this much slower TikZ version, which uses only a little goniometry and approximating an arc by drawing 180 line segments:

Code

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz-3dplot}

\begin{document}

\tdplotsetmaincoords{60}{155}
\usetikzlibrary{3d}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\tikzstyle{grid}=[thin,color=red,tdplot_rotated_coords]
    \foreach \a in {0,1,...,9}
    {   \draw (1,0,0)
        \foreach \b in  {1,...,180}
        { -- ({cos(\b)},{sin(\b)*cos(10*\a)},{sin(\b)*sin(10*\a)})
        }
        ;
    }
    \foreach \rot in {-90,-80,...,90} {
    \tdplotsetrotatedcoords{\rot}{90}{0};
    \tdplotdrawarc[grid]{(0,0,0)}{1}{90}{180}{}{};
    }
    \draw[thick,->] (-1,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{document}

Outputenter image description here

share|improve this answer
add comment

Actually,this is not a bug. The rotations are not xyz rotations but rather zyz rotations. To make a 90 degree rotation around the x-axis you can make a 90 degree rotation around the z-axis, followed by a 90 degree rotation around the rotated y-axis, and finaly a 270 degree rotation around the rotated z-axis. These rotations are called Euler rotations. You can read more about Euler rotations on Wikipedia or tikz-3dplot documention.

share|improve this answer
add comment

A solution with PSTricks. Run it with xelatex:

\documentclass{article}
\usepackage{pst-3dplot}
\begin{document}

\begin{pspicture}(-5,0)(15,10)
\psset{unit=3cm,Alpha=45, Beta=15,linecolor=blue!60,linewidth=1.5pt}
\parametricplotThreeD[xPlotpoints=500, yPlotpoints=10](0,180)(0,90){
    /r 1.0 def
    r t cos mul u sin mul 
    r t sin mul u sin mul 
    r u cos  mul }
\parametricplotThreeD[xPlotpoints=500, yPlotpoints=8](0,90)(0,180){
    /r 1.0 def
    r u cos mul t sin mul 
    r u sin mul t sin mul 
    r t cos  mul }
\pstThreeDCoor[xMin=-2,xMax=2.0,yMin=-.5,yMax=2.0, zMin=-.5,zMax=1.5,linecolor=black,linewidth=0.6pt]
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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