| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: sunpath.dtx Copyright (C) 2024 Hong-Phuc Bui |
| 4 |
% |
| 5 |
% It may be distributed and/or modified under the conditions of the |
| 6 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 7 |
% license or (at your option) any later version. The latest version |
| 8 |
% of this license is in the file |
| 9 |
% |
| 10 |
% https://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% |
| 13 |
% ----------------------------------------------------------------------- |
| 14 |
% |
| 15 |
% The development version of the bundle can be found at |
| 16 |
% |
| 17 |
% https://github.com/hpb-htw/sunpath |
| 18 |
% |
| 19 |
% for those people who are interested. |
| 20 |
% |
| 21 |
% ----------------------------------------------------------------------- |
| 22 |
% \fi |
| 23 |
% |
| 24 |
% ^^A To get version of latex run: |
| 25 |
% ^^A `latex '\typeout{\fmtversion}\stop' | grep LaTeX2e` |
| 26 |
% |
| 27 |
% \iffalse |
| 28 |
%<package>\NeedsTeXFormat{LaTeX2e}[2022/11/01] |
| 29 |
%<package>\ProvidesPackage{sunpath}[2024/10/20 v0.5 Draw Sun Path] |
| 30 |
% \fi |
| 31 |
|
| 32 |
% \changes{v0.5} |
| 33 |
% {2024/10/20} |
| 34 |
% {replace prefix "draw" in exposed commands by "sp"} |
| 35 |
% \changes{v0.4-Alpha} |
| 36 |
% {2024/10/20} |
| 37 |
% {rename option altitude projection to altitude mapping} |
| 38 |
% \changes{v0.3-Alpha} |
| 39 |
% {2024/10/16} |
| 40 |
% {add style option in exposed commands; |
| 41 |
% let build.lua read version information from sunpath.dtx file} |
| 42 |
% |
| 43 |
% \changes{v0.2-Alpha} |
| 44 |
% {2024/10/16} |
| 45 |
% {Small fixes in README.md and document} |
| 46 |
% |
| 47 |
% \changes{v0.1-Alpha} |
| 48 |
% {2024/10/10} |
| 49 |
% {Initial implementation} |
| 50 |
|
| 51 |
|
| 52 |
% \section{Implementation} |
| 53 |
% |
| 54 |
% \subsection{Package Dependenies} |
| 55 |
% |
| 56 |
% \begin{macrocode} |
| 57 |
\RequirePackage{expl3} |
| 58 |
\RequirePackage{tikz} |
| 59 |
% \end{macrocode} |
| 60 |
% |
| 61 |
% Load necsessary \texttt{tikz}-libraries. |
| 62 |
% \begin{macrocode} |
| 63 |
\usetikzlibrary{calc,math,through} |
| 64 |
% \end{macrocode} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
% \subsection{\texttt{tikz}-Options for the new coordinate system} |
| 70 |
% Setup options for \texttt{tikzpicture} environment. |
| 71 |
% |
| 72 |
% \DescribeMacro{spradius} The radius of the 0° Altitude circle, default 5.5. |
| 73 |
% This value can be accessed via macro \verb:\spradius:. |
| 74 |
% |
| 75 |
% \DescribeMacro{altitude mapping} |
| 76 |
% How the altitude of the sun is mapped on the sunpath diagram. |
| 77 |
% This mapping is a function $f(\theta): [-90,90] \to [0, r]$, where $r$ is saved in \verb|\spradius|. |
| 78 |
% |
| 79 |
% Valid values are \texttt{spherical} and \texttt{equidistance}. |
| 80 |
% Its default value is \texttt{spherical}. |
| 81 |
% |
| 82 |
% This value can be accessed via macro \verb:\altmapping:. |
| 83 |
|
| 84 |
% These options can be used like: |
| 85 |
% |
| 86 |
% \begin{verbatim} |
| 87 |
% \begin{tikzpicture}[spradius=6,altitude projection=equidistance] |
| 88 |
% \coordinate (sunrise) at (sunpath cs:azi=105, alt=66.6); |
| 89 |
% \end{tikzpicture} |
| 90 |
% \end{verbatim} |
| 91 |
% |
| 92 |
% \begin{macrocode} |
| 93 |
\pgfkeys{/tikz/.cd, |
| 94 |
spradius/.store in=\spradius, |
| 95 |
spradius=5.5, |
| 96 |
altitude mapping/.store in = \altmapping, |
| 97 |
altitude mapping=spherical |
| 98 |
} |
| 99 |
% \end{macrocode} |
| 100 |
% |
| 101 |
|
| 102 |
|
| 103 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 104 |
% \subsection{Define the new coordinate system \texttt{sunpath}} |
| 105 |
\makeatletter |
| 106 |
|
| 107 |
% \subsubsection{Azimuth and altitude} |
| 108 |
% Define component \texttt{azi} (=Azimuth angle) and \texttt{alt} (=Altidude angle) for the coordinate system \texttt{sunpath}. |
| 109 |
% \begin{macrocode} |
| 110 |
\tikzset{ |
| 111 |
cs/azi/.store in=\tikz@cs@azi, |
| 112 |
cs/alt/.store in=\tikz@cs@alt, |
| 113 |
} |
| 114 |
% \end{macrocode} |
| 115 |
|
| 116 |
|
| 117 |
% \subsubsection{Projection functions} |
| 118 |
% Funtions to map the atitude of the sun to the altitude value on the sun path diagram. |
| 119 |
% |
| 120 |
% \DescribeMacro{spherical} |
| 121 |
% maps an altitude angle $\theta$ to the altitude radius on the diagram with the function |
| 122 |
% \[s (\theta) = r \cos(\theta). \] |
| 123 |
% |
| 124 |
% \DescribeMacro{equidistance} |
| 125 |
% maps an altitude angle $\theta$ to the altitude radius on the diagram with the function |
| 126 |
% \[e (\theta) = r - r \cdot \frac{\left\lvert \theta \right\rvert}{90}. \] |
| 127 |
% |
| 128 |
% \DescribeMacro{altradius} |
| 129 |
% this function is used in the coordinate system \texttt{sunpath} to determinate the altitude |
| 130 |
% radius of an azimuth angle on the sun path chart. |
| 131 |
% It depends on the value of the option \verb:altitude projection:. |
| 132 |
% |
| 133 |
% |
| 134 |
% \DescribeMacro{aziangle} |
| 135 |
% maps the azimuth angle $\Phi$ to the azimuth angle on the diagram with the function |
| 136 |
% \[ a(\Phi) = 90 - \Phi. \] |
| 137 |
% \begin{macrocode} |
| 138 |
\tikzset{ |
| 139 |
declare function = { |
| 140 |
spherical(\alt) = \spradius * cos(\alt); |
| 141 |
equidistance(\alt) = \spradius - \spradius*abs(\alt)/90; |
| 142 |
altradius(\alt) = \altmapping(\alt); |
| 143 |
aziangle(\x) = 90 - \x; |
| 144 |
} |
| 145 |
} |
| 146 |
% \end{macrocode} |
| 147 |
% |
| 148 |
|
| 149 |
|
| 150 |
% \subsubsection{Coordinate system \texttt{sunpath}} |
| 151 |
% \begin{macrocode} |
| 152 |
\tikzdeclarecoordinatesystem{sunpath}% |
| 153 |
{ |
| 154 |
\tikzset{cs/.cd,azi=0,alt=0,#1} |
| 155 |
\tikzmath{ |
| 156 |
\r = altradius(\tikz@cs@alt); |
| 157 |
\angle = aziangle(\tikz@cs@azi); |
| 158 |
} |
| 159 |
\pgfpointadd{\pgfpointxy{0}{0}}{% |
| 160 |
\pgfpointpolarxy{\angle}{\r} |
| 161 |
} |
| 162 |
} |
| 163 |
% \end{macrocode} |
| 164 |
\makeatother |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 169 |
% \subsection{Setup optical options for sunpath diagram} |
| 170 |
% These are pre-defined \TikZ{} style for components of the chart. They can be easily changed by using \cmd{\tikzset}. |
| 171 |
% |
| 172 |
% \DescribeMacro{sunpath grid} \tikz{\draw [sunpath grid] (0,0) -- (1,0);} style for azimuth lines and altitude circles |
| 173 |
% |
| 174 |
% \DescribeMacro{sunpath tick} \tikz{\draw [sunpath tick] (0,0) -- (4pt,0);} style for ticks around the horizon line |
| 175 |
% |
| 176 |
% \DescribeMacro{sunpath minor tick} \tikz{\draw [sunpath minor tick] (0,0) -- (4pt,0);} style for minor ticks around horizon line |
| 177 |
% |
| 178 |
% \DescribeMacro{altitude label} \tikz{\node[altitude label] {80};} |
| 179 |
% |
| 180 |
% \DescribeMacro{azimuth label} \tikz{\node[altitude label] {350};} style for text label of altitude circle respective azimuth line |
| 181 |
% |
| 182 |
% \DescribeMacro{direction label} \tikz{\node[direction label] {N E S W}; } style for text label of four directions |
| 183 |
% |
| 184 |
% \begin{macrocode} |
| 185 |
\tikzset{ |
| 186 |
sunpath grid/.style={help lines,color=blue!45!white!80}, |
| 187 |
sunpath tick/.style={draw,thick,color=blue!90!white!80}, |
| 188 |
sunpath minor tick/.style={draw,thin,color=blue!90!white!80}, |
| 189 |
altitude label/.style={ |
| 190 |
font=\footnotesize\sffamily, |
| 191 |
fill=white,minimum width={width("90")+2pt}, |
| 192 |
inner sep=0.5pt |
| 193 |
}, |
| 194 |
azimuth label/.style={ |
| 195 |
font=\footnotesize\sffamily, |
| 196 |
minimum width={width("360")+2pt}, |
| 197 |
inner sep=0.5pt |
| 198 |
}, |
| 199 |
direction label/.style={ |
| 200 |
font=\normalsize\rmfamily |
| 201 |
} |
| 202 |
} |
| 203 |
% \end{macrocode} |
| 204 |
|
| 205 |
|
| 206 |
% \subsection{Expose some commands for end-user} |
| 207 |
|
| 208 |
% \DescribeMacro{\spcrosshair} \oarg{style} |
| 209 |
% |
| 210 |
% Draws a thin line from North to South and a thin line from East to West. |
| 211 |
% Default value of \oarg{style} is \texttt{sunpath grid}. |
| 212 |
% |
| 213 |
% \begin{macrocode} |
| 214 |
\NewDocumentCommand\spcrosshair{O{sunpath grid}}{ |
| 215 |
\draw[#1] (-\spradius,0) -- (\spradius,0); |
| 216 |
\draw[#1] (0,-\spradius) -- (0,\spradius); |
| 217 |
} |
| 218 |
% \end{macrocode} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
% \DescribeMacro{\spgeodirection} \oarg{offset}\oarg{style} |
| 224 |
% |
| 225 |
% |
| 226 |
% Puts four geographic directions North, East, South, West around the horinzon line. |
| 227 |
% \oarg{offset} is the distance from horizon to the \TikZ{} node of the directions. |
| 228 |
% Its default value is 22pt. |
| 229 |
% Set it to zero causes that the directions are set very near to the horizon line. |
| 230 |
% \begin{macrocode} |
| 231 |
\NewDocumentCommand\spgeodirection{O{22pt} O{direction label}}{ |
| 232 |
\foreach \dname / \dgrad in {N/0, E/90, S/180, W/270}{ |
| 233 |
\tikzmath{ |
| 234 |
\polarangle = aziangle(\dgrad); |
| 235 |
} |
| 236 |
\coordinate (D) at (\polarangle:\spradius cm + #1); |
| 237 |
\node[#2,anchor=270-\dgrad] at (D) {\dname}; |
| 238 |
} |
| 239 |
} |
| 240 |
% \end{macrocode} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
% \DescribeMacro{\spaltitudecircle} \marg{range}\oarg{style} |
| 246 |
% |
| 247 |
% Draws altitude circle given by \marg{range}. |
| 248 |
% The argument \marg{range} must be a valid \TikZ-range, which can be used in \cmd{\foreach}. |
| 249 |
% For example \verb|{{10,20,...,80,85}}|. |
| 250 |
% The argument \oarg{style} define the style of altitude circles, default is \texttt{sunpath~grid}. |
| 251 |
% \begin{macrocode} |
| 252 |
\NewDocumentCommand\spaltitudecircle{m O{sunpath grid}}{ |
| 253 |
\foreach \altitude in #1 { |
| 254 |
\coordinate (A) at (sunpath cs:azi=0,alt=\altitude) ; |
| 255 |
\path[draw,sunpath grid] (0,0) circle[radius=altradius(\altitude)]; |
| 256 |
} |
| 257 |
} |
| 258 |
% \end{macrocode} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
% \DescribeMacro{\spaltitudelabel} \marg{range}\oarg{azimuth}\oarg{style} |
| 264 |
% |
| 265 |
% Draws the labels of altitude circles given by \marg{range}. |
| 266 |
% Range must be an in \TikZ{} valid numeric range which can be used in \cmd{\foreach}. |
| 267 |
% For example \verb|{{10,20,...,80}}| |
| 268 |
% The labels are placed along the azimuth \oarg{azimuth} (default 135) |
| 269 |
% and typeset with style \oarg{style} (default \texttt{altitude label}). |
| 270 |
% |
| 271 |
% \begin{macrocode} |
| 272 |
\NewDocumentCommand\spaltitudelabel{m O{135} O{altitude label}}{ |
| 273 |
\foreach \altitude in #1 { |
| 274 |
\coordinate (A) at (sunpath cs:azi=#2,alt=\altitude) ; |
| 275 |
\node [anchor=east,#3] at (A) {\altitude}; |
| 276 |
} |
| 277 |
} |
| 278 |
% \end{macrocode} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
% \DescribeMacro{\spazimuthlabel} \marg{range}\oarg{style} |
| 284 |
% |
| 285 |
% \begin{macrocode} |
| 286 |
\NewDocumentCommand\spazimuthlabel{m O{azimuth label}}{ |
| 287 |
\foreach \azimuth in #1 { |
| 288 |
\tikzmath{ |
| 289 |
\polarangle = aziangle(\azimuth); |
| 290 |
} |
| 291 |
\coordinate (D) at (\polarangle:\spradius cm + 13pt); |
| 292 |
\node[#2] at (D) {\azimuth}; |
| 293 |
} |
| 294 |
} |
| 295 |
% \end{macrocode} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
% \DescribeMacro{\spazimuthline} \marg{range}\marg{start~alt}\marg{end~alt} |
| 301 |
% |
| 302 |
% \begin{macrocode} |
| 303 |
\NewDocumentCommand\spazimuthline{m m m}{ |
| 304 |
\foreach \azimuth in #1{ |
| 305 |
\draw[sunpath grid] |
| 306 |
(sunpath cs:azi=\azimuth,alt={#2}) -- (sunpath cs:azi=\azimuth,alt={#3}); |
| 307 |
} |
| 308 |
} |
| 309 |
% \end{macrocode} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
% \DescribeMacro{\spazimuthtick} \oarg{major}\oarg{minor}\oarg{mid} |
| 315 |
% |
| 316 |
% Draws ticks along and outside the horizon circle. The optional arguments \oarg{major}, |
| 317 |
% \oarg{minor} and \oarg{mid} are the length of major ticks (every 10° from Zero), |
| 318 |
% minor ticks (every 1°, from 1°) and the length of the middle ticks (every 30°, from 15°). |
| 319 |
% Their default values are 6pt, 2.5pt and 5pt. |
| 320 |
% |
| 321 |
% \begin{macrocode} |
| 322 |
\NewDocumentCommand\spazimuthtick{O{6pt} O{2.5pt} O{5pt}}{ |
| 323 |
\foreach \azimuth in {10,20,...,360}{ |
| 324 |
\tikzmath{ |
| 325 |
\pa = aziangle(\azimuth); |
| 326 |
} |
| 327 |
\path[sunpath tick] (\pa:\spradius) -- (\pa:{\spradius cm + #1}); |
| 328 |
} |
| 329 |
|
| 330 |
\foreach \azimuth in {1,2,...,360}{ |
| 331 |
\tikzmath{ |
| 332 |
\pa = aziangle(\azimuth); |
| 333 |
} |
| 334 |
\path[sunpath minor tick] (\pa:\spradius) -- (\pa:{\spradius cm + #2}); |
| 335 |
} |
| 336 |
|
| 337 |
\foreach \azimuth in {15,45,...,345}{ |
| 338 |
\tikzmath{ |
| 339 |
\pa = aziangle(\azimuth); |
| 340 |
} |
| 341 |
\path[sunpath minor tick] (\pa:\spradius) -- (\pa:{\spradius cm + #3}); |
| 342 |
} |
| 343 |
} |
| 344 |
% \end{macrocode} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
%%%%%%%%%%%%%% |
| 350 |
\endinput |
| 351 |
%%%%%%%%%%%%%% |
| 352 |
|
| 353 |
|