# Drawing a rotated and shifted coordinate system with tikz-3dplot

Following the good help I got from marmot, I have drawn another spherical coordinate system in geogebra software, and exported the code to pgf/tikz. This incorporates the little additions I mentioned in my post here. The idea is to illustrate how coordinate unit vectors vary with position in a spherical coordinate system. This coordinate system is widely used in the atmospheric sciences. What I have produced in much closer to what I wanted to do but does not really look professional. Any improvements would be appreciated. The code below

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

\definecolor{qqwuqq}{rgb}{0,0.39,0}
\definecolor{uququq}{rgb}{0.25,0.25,0.25}
\definecolor{xdxdff}{rgb}{0.49,0.49,1}
\definecolor{qqqqff}{rgb}{0,0,1}
\definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle
45,x=1.0cm,y=1.0cm,scale=0.45]
\clip(-7,-7) rectangle (7,8);
\draw [shift={(0,0)},color=qqwuqq,fill=qqwuqq,fill opacity=0.1] (0,0) --
(-119.05:0.76) arc (-119.05:-23.34:0.76) -- cycle;
\draw [shift={(0,0)},color=qqwuqq,fill=qqwuqq,fill opacity=0.1,line
width=1.2pt] (0,0) -- (-23.34:1.33) arc (-23.34:46.46:1.33) -- cycle;
\draw [rotate around={0:(0,0)},line width=1.2pt] (0,0) ellipse (6.75cm and
6.05cm);
\draw (0,0)-- (-1.11,-2.02);
\draw (0,0)-- (4,-1.8);
\draw [rotate around={0:(0,0)},fill=gray!25,fill opacity=0.1,line width=0.8pt]
(0,0) ellipse (6.8cm and 2.18cm);
\draw (0,0)-- (4.38,4.61);
\draw [line width=1.2pt](0,-6.5)-- (0,7.5);
\draw [->] (4.38,4.61) -- (3.22,5.53);
\draw [->] (4.38,4.61) -- (5.34,5.79);
\draw [->] (4.38,4.61) -- (5.72,5);
\draw (3.53,4.65) node[anchor=north west] {$P$};
\draw (0.85,8.08) node[anchor=north west] {$\Omega$};
\draw (3.14,7.08) node[anchor=north west] {$y'$};
\draw (5.07,6.63) node[anchor=north west] {$z'$};
\draw (5.74,5.91) node[anchor=north west] {$x'$};
\draw (2.18,3.94) node[anchor=north west] {$r$};
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (-6.26,0.85)-- (-6.7,0.35);
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (-5.46,1.3)-- (-6.21,0.88);
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (-3.87,1.79)-- (-5.42,1.29);
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (-1.52,2.13)-- (-3.79,1.78);
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (1.4,2.13)-- (-1.48,2.16);
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (3.41,1.89)-- (1.44,2.09);
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (5.25,1.38)-- (3.45,1.9);
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (6.19,0.9)-- (5.19,1.33);
\draw [line width=1.2pt,dash pattern=on 5pt off 5pt] (6.74,0.35)-- (6.21,0.88);
\begin{scriptsize}
\fill [color=qqqqff] (3.53,4.65) circle (1.5pt);
\draw[color=qqwuqq] (0.49,-1.14) node {$\varphi$};
\draw[color=qqwuqq] (1.7,0.27) node {$\lambda$};
\end{scriptsize}
\draw (0,7.1)  -- (0,7.2)  node [midway] {\AxisRotator[rotate=-90]};
\end{tikzpicture}
\end{document}

• Did you forget to define \AxisRotator? – user121799 Jan 3 '18 at 22:02

A proposal based on Alain Matthes macros and some additional stuff.

\documentclass{article}
\usepackage{tikz}
\usepackage{verbatim}

\newcommand\pgfmathsinandcos[3]{%
\pgfmathsetmacro#1{sin(#3)}%
\pgfmathsetmacro#2{cos(#3)}%
}
\newcommand\LongitudePlane[3][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#2} % elevation
\pgfmathsinandcos\sint\cost{#3} % azimuth
\tikzset{#1/.style={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
}

\newcommand\LatitudePlane[3][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#2} % elevation
\pgfmathsinandcos\sint\cost{#3} % latitude
\tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
}
\newcommand\NewLatitudePlane[4][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#3} % elevation
\pgfmathsinandcos\sint\cost{#4} % latitude
\pgfmathsetmacro\yshift{#2*\cosEl*\sint}
\tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
}
\newcommand\DrawLongitudeCircle[2][1]{
\LongitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=#1}}
% angle of "visibility"
\pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
\draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
\draw[current plane,opacity=0.4] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}
\newcommand\DrawLongitudeArc[4][black]{
\LongitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=1}}
\pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
\pgfmathsetmacro\angA{mod(max(\angVis,#3),360)} %
\pgfmathsetmacro\angB{mod(min(\angVis+180,#4),360} %
}%
\newcommand\DrawLatitudeCircle[2][1]{
\LatitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=#1}}
\pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
% angle of "visibility"
\pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
\draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
\draw[current plane,opacity=0.4] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}

\newcommand\DrawLatitudeArc[4][black]{
\LatitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=1}}
\pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
% angle of "visibility"
\pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
\pgfmathsetmacro\angA{max(min(\angVis,#3),-\angVis-180)} %
\pgfmathsetmacro\angB{min(\angVis,#4)} %
}

%% document-wide tikz options and styles

\tikzset{%
>=latex, % option for nice arrows
inner sep=0pt,%
outer sep=2pt,%
mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,
fill=black,circle}%
}

\begin{document}

\begin{tikzpicture} % "THE GLOBE" showcase
\def\angEl{20} % elevation angle
\def\angAz{-20} % azimuth angle

\pgfmathsetmacro\H{\RadiusSphere*cos(\angEl)} % distance to north pole
\coordinate (O) at (0,0);
\node[circle,draw,black,scale=0.3] at (0,0) {};
\draw[left] node at (0,0){O};
\coordinate[mark coordinate] (N) at (0,\H);
\draw[left] node at (0,\H){N};
\coordinate[mark coordinate] (S) at (0,-\H);
\draw[left] node at (0,-\H){S};
\draw[thick, dashed, black](N)--(S);

\tikzset{
every path/.style={
color=green!50!black
}
}
\tikzset{
every path/.style={
color=black
}
}

\def\myphi{-40}
\def\mytheta{60}
\def\newaxisscale{0.4} % length of coordinate axes (in units of \RadiusSphere)
\LongitudePlane[angle]{\angEl}{\myphi};
\draw[angle,->,blue] (\mytheta:\RadiusSphere) -- (\mytheta:1.2*\RadiusSphere) node[right] {$x'$};
\pgfmathsinandcos{\myy}{\myx}{\mytheta}
node[left] {$z'$};
\draw[left] node at (Oprime){$O'$};
\DrawLongitudeArc[red]{-40}{00}{60}
node[midway,right]{$\theta$};

\LatitudePlane[helsinki]{\angEl}{\mytheta};
\pgfmathsinandcos{\myx}{\myy}{\myphi}
\draw[helsinki,->,blue] (Opprime) --
node[right] {$y'$};

\draw[equator,->,blue] (0,0) -- (-80:\newaxisscale*\RadiusSphere) node[left] {$x$};
\draw[equator,->,blue] (0,0) -- (10:\newaxisscale*\RadiusSphere) node[right] {$y$};
\draw[->,blue] (0,0) -- (0,\newaxisscale*\RadiusSphere) node[right] {$z$};

node[midway,below]{$\phi$};

• @ZiloreMumba Hmmh, I really just started from Alain Matthes's macros, and made some minor adjustments. His approach is to define longitudinal and latitudinal planes, in which everything becomes 2-dimensional. For instance, the helskinki plane is a plane cuts the sphere at the circle at the 60 degree of latitude, or, more precisely, at \mytheta degrees. So, in order to change the location of O', you need to play with \mytheta and \myphi. Unfortunately, I do not know what \AxisRotator does, but I guess you want to put it \node [above of=N] {\AxisRotator};. – user121799 Jan 5 '18 at 20:00