Graphics, Figures & Tables3d sphere old code

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
startrucky
Posts: 11
Joined: Mon Aug 18, 2014 2:02 pm

3d sphere old code

Post by startrucky »

Hi there,
as recommended I moved here to make a new post rather than adding to an 6 year old one.
This one: http://latex-community.org/forum/viewto ... 1&start=10
by the way, sorry I don't know how to link properly.

This is a crosspost to http://tex.stackexchange.com/questions/ ... oordinates

I got the problem that the code I modified is kinda old so... well I show you:
I want this:
What i want
What i want
want.jpg (118.66 KiB) Viewed 6331 times
which works in writeLatex, the problem is it uses estyle which leads to removed latitude and longitude circles using texniccenter and miktex:
without longitude circles
without longitude circles
screwed.jpg (74.43 KiB) Viewed 6331 times
Replacing estyle by style, makes the lines appear again, but confused all the nodes:
After change of estyle to style
After change of estyle to style
screwed2.jpg (105.22 KiB) Viewed 6331 times
As far as I now this is a problem of the old code I am using, I would really appreciate some suggestions or somebody who knows the changes of tikz from i guess 1.5 to 3.0+

If somebody could tell me how to place my points again it should work.

Thanks and kind regards
sty

Code: Select all

\documentclass{article} 
\usepackage{tikz} 
\usetikzlibrary{calc,fadings,decorations.pathreplacing} 
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\pagestyle{empty} 

%% helper macros
\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
  \pgfmathsetmacro\yshift{\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,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1); 
}
\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,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}

%% 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} % CENT

%% some definitions 
\def\R{4} % sphere radius
\def\angEl{35} % elevation angle 
\def\angAz{-105} % azimuth angle 
\def\angPhi{-40} % longitude of point P 
\def\angBeta{25} % latitude of point P 

%% working planes
\pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
\tikzset{xyplane/.estyle={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),cos(\angAz)*sin(\angEl),(0,-\H)}}}
\LongitudePlane[xzplane]{\angEl}{\angAz}
\LongitudePlane[pzplane]{\angEl}{\angPhi}
\LongitudePlane[yzplane]{\angEl}{\angAz+90}
\LatitudePlane[equator]{\angEl}{0}

%% draw xyplane and sphere
\fill[ball color=white] (0,0) circle (\R); % 3D lighting effect
\draw (0,0) circle (\R);

\coordinate (O) at (0,0);
\coordinate[mark coordinate] (N) at (0,\H);
\coordinate[mark coordinate] (S) at (0,-\H);
%\path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P);
\path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P1);
\path[pzplane] (-\angBeta:\R) coordinate[mark coordinate] (P2);
\path[pzplane] (\angBeta:2.2*\R) coordinate (P11);
\path[pzplane] (-\angBeta:1.8*\R) coordinate (P22);
\path[pzplane] (\angBeta:0.5*\R) coordinate (P15);
\path[pzplane] (-\angBeta:0.5*\R) coordinate (P25);

%% draw meridians and latitude circles
\DrawLatitudeCircle[\R]{0} % equator
\DrawLongitudeCircle[\R]{\angAz} % xzplane
\DrawLongitudeCircle[\R]{\angAz+90} % yzplane
\DrawLongitudeCircle[\R]{\angPhi} % pzplane

%% draw xyz coordinate system

\draw[xzplane,->] (0,0) -- (1.9*\R,0) node[below] {$x$};
\draw[yzplane,->] (0,0) -- (1.4*\R,0) node[below] {$y$};
\draw[->] 		  (0,0) -- (0,1.3*\R) node[above] {$z$};
\draw[pzplane,->] (0,0) -- (1.5*\R,0) node[below] {$x_{2}$};

%% draw lines and put labels
\draw[dashed] (S) -- (N) +(0.3ex,0.6ex) node[above left] {$\mathbf{N}$};
\path (S) +(0.4ex,-0.4ex) node[below] {$\mathbf{S}$};
\draw[dashed] (P11) -- (P1) -- (O) -- (P2) -- (P22);
\draw[->,thin] (P22) to[bend right=25] node[pos=0.5,right] {$\beta$} (P11);
\draw[equator,->,thin] (\angAz:0.5*\R) to[bend right=30] node[pos=0.44,below] {$\theta$} (\angPhi:0.5*\R);

