├── .project
├── .texlipse
├── LICENSE
├── README.md
├── _tester.tex
├── example_frontpage1.tex
├── example_frontpage2.tex
├── example_minimalistcode.tex
├── images
├── example_frontpage1.png
└── example_frontpage2.png
├── tikz-3dplot-circleofsphere.bib
├── tikz-3dplot-circleofsphere.pdf
├── tikz-3dplot-circleofsphere.sty
├── tikz-3dplot-circleofsphere.tex
└── tikz_3dplot_circleofsphere.m
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | tikz-3dplot-circleofsphere
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.texlipse.builder.TexlipseBuilder
10 |
11 |
12 |
13 |
14 | net.sourceforge.texlipse.builder.TexlipseBuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.texlipse.builder.TexlipseNature
21 | net.sourceforge.texlipse.builder.TexlipseNature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.texlipse:
--------------------------------------------------------------------------------
1 | #TeXlipse project settings
2 | #Thu Jul 26 13:19:27 CEST 2018
3 | markTmpDer=true
4 | builderNum=2
5 | outputDir=
6 | makeIndSty=
7 | bibrefDir=
8 | outputFormat=pdf
9 | tempDir=
10 | mainTexFile=tikz-3dplot-circleofsphere.tex
11 | outputFile=tikz-3dplot-circleofsphere.pdf
12 | langSpell=en
13 | markDer=true
14 | srcDir=
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Matthias Wolff
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### The tikz-3dplot-circleofsphere Package: Drawing Circles of a Sphere with tikz-3dplot
2 |
3 | #### Abstract
4 | A _circle of a sphere_ is a circle drawn on a spherical surface like, for instance, circles of latitude or longitude.
5 | Circles in arbitrary 3D positions can be drawn with TikZ [2] very easily using a transformed coordinate system provided
6 | by the `tikz-3dplot` package [1] (that is because TikZ can only draw circles on the _xy_-plane). However, automatically
7 | distinguishing the parts of the circle lying on the front and back sides of the sphere, e.g. by drawing a solid arc on
8 | the front side and a dashed one on the back side, is a somewhat tricky feat. The `tikz-3dplot-circleofsphere` package
9 | will perform that feat for you.
10 |
11 | __Examples__
12 |
13 |
14 |  |
15 |  |
16 |
17 |
18 | Example 1: Latitude-longitude grid |
19 | Example 2: Bunch of great circles |
20 |
21 |
22 |
23 | #### Package Documentation
24 | [Click here to read package documentation](tikz-3dplot-circleofsphere.pdf).
25 |
26 | #### Installation
27 | Download the [`tikz-3dplot-circleofsphere.sty`](https://rawgit.com/matthias-wolff/tikz-3dplot-circleofsphere/master/tikz-3dplot-circleofsphere.sty) file into your project folder and include the package with
28 | `\usepackage{tikz-3dplot-circleofsphere}`.
29 |
30 | #### References
31 | 1. Jeff Hein. The tikz-3dplot package. http://mirror.ctan.org/graphics/pgf/contrib/tikz-3dplot/tikz-3dplot_documentation.pdf, 2012 Retrieved July 27, 2018.
32 | 2. Till Tantau. Tikz & pgf - manual for version 3.0.1a. http://mirror.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf, 2015. Retrieved July 27, 2018.
33 |
--------------------------------------------------------------------------------
/_tester.tex:
--------------------------------------------------------------------------------
1 | \documentclass{standalone}
2 | \usepackage[dvipsnames]{xcolor}
3 | \usepackage{tikz-3dplot-circleofsphere}
4 |
5 | \begin{document}
6 |
7 | \def\elev{ 30} \pgfmathsetmacro{\tdpTheta}{90-\elev}
8 | \def\azim{ 35} \pgfmathsetmacro{\tdpPhi}{90+\azim}
9 | \def\R{3}
10 | \tdplotsetmaincoords{\tdpTheta}{\tdpPhi}
11 | \begin{tikzpicture}[scale=1,tdplot_main_coords]
12 | \begin{scope}[black!30,name=auxiliary]
13 | \draw[tdplot_screen_coords] (0,0,0) circle (\R);
14 | \draw[->] (-1.3*\R,0,0) -- (1.3*\R,0,0) node[anchor=north east]{$x$};
15 | \draw[->] (0,-1.3*\R,0) -- (0,1.3*\R,0) node[anchor=north west]{$y$};
16 | \draw[->] (0,0,-1.3*\R) -- (0,0,1.3*\R) node[anchor=south]{$z$};
17 | \tdplotCsDrawCircle{\R}{0}{0}{0};
18 | \end{scope}
19 | \begin{scope}
20 | % \tdplotCsDrawLatCircle[tdplotCsDrawAux]{\R}{-30}
21 | % --
22 | \tdplotCsDrawCircle[tdplotCsDrawAux]{\R}{-40}{30}{30}
23 | % --
24 | % \foreach \a in {0,15,...,345}
25 | % { \tdplotCsDrawCircle[very thin,gray]{\R}{\a}{90}{0} }
26 | % \foreach \a in {-75,-60,...,75}
27 | % { \tdplotCsDrawCircle[very thin,gray]{\R}{0}{0}{\a} }
28 | % -- Pathologic cases -->
29 | % \tdplotCsDrawCircle{\R}{35}{60}{0}
30 | % <--
31 | \end{scope}
32 | \end{tikzpicture}
33 |
34 | \end{document}
--------------------------------------------------------------------------------
/example_frontpage1.tex:
--------------------------------------------------------------------------------
1 | \documentclass{standalone}
2 | \usepackage{tikz-3dplot-circleofsphere}
3 | \begin{document}
4 | \centering
5 | \def\r{3}
6 | \tdplotsetmaincoords{60}{125}
7 | \begin{tikzpicture}[tdplot_main_coords]
8 | \draw[tdplot_screen_coords,thin,black!30] (0,0,0) circle (\r);
9 | \foreach \a in {-75,-60,...,75}
10 | {\tdplotCsDrawLatCircle[thin,black!30]{\r}{\a}}
11 | \foreach \a in {0,15,...,165}
12 | {\tdplotCsDrawLonCircle[thin,black!30]{\r}{\a}}
13 | \tdplotCsDrawLatCircle%
14 | [thick,tdplotCsFill/.style={opacity=0.05}]{\r}{0}
15 | \tdplotCsDrawGreatCircle%
16 | [red,thick,tdplotCsFill/.style={opacity=0.1}]{\r}{105}{-23.5}
17 | \end{tikzpicture}
18 | \end{document}
--------------------------------------------------------------------------------
/example_frontpage2.tex:
--------------------------------------------------------------------------------
1 | \documentclass{standalone}
2 | \usepackage{tikz-3dplot-circleofsphere}
3 | \begin{document}
4 | \centering
5 | \def\r{3}
6 | \tdplotsetmaincoords{60}{125}
7 | \begin{tikzpicture}[tdplot_main_coords]
8 | \def\e{80};
9 | \draw[tdplot_screen_coords,very thin] (0,0,0) circle (\r);
10 | \foreach \a in {0,5,...,175} {
11 | \tdplotCsDrawGreatCircle%
12 | [thin, tdplotCsBack/.style={thin,blue!40}]%
13 | {\r}{\a}{90*sin(\a)*sin(\e)}
14 | }
15 | \end{tikzpicture}
16 | \end{document}
--------------------------------------------------------------------------------
/example_minimalistcode.tex:
--------------------------------------------------------------------------------
1 | \documentclass{standalone}
2 | \usepackage{tikz,tikz-3dplot}
3 | %% >> MINIMALIST CIRCLE OF SHPERE DRAWING CODE _______________________________________________________________________
4 | \newcommand\scircle[4]{%
5 | \tdplotsetrotatedcoords{#2}{#3}{0} % Rotate coordinate system
6 | \let\a\tdplotalpha % alpha (rotated coord. system)
7 | \let\b\tdplotbeta % beta (rotated coord. system)
8 | \let\p\tdplotmainphi % phi (main coord. system)
9 | \let\t\tdplotmaintheta % theta (main coord. system)
10 | \pgfmathsetmacro\azx{cos(\a)*cos(\b)*sin(\p)*sin(\t) - sin(\b)*cos(\t) - cos(\b)*cos(\p)*sin(\a)*sin(\t)}
11 | \pgfmathsetmacro\azy{-cos(\a)*cos(\p)*sin(\t) - sin(\a)*sin(\p)*sin(\t)}
12 | \pgfmathsetmacro\azz{cos(\b)*cos(\t) + cos(\a)*sin(\b)*sin(\p)*sin(\t) - cos(\p)*sin(\a)*sin(\b)*sin(\t)}
13 | \pgfmathsetmacro\re {#1*cos(#4)} % Radius of circle
14 | \pgfmathsetmacro\ze {#1*sin(#4)} % z-coordinate of drawing plane
15 | \pgfmathsetmacro\coX{\ze*cos(#2)*sin(#3)} % x-coordinate offset for ze
16 | \pgfmathsetmacro\coY{\ze*sin(#2)*sin(#3)} % y-coordinate offset for ze
17 | \pgfmathsetmacro\coZ{\ze*cos(#3)} % z-coordinate offset for ze
18 | \coordinate (coffs) at (\coX,\coY,\coZ); % Offset as coordinate value
19 | \tdplotsetrotatedcoordsorigin{(coffs)} % Offset coordinate system
20 | \begin{scope}[tdplot_rotated_coords] % Drawing scope >>
21 | \pgfmathsetmacro\tanEps{tan(#4)} % Tangent of elevation angle
22 | \pgfmathsetmacro\bOneside{((\tanEps)^2)>=(((\azx)^2+(\azy)^2)/(\azz)^2)} % Circle entirely on one side?
23 | \ifthenelse{\bOneside=1}{% % Circle on one side of sphere >>
24 | \pgfmathsetmacro\bFrontside{(\azx*\re+\azz*\ze)>=0} % Circle entirely on front side?
25 | \ifthenelse{\bFrontside=1} % |
26 | {\draw (0,0) circle (\re);} % Draw on front side
27 | {\draw[dashed] (0,0) circle (\re);} % Draw on back side
28 | }{% % << Circle on both sides >>
29 | \pgfmathsetmacro\u{\azy} % Substitution u=...
30 | \pgfmathsetmacro\v{sqrt( (\azx)^2 + (\azy)^2 - (\azz)^2*(\tanEps)^2 )} % Substitution v=...
31 | \pgfmathsetmacro\w{\azx - \azz*\tanEps} % Substitution w=...
32 | \pgfmathsetmacro\phiBf{2*atan2(\u-\v,\w)} % Back->front crossing angle
33 | \pgfmathsetmacro\phiFb{2*atan2(\u+\v,\w)} % Front->back crossing angle
34 | \pgfmathsetmacro\bUnwrapA{(\phiFb-\phiBf)>360} % Unwrap front->back angle #1?
35 | \pgfmathsetmacro\bUnwrapB{\phiBf>\phiFb} % Unwrap front->back angle #2?
36 | \ifthenelse{\bUnwrapA=1}{\pgfmathsetmacro\phiBf{\phiBf+360}}{} % Unwrap front->back angle #1
37 | \ifthenelse{\bUnwrapB=1}{\pgfmathsetmacro\phiBf{\phiBf-360}}{} % Unwrap front->back angle #2
38 | \draw[dashed] (\phiFb:\re) arc (\phiFb:{\phiBf+360}:\re); % Draw back side arc
39 | \draw (\phiBf:\re) arc (\phiBf:\phiFb:\re); % Draw back side arc
40 | } % <<
41 | \end{scope} % << (Drawing scope)
42 | }
43 | %% << ________________________________________________________________________________________________________________
44 | \begin{document}
45 | \tdplotsetmaincoords{60}{125} % Set main coordintate system
46 | \begin{tikzpicture}[thick,tdplot_main_coords] % TikZ picture >>
47 | \begin{scope}[black!30] % Draw in gray >>
48 | \draw[tdplot_screen_coords] (0,0,0) circle (2.5); % Sphere outline
49 | \scircle{2.5}{0}{0}{0} % Equator
50 | \end{scope} % <<
51 | \scircle{2.5}{-40}{40}{30} % Draw another sphere circle
52 | \end{tikzpicture} % <<
53 | \end{document}
54 |
--------------------------------------------------------------------------------
/images/example_frontpage1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matthias-wolff/tikz-3dplot-circleofsphere/b17ac11510c744f7e82e6674bfccc6617c7c0060/images/example_frontpage1.png
--------------------------------------------------------------------------------
/images/example_frontpage2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matthias-wolff/tikz-3dplot-circleofsphere/b17ac11510c744f7e82e6674bfccc6617c7c0060/images/example_frontpage2.png
--------------------------------------------------------------------------------
/tikz-3dplot-circleofsphere.bib:
--------------------------------------------------------------------------------
1 | @Misc{Hei12,
2 | author = {Jeff Hein},
3 | title = {The \texttt{tikz-3dplot} Package},
4 | howpublished = {\url{http://mirror.ctan.org/graphics/pgf/contrib/tikz-3dplot/tikz-3dplot_documentation.pdf}},
5 | note = {Retrieved: July 27, 2018},
6 | year = {2012}
7 | }
8 |
9 | @Misc{Tan15,
10 | author = {Till Tantau},
11 | title = {TikZ \& PGF - Manual for Version 3.0.1a},
12 | howpublished = {\url{http://mirror.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf}},
13 | note = {Retrieved: July 27, 2018},
14 | year = {2015}
15 | }
16 |
17 | @Misc{Wol18,
18 | author = {Matthias Wolff},
19 | title = {The \texttt{tikz-3dplot-circleofsphere} Package: Drawing Circles of a Sphere with \texttt{tikz-3dplot}},
20 | howpublished = {\url{https://github.com/matthias-wolff/tikz-3dplot-circleofsphere}},
21 | note = {Retrieved: July 27, 2018},
22 | year = {2018}
23 | }
24 |
--------------------------------------------------------------------------------
/tikz-3dplot-circleofsphere.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matthias-wolff/tikz-3dplot-circleofsphere/b17ac11510c744f7e82e6674bfccc6617c7c0060/tikz-3dplot-circleofsphere.pdf
--------------------------------------------------------------------------------
/tikz-3dplot-circleofsphere.sty:
--------------------------------------------------------------------------------
1 | %% == LaTeX PACKAGE tikz-3dplot-circleofsphere ================================
2 | %% Drawing circles of a sphere with tikz-3dplot
3 | %%
4 | %% Matthias Wolff, BTU Cottbus-Senftenberg
5 | %% July 27, 2018
6 | %%
7 | %% References:
8 | %% [1] J. Hein. The tikz-3dplot package. 2012. Online, retrieved July 20, 2018.
9 | %% http://mirror.ctan.org/graphics/pgf/contrib/tikz-3dplot/tikz-3dplot_documentation.pdf
10 | %% [2] T. Tantau. TikZ & PGF - Manual for Version 3.0.1a. 2015. Online, retrieved July 22, 2018.
11 | %% http://mirror.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf
12 | %% [3] Drawing Great Circles
13 | %% https://tex.stackexchange.com/questions/168521/spherical-triangles-and-great-circles
14 |
15 | %% == REQUIRED PACKAGES =======================================================
16 |
17 | \RequirePackage{xifthen}
18 | \RequirePackage{tikz}
19 | \RequirePackage{tikz-3dplot}
20 |
21 | %% == TikZ STYLES =============================================================
22 |
23 | \tikzset{
24 | tdplotCsFront/.style={solid},
25 | tdplotCsBack/.style={dashed},
26 | tdplotCsFill/.style={opacity=0},
27 | tdplotPtFront/.style={},
28 | tdplotPtBack/.style={},
29 | tdplotCsDrawAux/.style={}
30 | }
31 |
32 | %% == COMMANDS ================================================================
33 |
34 | \newcommand{\tdplotCsComputeTransformRotScreen}{%
35 | % Computes the elements of the full rotation matrix
36 | %
37 | % A = [\axx \axy \axz]
38 | % [\ayx \ayy \ayz]
39 | % [\azx \azy \azz].
40 | %
41 | % Ouput:
42 | % \axx - Element A(1,1) of rotation matrix
43 | % \axy - Element A(1,2) of rotation matrix
44 | % ...
45 | % \azz - Element A(3,3) of rotation matrix
46 | %
47 | \let\a\tdplotalpha
48 | \let\b\tdplotbeta
49 | \let\p\tdplotmainphi
50 | \let\t\tdplotmaintheta
51 | % Row 1: [\axx \axy \axz]
52 | \pgfmathsetmacro\axx{cos(\a)*cos(\b)*cos(\p) + cos(\b)*sin(\a)*sin(\p)}
53 | \pgfmathsetmacro\axy{cos(\a)*sin(\p) - cos(\p)*sin(\a)}
54 | \pgfmathsetmacro\axz{cos(\a)*cos(\p)*sin(\b) + sin(\a)*sin(\b)*sin(\p)}
55 | % Row 2: [\ayx \ayy \ayz]
56 | \pgfmathsetmacro\ayx{cos(\b)*cos(\p)*sin(\a)*cos(\t) - cos(\a)*cos(\b)*cos(\t)*sin(\p) - sin(\b)*sin(\t)}
57 | \pgfmathsetmacro\ayy{cos(\a)*cos(\p)*cos(\t) + sin(\a)*cos(\t)*sin(\p)}
58 | \pgfmathsetmacro\ayz{cos(\b)*sin(\t) - cos(\a)*sin(\b)*cos(\t)*sin(\p) + cos(\p)*sin(\a)*sin(\b)*cos(\t)}
59 | % Row 3: [\azx \azy \azz]
60 | \pgfmathsetmacro\azx{cos(\a)*cos(\b)*sin(\p)*sin(\t) - sin(\b)*cos(\t) - cos(\b)*cos(\p)*sin(\a)*sin(\t)}
61 | \pgfmathsetmacro\azy{-cos(\a)*cos(\p)*sin(\t) - sin(\a)*sin(\p)*sin(\t)}
62 | \pgfmathsetmacro\azz{cos(\b)*cos(\t) + cos(\a)*sin(\b)*sin(\p)*sin(\t) - cos(\p)*sin(\a)*sin(\b)*sin(\t)}
63 | }
64 |
65 | % ------------------------------------------------------------------------------
66 |
67 | \newcommand{\tdplotCsDrawCircle}[5][]{%
68 | % Draws a circle of a sphere.
69 | %
70 | % Input:
71 | % #1 - TikZ style
72 | % - use tdplotCsFront/.style={...} to style the front side arc
73 | % - use tdplotCsBack/.style={...} to style the back side arc
74 | % - use tdplotCsFill/.style={...} to style the circle filling
75 | % - use tdplotCsDrawAux to draw some auxiliary information
76 | % #2 - Radius of sphere
77 | % #3 - Azimuthal angle of drawing plane 1)
78 | % #4 - Polar angle of drawing plane 2)
79 | % #5 - Elevation angle of circle above the drawing plane. Permissible
80 | % values are -90 < #5 < 90. Use 0 for drawing a great circle.
81 | %
82 | % Ouput:
83 | % none
84 | %
85 | % Footnotes:
86 | % 1) passed as alpha to \tdplotsetrotatedcoords{alpha}{beta}{gamma}
87 | % 2) passed as beta to \tdplotsetrotatedcoords{alpha}{beta}{gamma}
88 | \begin{scope}[#1] % Macro scope >>
89 | % Do some computation # -----------------------------------
90 | \pgfmathsetmacro\r {#2} % Parse radius
91 | \pgfmathsetmacro\alp{#3} % Parse azimuthal angle (alpha)
92 | \pgfmathsetmacro\bet{#4} % Parse polar angle (beta)
93 | \pgfmathsetmacro\eps{#5} % Parse elevation angle (epsilon)
94 | \pgfmathsetmacro\re {\r*cos(\eps)} % Radius of circle
95 | \pgfmathsetmacro\ze {\r*sin(\eps)} % z-coordinate of drawing plane
96 | \pgfmathsetmacro\coX{\ze*cos(\alp)*sin(\bet)} % x-coordinate offset for ze
97 | \pgfmathsetmacro\coY{\ze*sin(\alp)*sin(\bet)} % y-coordinate offset for ze
98 | \pgfmathsetmacro\coZ{\ze*cos(\bet)} % z-coordinate offset for ze
99 | \coordinate (coffs) at (\coX,\coY,\coZ); % Offset as coordinate value
100 | % Rotate and offset coordinate system % -----------------------------------
101 | \tdplotsetrotatedcoords{\alp}{\bet}{0} % Rotate coordinate system
102 | \tdplotsetrotatedcoordsorigin{(coffs)} % Offset coordinate system
103 | % Draw % -----------------------------------
104 | \begin{scope}[tdplot_rotated_coords] % Drawing scope >>
105 | \tdplotCsComputeTransformRotScreen % Compute full rotation matrix
106 | \pgfmathsetmacro\tanEps{tan(\eps)} % Tangent of elevation angle
107 | \pgfmathsetmacro\bOneside{((\tanEps)^2)>=(((\azx)^2+(\azy)^2)/(\azz)^2)} % Circle entirely on one side?
108 | \ifthenelse{\isin{tdplotCsFill}{#1}}{ % Fill style passed >>
109 | \fill[tdplotCsFill] (0,0) circle (\re); % Draw filling of circle
110 | }{} % <<
111 | \ifthenelse{\bOneside=1}{ % Circle on one side of sphere >>
112 | \pgfmathsetmacro\bFrontside{(\azx*\re+\azz*\ze)>=0} % Circle entirely on front side?
113 | \ifthenelse{\bFrontside=1} % |
114 | {\draw[tdplotCsFront] (0,0) circle (\re);} % Draw on front side
115 | {\draw[tdplotCsBack] (0,0) circle (\re);} % Draw on back side
116 | }{ % << Circle on both sides >>
117 | \pgfmathsetmacro\u{\azy} % Substitution u=...
118 | \pgfmathsetmacro\v{sqrt( (\azx)^2 + (\azy)^2 - (\azz)^2*(\tanEps)^2 )} % Substitution v=...
119 | \pgfmathsetmacro\w{\azx - \azz*\tanEps} % Substitution w=...
120 | \pgfmathsetmacro\phiBf{2*atan2(\u-\v,\w)} % Back->front crossing angle
121 | \pgfmathsetmacro\phiFb{2*atan2(\u+\v,\w)} % Front->back crossing angle
122 | \pgfmathsetmacro\bUnwrapA{(\phiFb-\phiBf)>360} % Unwrap front->back angle #1?
123 | \pgfmathsetmacro\bUnwrapB{\phiBf>\phiFb} % Unwrap front->back angle #2?
124 | \ifthenelse{\bUnwrapA=1}{\pgfmathsetmacro\phiBf{\phiBf+360}}{} % Unwrap front->back angle #1
125 | \ifthenelse{\bUnwrapB=1}{\pgfmathsetmacro\phiBf{\phiBf-360}}{} % Unwrap front->back angle #2
126 | \draw[tdplotCsBack] (\phiFb:\re) arc (\phiFb:{\phiBf+360}:\re); % Draw back side arc
127 | \draw[tdplotCsFront] (\phiBf:\re) arc (\phiBf:\phiFb:\re); % Draw back side arc
128 | } % <<
129 | % Auxliliary drawing (for debugging and illustration) % - - - - - - - - - - - - - - - - -
130 | \ifthenelse{\isin{tdplotCsDrawAux}{#1}}{ % Auxiliary drawing activated >>
131 | \draw[red!40,->] (-\re,0,0) -- (\re,0,0) node[anchor=north] {$x_d$}; % x-axis of drawing corrd. system
132 | \draw[red!40,->] (0,-\re,0) -- (0,\re,0) node[anchor=north] {$y_d$}; % y-axis of drawing corrd. system
133 | \draw[red!40,->] (0,0,0) -- (0,0,\re) node[anchor=north] {$z_d$}; % z-axis of drawing corrd. system
134 | \ifthenelse{\bOneside=0}{ % Circ.on both sides of sphere >>
135 | \node[red] at (\phiBf:\re) {$\circ$}; % Indicate back-front crossing
136 | \node[red] at (\phiFb:\re) {$\times$}; % Indicate front-back crossing
137 | }{} % <<
138 | \coordinate (coffs) at (-\coX,-\coY,-\coZ); % HACK: Forcibly reset ...
139 | \tdplotsetrotatedcoordsorigin{(coffs)} % ... coordinate system
140 | \begin{scope}[tdplot_rotated_coords] % Aux. display scope >>
141 | \node[tdplot_screen_coords,red,anchor=north west] at (0.7*\r,-0.9*\r) % Make a litte display ...
142 | {\parbox{200pt}{\footnotesize % ... >>
143 | $\theta=\tdplotmaintheta^\circ, \phi=\tdplotmainphi^\circ$\\ % Main coord. sys. parameters
144 | $\alpha=\alp^\circ, \beta=\bet^\circ, % Rot. coord. sys. parameters
145 | \epsilon\!=\!\eps^\circ\!$\\ % Drawing plane elev. angle
146 | $a_{zx}=\azx, a_{zy}=\azy, a_{zz}=\azz$\\ % Elems. of full rot. matrix
147 | $r_e\!=\!\re, z_e\!=\!\ze$\\ % Radius and z-elevation
148 | $\texttt{\textbackslash bOneside}\!=\!\bOneside$, % One-side circle flag
149 | \ifthenelse{\bOneside=1}{ % One-side circle >>
150 | $\texttt{\textbackslash bFrontside}\!=\!\bFrontside$\\ % Front-side flag
151 | }{ % << Two-side circle >>
152 | $\texttt{\textbackslash bUnwrapA}\!=\!\bUnwrapA$, % Angle unwrap flag #1
153 | $\texttt{\textbackslash bUnwrapB}\!=\!\bUnwrapB$\\ % Angle unwrap flag #2
154 | $\circ\!: \!\texttt{\textbackslash phiBf}\!=\!\phiBf^\circ\!, % Back-front crossing angle
155 | \times\!:\!\texttt{\textbackslash phiFb}\!=\!\phiFb^\circ$\\ % Front-back crossing angle
156 | } % <<
157 | }}; % <<
158 | \end{scope} % << (Aux. display scope)
159 | }{} % << (Auxiliary drawing activated)
160 | \end{scope} % << (Drawing scope)
161 | \end{scope} % << (Macro scope)
162 | }
163 |
164 | % ------------------------------------------------------------------------------
165 |
166 | \newcommand{\tdplotCsDrawGreatCircle}[4][]{%
167 | % Draws a great circle.
168 | %
169 | % Input:
170 | % #1 - TikZ style
171 | % - use tdplotCsFront/.style={...} to style the front side arc
172 | % - use tdplotCsBack/.style={...} to style the back side arc
173 | % - use tdplotCsFill/.style={...} to style the circle filling
174 | % - use tdplotCsDrawAux to draw some auxiliary information
175 | % #2 - Radius of sphere
176 | % #3 - Azimuthal angle of drawing plane 1)
177 | % #4 - Polar angle of drawing plane 2)
178 | %
179 | % Ouput:
180 | % none
181 | %
182 | % Footnotes:
183 | % 1) passed as alpha to \tdplotsetrotatedcoords{alpha}{beta}{gamma}
184 | % 2) passed as beta to \tdplotsetrotatedcoords{alpha}{beta}{gamma}
185 | \tdplotCsDrawCircle[#1]{#2}{#3}{#4}{0}
186 | }
187 |
188 | % ------------------------------------------------------------------------------
189 |
190 | \newcommand{\tdplotCsDrawLatCircle}[3][]{%
191 | % Draws a circle of latitude.
192 | %
193 | % Input:
194 | % #1 - TikZ style
195 | % - use tdplotCsFront/.style={...} to style the front side arc
196 | % - use tdplotCsBack/.style={...} to style the back side arc
197 | % - use tdplotCsFill/.style={...} to style the circle filling
198 | % - use tdplotCsDrawAux to draw some auxiliary information
199 | % #2 - Radius of sphere
200 | % #3 - Elevation angle of circle above the drawing plane. Permissible
201 | % values are -90 < #5 < 90. Use 0 for drawing a great circle.
202 | %
203 | % Ouput:
204 | % none
205 | \tdplotCsDrawCircle[#1]{#2}{0}{0}{#3}
206 | }
207 |
208 | % ------------------------------------------------------------------------------
209 |
210 | \newcommand{\tdplotCsDrawLonCircle}[3][]{%
211 | % Draws a circle of longitude.
212 | %
213 | % Input:
214 | % #1 - TikZ style
215 | % - use tdplotCsFront/.style={...} to style the front side arc
216 | % - use tdplotCsBack/.style={...} to style the back side arc
217 | % - use tdplotCsFill/.style={...} to style the circle filling
218 | % - use tdplotCsDrawAux to draw some auxiliary information
219 | % #2 - Radius of sphere
220 | % #3 - Azimuthal angle of drawing plane 1)
221 | %
222 | % Ouput:
223 | % none
224 | %
225 | % Footnotes:
226 | % 1) passed as alpha to \tdplotsetrotatedcoords{alpha}{beta}{gamma}
227 | \tdplotCsDrawCircle[#1]{#2}{#3}{90}{0}
228 | }
229 |
230 | % ------------------------------------------------------------------------------
231 |
232 | \newcommand{\tdplotCsFrontsidePoint}{%
233 | % Invoked by \tdplotCsDrawPoint to draw a point on the front side of a sphere.
234 | % Redefine to customize.
235 | \textbullet%
236 | }
237 |
238 | % ------------------------------------------------------------------------------
239 |
240 | \newcommand{\tdtlotCsBacksidePoint}{%
241 | % Invoked by \tdplotCsDrawPoint to draw a point on the back side of a sphere.
242 | % Redefine to customize.
243 | $\circ$%
244 | }
245 |
246 | % ------------------------------------------------------------------------------
247 |
248 | \newcommand{\tdplotCsDrawPoint}[4][]{%
249 | % Draws a point on a sphere.
250 | %
251 | % Input:
252 | % #1 - TikZ style
253 | % - use tdplotPtFront/.style={...} to style a front side point
254 | % - use tdplotPtBack/.style={...} to style a back side point
255 | % #2 - Radius of sphere
256 | % #3 - Azimuthal angle of drawing plane 1)
257 | % #4 - Polar angle of drawing plane 2)
258 | %
259 | % Ouput:
260 | % none
261 | %
262 | % Remarks:
263 | % - Redefine \tdplotCsFrontsidePoint to customize drawing of a front side
264 | % point.
265 | % - Redefine \tdplotCsBacksidePoint to customize drawing of a back side
266 | % point.
267 | %
268 | % Footnotes:
269 | % 1) passed as alpha to \tdplotsetrotatedcoords{alpha}{beta}{gamma}
270 | % 2) passed as beta to \tdplotsetrotatedcoords{alpha}{beta}{gamma}
271 | \begin{scope}[#1] % Macro scope >>
272 | \pgfmathsetmacro{\r}{#2} % Parse radius
273 | \pgfmathsetmacro{\alp}{#3} % Parse alpha angle
274 | \pgfmathsetmacro{\bet}{#4} % Parse beta angle
275 | \tdplotsetrotatedcoords{\alp}{\bet}{0} % Set rotated coord. system
276 | \begin{scope}[tdplot_rotated_coords] % Draw in rotated coord. system >>
277 | \tdplotCsComputeTransformRotScreen % Get \azz
278 | \pgfmathsetmacro{\bVisible}{\azz>0} % Test if point is on visible side
279 | \ifthenelse{\bVisible=1}{% % Point on front side >>
280 | \node[tdplotPtFront] at (0,0,\r) {\tdplotCsFrontsidePoint}; % Draw it
281 | }{% % << Point on back side >>
282 | \node[tdplotPtBack] at (0,0,\r) {\tdtlotCsBacksidePoint}; % Draw it
283 | } % <<
284 | \end{scope} % <<
285 | \end{scope} % <<
286 | }
287 |
288 | %% == EOF =====================================================================
289 |
--------------------------------------------------------------------------------
/tikz-3dplot-circleofsphere.tex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matthias-wolff/tikz-3dplot-circleofsphere/b17ac11510c744f7e82e6674bfccc6617c7c0060/tikz-3dplot-circleofsphere.tex
--------------------------------------------------------------------------------
/tikz_3dplot_circleofsphere.m:
--------------------------------------------------------------------------------
1 | %% == LaTeX PACKAGE tikz-3dplot-circleofsphere ================================
2 | % Drawing circles of a sphere with tikz-3dplot
3 | %
4 | % Matthias Wolff, BTU Cottbus-Sentenberg
5 | % July 26, 2018
6 | %
7 | % References:
8 | % [1] J. Hein. The tikz-3dplot package. 2012. Online, retrieved July 20, 2018.
9 | % https://mirror.hmc.edu/ctan/graphics/pgf/contrib/tikz-3dplot/tikz-3dplot_documentation.pdf
10 | %
11 |
12 | %% Rotation matrices ==========================================================
13 | syms a b p t
14 |
15 | % R rotation matrix -----------------------------------------------------------
16 | Rz = [ cos(p) -sin(p) 0
17 | sin(p) cos(p) 0
18 | 0 0 1 ];
19 |
20 | Rx = [ 1 0 0
21 | 0 cos(t) -sin(t)
22 | 0 sin(t) cos(t) ];
23 |
24 | % - [1] eq. (2.1) line 2
25 | % R = Rz*Rx; disp(R);
26 |
27 | % - [1] eq. (2.1) line 3
28 | % R = [ cos(p) sin(p) 0
29 | % -cos(t)*sin(p) cos(t)*cos(p) -sin(t)
30 | % sin(t)*sin(p) -sin(t)*cos(p) cos(t) ];
31 |
32 | % - [1] eq. (2.1) line 3, corrected
33 | R = (Rz*Rx).';
34 |
35 | % -- D rotation matrix --------------------------------------------------------
36 | Dz = [ cos(a) -sin(a) 0
37 | sin(a) cos(a) 0
38 | 0 0 1 ];
39 |
40 | Dy = [ cos(b) 0 sin(b)
41 | 0 1 0
42 | -sin(b) 0 cos(b) ];
43 |
44 | Dx = [ 1 0 0
45 | 0 cos(b) -sin(b)
46 | 0 sin(b) cos(b) ];
47 |
48 | D = Dz*Dy; disp(D);
49 |
50 | % -- Full rotation matrix -----------------------------------------------------
51 | A = R*D; disp(A);
52 | axx = A(1,1); axy = A(1,2); axz = A(1,3);
53 | ayx = A(2,1); ayy = A(2,2); ayz = A(2,3);
54 | azx = A(3,1); azy = A(3,2); azz = A(3,3);
55 |
56 | %% == Transform a vector (world -> screen) ====================================
57 | syms x y z
58 | p = [ x
59 | y
60 | z ];
61 | q=A*p;
62 | disp(q);
63 |
64 | %% == View angle ==============================================================
65 | syms p0 r eps azx azy azz
66 | assume(p0,'real');
67 | assume(r,'real');
68 | assume(eps,'real');
69 | assume(azx,'real');
70 | assume(azy,'real');
71 | assume(azz,'real');
72 | eqn = azx*r*cos(eps)*cos(p0) + azy*r*cos(eps)*sin(p0) + azz*r*sin(eps) == 0
73 | solve(eqn,p0,'Real',true)
74 |
75 | %% == EOF =====================================================================
--------------------------------------------------------------------------------