summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/sunpath/sunpath.sty
blob: d9efce39ce8a2c8b2b8642e8e6a7d990a4ba4de5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
%%
%% This is file `sunpath.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% sunpath.dtx  (with options: `package')
%% 
\NeedsTeXFormat{LaTeX2e}[2022/11/01]
\ProvidesPackage{sunpath}[2024/10/20 v0.5 Draw Sun Path]


\RequirePackage{expl3}
\RequirePackage{tikz}
\usetikzlibrary{calc,math,through}


\pgfkeys{/tikz/.cd,
  spradius/.store in=\spradius,
  spradius=5.5,
  altitude mapping/.store in = \altmapping,
  altitude mapping=spherical
}

\makeatletter

\tikzset{
  cs/azi/.store in=\tikz@cs@azi,
  cs/alt/.store in=\tikz@cs@alt,
}

\tikzset{
  declare function = {
      spherical(\alt) = \spradius * cos(\alt);
      equidistance(\alt) = \spradius - \spradius*abs(\alt)/90;
      altradius(\alt) = \altmapping(\alt);
      aziangle(\x) = 90 - \x;
  }
}

\tikzdeclarecoordinatesystem{sunpath}%
{
    \tikzset{cs/.cd,azi=0,alt=0,#1}
    \tikzmath{
      \r = altradius(\tikz@cs@alt);
      \angle = aziangle(\tikz@cs@azi);
    }
    \pgfpointadd{\pgfpointxy{0}{0}}{%
        \pgfpointpolarxy{\angle}{\r}
    }
}
\makeatother

\tikzset{
  sunpath grid/.style={help lines,color=blue!45!white!80},
  sunpath tick/.style={draw,thick,color=blue!90!white!80},
  sunpath minor tick/.style={draw,thin,color=blue!90!white!80},
  altitude label/.style={
      font=\footnotesize\sffamily,
      fill=white,minimum width={width("90")+2pt},
      inner sep=0.5pt
  },
  azimuth label/.style={
      font=\footnotesize\sffamily,
      minimum width={width("360")+2pt},
      inner sep=0.5pt
  },
  direction label/.style={
      font=\normalsize\rmfamily
  }
}


\NewDocumentCommand\spcrosshair{O{sunpath grid}}{
    \draw[#1] (-\spradius,0) -- (\spradius,0);
    \draw[#1] (0,-\spradius) -- (0,\spradius);
}

\NewDocumentCommand\spgeodirection{O{22pt} O{direction label}}{
  \foreach \dname / \dgrad in {N/0, E/90, S/180, W/270}{
      \tikzmath{
        \polarangle = aziangle(\dgrad);
      }
      \coordinate (D) at (\polarangle:\spradius cm + #1);
      \node[#2,anchor=270-\dgrad] at (D) {\dname};
  }
}

\NewDocumentCommand\spaltitudecircle{m O{sunpath grid}}{
  \foreach \altitude in #1 {
    \coordinate (A) at (sunpath cs:azi=0,alt=\altitude) ;
    \path[draw,sunpath grid] (0,0) circle[radius=altradius(\altitude)];
  }
}

\NewDocumentCommand\spaltitudelabel{m O{135} O{altitude label}}{
  \foreach \altitude in #1 {
      \coordinate (A) at (sunpath cs:azi=#2,alt=\altitude) ;
      \node [anchor=east,#3] at (A) {\altitude};
    }
}

\NewDocumentCommand\spazimuthlabel{m O{azimuth label}}{
  \foreach \azimuth in #1 {
      \tikzmath{
        \polarangle = aziangle(\azimuth);
      }
      \coordinate (D) at (\polarangle:\spradius cm + 13pt);
      \node[#2] at (D) {\azimuth};
  }
}

\NewDocumentCommand\spazimuthline{m m m}{
  \foreach \azimuth in #1{
      \draw[sunpath grid]
        (sunpath cs:azi=\azimuth,alt={#2}) -- (sunpath cs:azi=\azimuth,alt={#3});
  }
}

\NewDocumentCommand\spazimuthtick{O{6pt} O{2.5pt} O{5pt}}{
  \foreach \azimuth in {10,20,...,360}{
    \tikzmath{
        \pa = aziangle(\azimuth);
    }
    \path[sunpath tick] (\pa:\spradius) -- (\pa:{\spradius cm + #1});
  }

  \foreach \azimuth in {1,2,...,360}{
    \tikzmath{
        \pa = aziangle(\azimuth);
    }
    \path[sunpath minor tick] (\pa:\spradius) -- (\pa:{\spradius cm + #2});
  }

  \foreach \azimuth in {15,45,...,345}{
      \tikzmath{
          \pa = aziangle(\azimuth);
      }
      \path[sunpath minor tick] (\pa:\spradius) -- (\pa:{\spradius cm + #3});
    }
}

%%%%%%%%%%%%%%
%% Copyright (C) 2024 by
%%   Hong-Phuc Bui
%% 
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version.  The latest
%% version of this license is in the file:
%% 
%%    https://www.latex-project.org/lppl.txt
%% 
%% 
%% This work consists of the files sunpath.dtx,
%%                                 sunpath.ins,
%%           and the derived files sunpath.pdf,
%%                                 sunpath.sty.
%% 
%%
%% End of file `sunpath.sty'.