\end{tikzpicture} 
\end{document} 
Last edited by startrucky on Mon Aug 18, 2014 8:52 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

startrucky
Posts: 11
Joined: Mon Aug 18, 2014 2:02 pm

3d sphere old code

Post by startrucky »

Here is a bloody fix up, by setting all points manually.
For the actual problem there seems to be a ticket http://sourceforge.net/p/pgf/bugs/306/

Code: Select all

    \documentclass{article}

		%%\usepackage[nomain,nonumberlist,acronym,section,description]{glossaries}
%%\newglossary[alg]{acronymlist}{acr}{acn}{Abkverzeichnis}
    %%\makeglossaries
%%
		%%\newacronym[description=Part of Speech test extra]{POS}{POS}{Part Of Speech}
%%
    %%\begin{document}
%%
    %%Test \gls{POS} and ?
%%\glsaddall
%%
    %%\printglossaries
		%%\input{globe}
%% ========== glossaries test end
%
%\documentclass{article} 
%\usepackage{pgfplots}
% added tikz-3dplots, 3D NOT CHANGING ANYTHING SO FAR
\usepackage{tikz, tikz-3dplot} 
\usetikzlibrary{3D,calc,fadings,decorations.pathreplacing} 
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\pagestyle{empty} 

%% helper macros
\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
  \pgfmathsetmacro\yshift{\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,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1); 
}
\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,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}

%% 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} % CENT

%% some definitions 

\def\R{4} % sphere radius
\def\angEl{35} % elevation angle 
\def\angAz{-105} % azimuth angle 
\def\angPhi{-40} % longitude of point P 
\def\angBeta{25} % latitude of point P 

%% working planes

\pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
\tikzset{xyplane/.style={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),cos(\angAz)*sin(\angEl),(0,-\H)}}}
\LongitudePlane[xzplane]{\angEl}{\angAz}
\LongitudePlane[pzplane]{\angEl}{\angPhi}
\LongitudePlane[yzplane]{\angEl}{\angAz+90}
\LatitudePlane[equator]{\angEl}{0}

%% draw xyplane and sphere

%\draw[xyplane] (-1.45*\R,-1.45*\R);% rectangle (2.2*\R,2.2*\R);
%\draw[xyplane] (0.5*\R,1*\R); % rectangle (2.2*\R,2.2*\R);
\fill[ball color=gray] (0,0) circle (\R); % 3D lighting effect
%\fill[white] (0,0) circle (\R); % just a white circle
\draw[gray] (0,0) circle (\R);

%% characteristic points

\coordinate (O) at (0,0);
\coordinate[mark coordinate] (N) at (0,\H);
\coordinate[mark coordinate] (S) at (0,-\H);
%######################################################################
% alternative to good style method
\coordinate[mark coordinate] (P1) at (2.775,0.05); %good
\coordinate (P11) at (6.1,0.115); %good
\coordinate (pt15) at (1.39,0.02); %good
\coordinate[mark coordinate] (P2) at (2.78,-2.725); %good
\coordinate (P22) at (5,-4.9); %good
\coordinate (P25) at (1.39,-1.36); %good
%######################################################################
%\path[pzplane] (\angEl:\R) coordinate[mark coordinate] (P);
%\path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P1);
%\path[pzplane] (-\angBeta:\R) coordinate[mark coordinate] (P2);
%\path[pzplane] (\angBeta:2.2*\R) coordinate (P11);
%\path[pzplane] (-\angBeta:1.8*\R) coordinate (P22);
%\path[pzplane] (\angBeta:0.5*\R) coordinate (P15);
%\path[pzplane] (-\angBeta:0.5*\R) coordinate (P25);
 %\path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P1);
 %\path[pzplane] (-\angBeta:\R) coordinate[mark coordinate] (P2);
 %\path[pzplane] (\angBeta:2.2*\R) coordinate[mark coordinate] (P11);
 %\path[pzplane] (-\angBeta:1.8*\R) coordinate[mark coordinate] (P22);
 %\path[pzplane] (\angBeta:0.5*\R) coordinate[mark coordinate] (P15);
 %\path[pzplane] (-\angBeta:0.5*\R) coordinate[mark coordinate] (P25);
%\path[pzplane] (\R,0) coordinate (PE);
%\path[xzplane] (\R,0) coordinate (XE);
%\path[xyplane] (\R,0) coordinate (XY)
%\path (PE) ++(0,-\H) coordinate (Paux); % to aid Phat calculation
%\coordinate[mark coordinate] (Phat) at (intersection cs: first line={(N)--(P)}, second line={(S)--(Paux)});

%% draw meridians and latitude circles

\DrawLatitudeCircle[\R,yellow]{0} % equator
%%\DrawLatitudeCircle[\R]{\angBeta}
\DrawLongitudeCircle[\R,blue]{\angAz} % xzplane
\DrawLongitudeCircle[\R,green]{\angAz+90} % yzplane
\DrawLongitudeCircle[\R,red]{\angPhi} % pzplane

%######################################################################
% more alternative or workaround
%\coordinate[mark coordinate,red] (x1) at (-1.95,-4.2);
\coordinate (x1) at (-1.95,-4.2);
\draw[->] (O)--(x1) node[below] {$x_{CIO}$};
\coordinate (y1) at (5.45,-0.81);
\draw[->] (O) -- (y1) node[below] {$y_{CIO}$};
\coordinate (x2) at (4.6,-2.2);
\draw[->] (O) -- (x2) node[below] {$x_{TIO}$};
\coordinate (z1) at (0,5);
\draw[->] 		    (O) -- (z1) node[above] {$z_{CIP}$};
%######################################################################
%% draw xyz coordinate system
%\draw[xyplane,<->] (1.5*\R,0) node[below] {$x$} -- (0,0) -- (0,1.5*\R) node[right] {$y$};
%\draw[xzplane,->] (O) -- (1.9*\R,0) node[below] {$x_{CIO}$};
%\draw[yzplane,->] (O) -- (1.4*\R,0) node[below] {$y_{CIO}$};
%\draw[->] 		    (O) -- (0,1.3*\R) node[above] {$z_{CIP}$};
%\draw[pzplane,->] (O) -- (1.5*\R,0) node[below] {$x_{TIO}$};

%% draw lines and put labels

\draw[dashed] (S) -- (N) +(0.3ex,0.6ex) node[above left] {$\mathbf{N}$};
%\draw (P) -- (Phat) node[above right] {$\mathbf{\hat{P}}$};
\path (S) +(0.4ex,-0.4ex) node[below] {$\mathbf{S}$};
%\draw[->] (O) -- (P) node[above right] {$\mathbf{P}$};
\draw[dashed] (P11) -- (P1) -- (O) -- (P2) -- (P22);
%\draw[pzplane,->,thin] (P15) to[bend right=15] node[pos=0.5,right] {$\beta_{CEO}$} (p25);
%\draw[->,thin] (P25) to[bend right=15] node[pos=0.5,right] {$\beta_{CEO}$} (P15);
\draw[->,thin] (P22) to[bend right=25] node[pos=0.5,right] {$\beta_{CEO}$} (P11);
\draw[equator,->,thin,purple] (\angAz:0.5*\R) to[bend right=30] node[pos=0.44,below] {$\theta_{ERA}$} (\angPhi:0.5*\R);
%\draw[thin,decorate,decoration={brace,raise=0.5pt,amplitude=1ex}] (N) -- (O) node[midway,right=1ex] {$a$};

\end{tikzpicture} 

%\begin{tikzpicture}
    %\draw (-1,0) arc (180:360:1cm and 0.5cm);
    %\draw[dashed] (-1,0) arc (180:0:1cm and 0.5cm);
    %\draw (0,1) arc (90:270:0.5cm and 1cm);
    %\draw[dashed] (0,1) arc (90:-90:0.5cm and 1cm);
    %\draw (0,0) circle (1cm);
		%\draw (0,0) circle (0.008cm);
    %\shade[ball color=blue!10!white,opacity=0.20] (0,0) circle (1cm);
%\end{tikzpicture}

    \end{document}

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: 3d sphere old code

Post by cgnieder »

This post looks like a crosspost to TeX.sx: http://tex.stackexchange.com/questions/ ... oordinates

It's always nice to give a link in such cases!

Regards
site moderator & package author
startrucky
Posts: 11
Joined: Mon Aug 18, 2014 2:02 pm

Re: 3d sphere old code

Post by startrucky »

Yeah forgot that sorry, added it above as well just to make sure.
Post Reply