| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3draw-points.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2018-2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% http://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "l3experimental bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/latex3 |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\RequirePackage{expl3} |
| 27 |
\documentclass[full]{l3doc} |
| 28 |
\begin{document} |
| 29 |
\DocInput{\jobname.dtx} |
| 30 |
\end{document} |
| 31 |
%</driver> |
| 32 |
% \fi |
| 33 |
% |
| 34 |
% \title{^^A |
| 35 |
% The \pkg{l3draw-points} package\\ Calculating points^^A |
| 36 |
% } |
| 37 |
% |
| 38 |
% \author{^^A |
| 39 |
% The \LaTeX{} Project\thanks |
| 40 |
% {^^A |
| 41 |
% E-mail: |
| 42 |
% \href{mailto:[email protected]} |
| 43 |
% {[email protected]}^^A |
| 44 |
% }^^A |
| 45 |
% } |
| 46 |
% |
| 47 |
% \date{Released 2026-05-26} |
| 48 |
% |
| 49 |
% \maketitle |
| 50 |
% |
| 51 |
% \begin{implementation} |
| 52 |
% |
| 53 |
% \section{\pkg{l3draw-points} implementation} |
| 54 |
% |
| 55 |
% \begin{macrocode} |
| 56 |
%<*package> |
| 57 |
% \end{macrocode} |
| 58 |
% |
| 59 |
% \begin{macrocode} |
| 60 |
%<@@=draw> |
| 61 |
% \end{macrocode} |
| 62 |
% |
| 63 |
% This sub-module covers more-or-less the same ideas as |
| 64 |
% \texttt{pgfcorepoints.code.tex}, though the approach taken to returning |
| 65 |
% values is different: point expressions here are processed by expansion |
| 66 |
% and return a coordinate pair in the form |{|\meta{x}|}{|\meta{y}|}|. |
| 67 |
% Equivalents of following \pkg{pgf} functions are deliberately omitted: |
| 68 |
% \begin{itemize} |
| 69 |
% \item \cs{pgfpointorigin}: Can be given explicitly as |0pt,0pt|. |
| 70 |
% \item \cs{pgfpointadd}, \cs{pgfpointdiff}, |
| 71 |
% \cs{pgfpointscale}: Can be given explicitly. |
| 72 |
% \item \cs{pgfextractx}, \cs{pgfextracty}: Available by applying |
| 73 |
% \cs{use_i:nn}/\cs{use_ii:nn} or similar to the \texttt{e}-type |
| 74 |
% expansion of a point expression. |
| 75 |
% \item \cs{pgfgetlastxy}: Unused in the entire \pkg{pgf} core, may be |
| 76 |
% emulated by \texttt{e}-type expansion of a point expression, then using |
| 77 |
% the result. |
| 78 |
% \end{itemize} |
| 79 |
% In addition, equivalents of the following \emph{may} be added in future but |
| 80 |
% are currently absent: |
| 81 |
% \begin{itemize} |
| 82 |
% \item \cs{pgfpointcylindrical}, \cs{pgfpointspherical}: The usefulness |
| 83 |
% of these commands is not currently clear. |
| 84 |
% \item \cs{pgfpointborderrectangle}, \cs{pgfpointborderellipse}: To be |
| 85 |
% revisited once the semantics and use cases are clear. |
| 86 |
% \item \cs{pgfqpoint}, \cs{pgfqpointscale}, \cs{pgfqpointpolar}, |
| 87 |
% \cs{pgfqpointxy}, \cs{pgfqpointxyz}: The expandable approach taken in |
| 88 |
% the code here, along with the absolute requirement for \eTeX{}, means |
| 89 |
% it is likely many use cases for these commands may be covered in other |
| 90 |
% ways. This may be revisited as higher-level structures are constructed. |
| 91 |
% \end{itemize} |
| 92 |
% |
| 93 |
% \subsection{Support functions} |
| 94 |
% |
| 95 |
% \begin{macro}[EXP]{\@@_point_process:nn} |
| 96 |
% \begin{macro}[EXP]{\@@_point_process_auxi:nn, \@@_point_process_auxi:en} |
| 97 |
% \begin{macro}[EXP]{\@@_point_process_auxii:nw} |
| 98 |
% \begin{macro}[EXP]{\@@_point_process:nnn} |
| 99 |
% \begin{macro}[EXP]{\@@_point_process_auxiii:nnn, \@@_point_process_auxiii:een} |
| 100 |
% \begin{macro}[EXP]{\@@_point_process_auxiv:nw} |
| 101 |
% \begin{macro}[EXP]{\@@_point_process:nnnn} |
| 102 |
% \begin{macro}[EXP] |
| 103 |
% {\@@_point_process_auxv:nnnn, \@@_point_process_auxv:eeen} |
| 104 |
% \begin{macro}[EXP]{\@@_point_process_auxvi:nw} |
| 105 |
% \begin{macro}[EXP]{\@@_point_process:nnnnn} |
| 106 |
% \begin{macro}[EXP] |
| 107 |
% {\@@_point_process_auxvii:nnnnn, \@@_point_process_auxvii:eeeen} |
| 108 |
% \begin{macro}[EXP]{\@@_point_process_auxviii:nw} |
| 109 |
% Execute whatever code is passed to extract the $x$ and $y$ coordinates. |
| 110 |
% The first argument here should itself absorb two arguments. There is |
| 111 |
% also a version to deal with two coordinates: common enough to justify a |
| 112 |
% separate function. |
| 113 |
% \begin{macrocode} |
| 114 |
\cs_new:Npn \@@_point_process:nn #1#2 |
| 115 |
{ \@@_point_process_auxi:en {#2} {#1} } |
| 116 |
\cs_new:Npn \@@_point_process_auxi:nn #1#2 |
| 117 |
{ \@@_point_process_auxii:nw {#2} #1 \s_@@_stop } |
| 118 |
\cs_generate_variant:Nn \@@_point_process_auxi:nn { e } |
| 119 |
\cs_new:Npn \@@_point_process_auxii:nw #1 #2 , #3 \s_@@_stop |
| 120 |
{ #1 {#2} {#3} } |
| 121 |
\cs_new:Npn \@@_point_process:nnn #1#2#3 |
| 122 |
{ \@@_point_process_auxiii:een {#2} {#3} {#1} } |
| 123 |
\cs_new:Npn \@@_point_process_auxiii:nnn #1#2#3 |
| 124 |
{ \@@_point_process_auxiv:nw {#3} #1 \s_@@_mark #2 \s_@@_stop } |
| 125 |
\cs_generate_variant:Nn \@@_point_process_auxiii:nnn { ee } |
| 126 |
\cs_new:Npn \@@_point_process_auxiv:nw #1 #2 , #3 \s_@@_mark #4 , #5 \s_@@_stop |
| 127 |
{ #1 {#2} {#3} {#4} {#5} } |
| 128 |
\cs_new:Npn \@@_point_process:nnnn #1#2#3#4 |
| 129 |
{ \@@_point_process_auxv:eeen {#2} {#3} {#4} {#1} } |
| 130 |
\cs_new:Npn \@@_point_process_auxv:nnnn #1#2#3#4 |
| 131 |
{ \@@_point_process_auxvi:nw {#4} #1 \s_@@_mark #2 \s_@@_mark #3 \s_@@_stop } |
| 132 |
\cs_generate_variant:Nn \@@_point_process_auxv:nnnn { eee } |
| 133 |
\cs_new:Npn \@@_point_process_auxvi:nw |
| 134 |
#1 #2 , #3 \s_@@_mark #4 , #5 \s_@@_mark #6 , #7 \s_@@_stop |
| 135 |
{ #1 {#2} {#3} {#4} {#5} {#6} {#7} } |
| 136 |
\cs_new:Npn \@@_point_process:nnnnn #1#2#3#4#5 |
| 137 |
{ \@@_point_process_auxvii:eeeen {#2} {#3} {#4} {#5} {#1} } |
| 138 |
\cs_new:Npn \@@_point_process_auxvii:nnnnn #1#2#3#4#5 |
| 139 |
{ |
| 140 |
\@@_point_process_auxviii:nw |
| 141 |
{#5} #1 \s_@@_mark #2 \s_@@_mark #3 \s_@@_mark #4 \s_@@_stop |
| 142 |
} |
| 143 |
\cs_generate_variant:Nn \@@_point_process_auxvii:nnnnn { eeee } |
| 144 |
\cs_new:Npn \@@_point_process_auxviii:nw |
| 145 |
#1 #2 , #3 \s_@@_mark #4 , #5 \s_@@_mark #6 , #7 \s_@@_mark #8 , #9 \s_@@_stop |
| 146 |
{ #1 {#2} {#3} {#4} {#5} {#6} {#7} {#8} {#9} } |
| 147 |
% \end{macrocode} |
| 148 |
% \end{macro} |
| 149 |
% \end{macro} |
| 150 |
% \end{macro} |
| 151 |
% \end{macro} |
| 152 |
% \end{macro} |
| 153 |
% \end{macro} |
| 154 |
% \end{macro} |
| 155 |
% \end{macro} |
| 156 |
% \end{macro} |
| 157 |
% \end{macro} |
| 158 |
% \end{macro} |
| 159 |
% \end{macro} |
| 160 |
% |
| 161 |
% \subsection{Basic points} |
| 162 |
% |
| 163 |
% \begin{macro}[EXP]{\draw_point:n} |
| 164 |
% \begin{macro}[EXP]{\@@_point_to_dim:n, \@@_point_to_dim:e} |
| 165 |
% \begin{macro}[EXP]{\@@_point_to_dim:w} |
| 166 |
% Coordinates are always returned as two dimensions. |
| 167 |
% \begin{macrocode} |
| 168 |
\cs_new:Npn \draw_point:n #1 |
| 169 |
{ \@@_point_to_dim:e { \fp_eval:n {#1} } } |
| 170 |
\cs_new:Npn \@@_point_to_dim:n #1 |
| 171 |
{ \@@_point_to_dim:w #1 } |
| 172 |
\cs_generate_variant:Nn \@@_point_to_dim:n { e } |
| 173 |
\cs_new:Npn \@@_point_to_dim:w ( #1 , ~ #2 ) { #1pt , #2pt } |
| 174 |
% \end{macrocode} |
| 175 |
% \end{macro} |
| 176 |
% \end{macro} |
| 177 |
% |
| 178 |
% \subsection{Polar coordinates} |
| 179 |
% |
| 180 |
% \begin{macro}[EXP]{\draw_point_polar:nn} |
| 181 |
% \begin{macro}[EXP]{\draw_point_polar:nnn} |
| 182 |
% \begin{macro}[EXP]{\@@_draw_polar:nnn, \@@_draw_polar:enn} |
| 183 |
% Polar coordinates may have either one or two lengths, so there is a need |
| 184 |
% to do a simple split before the calculation. As the angle gets used twice, |
| 185 |
% save on any expression evaluation there and force expansion. |
| 186 |
% \begin{macrocode} |
| 187 |
\cs_new:Npn \draw_point_polar:nn #1#2 |
| 188 |
{ \draw_point_polar:nnn {#1} {#1} {#2} } |
| 189 |
\cs_new:Npn \draw_point_polar:nnn #1#2#3 |
| 190 |
{ \@@_draw_polar:enn { \fp_eval:n {#3} } {#1} {#2} } |
| 191 |
\cs_new:Npn \@@_draw_polar:nnn #1#2#3 |
| 192 |
{ \draw_point:n { cosd(#1) * (#2) , sind(#1) * (#3) } } |
| 193 |
\cs_generate_variant:Nn \@@_draw_polar:nnn { e } |
| 194 |
% \end{macrocode} |
| 195 |
% \end{macro} |
| 196 |
% \end{macro} |
| 197 |
% \end{macro} |
| 198 |
% |
| 199 |
% \subsection{Point expression arithmetic} |
| 200 |
% |
| 201 |
% These functions all take point expressions as arguments. |
| 202 |
% |
| 203 |
% \begin{macro}[EXP]{\draw_point_unit_vector:n} |
| 204 |
% \begin{macro}[EXP]{\@@_point_unit_vector:nn} |
| 205 |
% \begin{macro}[EXP]{\@@_point_unit_vector:nnn, \@@_point_unit_vector:enn} |
| 206 |
% The outcome is the normalized vector from $(0,0)$ in the direction of |
| 207 |
% the point, i.e. |
| 208 |
% \[ |
| 209 |
% P_{x} = \frac{x}{\sqrt{x^{2} + y^{2}}} \quad |
| 210 |
% P_{y} = \frac{y}{\sqrt{x^{2} + y^{2}}} |
| 211 |
% \] |
| 212 |
% except where the length is zero, in which case a vertical vector is |
| 213 |
% returned. |
| 214 |
% \begin{macrocode} |
| 215 |
\cs_new:Npn \draw_point_unit_vector:n #1 |
| 216 |
{ \@@_point_process:nn { \@@_point_unit_vector:nn } { \draw_point:n {#1} } } |
| 217 |
\cs_new:Npn \@@_point_unit_vector:nn #1#2 |
| 218 |
{ |
| 219 |
\@@_point_unit_vector:nnn |
| 220 |
{ \fp_eval:n { (sqrt(#1 * #1 + #2 * #2)) } } |
| 221 |
{#1} {#2} |
| 222 |
} |
| 223 |
\cs_new:Npn \@@_point_unit_vector:nnn #1#2#3 |
| 224 |
{ |
| 225 |
\fp_compare:nNnTF {#1} = \c_zero_fp |
| 226 |
{ 0pt, 1pt } |
| 227 |
{ |
| 228 |
\draw_point:n |
| 229 |
{ ( #2 , #3 ) / #1 } |
| 230 |
} |
| 231 |
} |
| 232 |
\cs_generate_variant:Nn \@@_point_unit_vector:nnn { e } |
| 233 |
% \end{macrocode} |
| 234 |
% \end{macro} |
| 235 |
% \end{macro} |
| 236 |
% \end{macro} |
| 237 |
% |
| 238 |
% \subsection{Intersection calculations} |
| 239 |
% |
| 240 |
% \begin{macro}[EXP]{\draw_point_intersect_lines:nnnn} |
| 241 |
% \begin{macro}[EXP]{\@@_point_intersect_lines:nnnnnn} |
| 242 |
% \begin{macro}[EXP]{\@@_point_intersect_lines:nnnnnnnn} |
| 243 |
% \begin{macro}[EXP] |
| 244 |
% {\@@_point_intersect_lines_aux:nnnnnn, \@@_point_intersect_lines_aux:eeeeee} |
| 245 |
% The intersection point~$P$ between a line joining points $(x_{1}, y_{1})$ |
| 246 |
% and $(x_{2}, y_{2})$ with a second line joining points $(x_{3}, y_{3})$ |
| 247 |
% and $(x_{4}, y_{4})$ can be calculated using the formulae |
| 248 |
% \[ |
| 249 |
% P_{x} = |
| 250 |
% \frac{(x_{1}y_{2} - y_{1}x_{2})(x_{3} - x_{4}) |
| 251 |
% - (x_{3}y_{4} - y_{3}x_{4})(x_{1} - x_{2})} |
| 252 |
% {(x_{1} - x_{2})(y_{3} - y_{4}) - (y_{1} - y_{2})(x_{3} - x_{4})} |
| 253 |
% \] |
| 254 |
% and |
| 255 |
% \[ |
| 256 |
% P_{y} = |
| 257 |
% \frac{(x_{1}y_{2} - y_{1}x_{2})(y_{3} - y_{5}) |
| 258 |
% - (x_{3}y_{4} - y_{3}x_{4})(y_{1} - y_{2})} |
| 259 |
% {(x_{1} - x_{2})(y_{3} - y_{4}) - (y_{1} - y_{2})(x_{3} - x_{4})} |
| 260 |
% \] |
| 261 |
% The work therefore comes down to expanding the incoming data, then |
| 262 |
% pre-calculating as many parts as possible before the final work to find |
| 263 |
% the intersection. (Expansion and argument re-ordering is much less work |
| 264 |
% than additional floating point calculations.) |
| 265 |
% \begin{macrocode} |
| 266 |
\cs_new:Npn \draw_point_intersect_lines:nnnn #1#2#3#4 |
| 267 |
{ |
| 268 |
\@@_point_process:nnnnn |
| 269 |
{ \@@_point_intersect_lines:nnnnnnnn } |
| 270 |
{ \draw_point:n {#1} } |
| 271 |
{ \draw_point:n {#2} } |
| 272 |
{ \draw_point:n {#3} } |
| 273 |
{ \draw_point:n {#4} } |
| 274 |
} |
| 275 |
% \end{macrocode} |
| 276 |
% At this stage we have all of the information we need, fully expanded: |
| 277 |
% \begin{enumerate}[label = \#\arabic*, font = \ttfamily] |
| 278 |
% \item $x_{1}$ |
| 279 |
% \item $y_{1}$ |
| 280 |
% \item $x_{2}$ |
| 281 |
% \item $y_{2}$ |
| 282 |
% \item $x_{3}$ |
| 283 |
% \item $y_{3}$ |
| 284 |
% \item $x_{4}$ |
| 285 |
% \item $y_{4}$ |
| 286 |
% \end{enumerate} |
| 287 |
% so now just have to do all of the calculation. |
| 288 |
% \begin{macrocode} |
| 289 |
\cs_new:Npn \@@_point_intersect_lines:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 290 |
{ |
| 291 |
\@@_point_intersect_lines_aux:eeeeee |
| 292 |
{ \fp_eval:n { #1 * #4 - #2 * #3 } } |
| 293 |
{ \fp_eval:n { #5 * #8 - #6 * #7 } } |
| 294 |
{ \fp_eval:n { #1 - #3 } } |
| 295 |
{ \fp_eval:n { #5 - #7 } } |
| 296 |
{ \fp_eval:n { #2 - #4 } } |
| 297 |
{ \fp_eval:n { #6 - #8 } } |
| 298 |
} |
| 299 |
\cs_new:Npn \@@_point_intersect_lines_aux:nnnnnn #1#2#3#4#5#6 |
| 300 |
{ |
| 301 |
\draw_point:n |
| 302 |
{ |
| 303 |
( #2 * #3 - #1 * #4 , #2 * #5 - #1 * #6 ) |
| 304 |
/ ( #4 * #5 - #6 * #3 ) |
| 305 |
} |
| 306 |
} |
| 307 |
\cs_generate_variant:Nn \@@_point_intersect_lines_aux:nnnnnn { eeeeee } |
| 308 |
% \end{macrocode} |
| 309 |
% \end{macro} |
| 310 |
% \end{macro} |
| 311 |
% \end{macro} |
| 312 |
% \end{macro} |
| 313 |
% |
| 314 |
% \begin{macro}[EXP]{\draw_point_intersect_circles:nnnnn} |
| 315 |
% \begin{macro}[EXP]{\@@_point_intersect_circles_auxi:nnnnnnn} |
| 316 |
% \begin{macro}[EXP] |
| 317 |
% { |
| 318 |
% \@@_point_intersect_circles_auxii:nnnnnnn, |
| 319 |
% \@@_point_intersect_circles_auxii:eennnnn, |
| 320 |
% \@@_point_intersect_circles_auxiii:nnnnnnn, |
| 321 |
% \@@_point_intersect_circles_auxiii:eennnnn |
| 322 |
% } |
| 323 |
% \begin{macro}[EXP] |
| 324 |
% { |
| 325 |
% \@@_point_intersect_circles_auxiv:nnnnnnnn, |
| 326 |
% \@@_point_intersect_circles_auxiv:ennnnnnn |
| 327 |
% } |
| 328 |
% \begin{macro}[EXP] |
| 329 |
% { |
| 330 |
% \@@_point_intersect_circles_auxv:nnnnnnnnn, |
| 331 |
% \@@_point_intersect_circles_auxv:eennnnnnn |
| 332 |
% } |
| 333 |
% \begin{macro}[EXP] |
| 334 |
% { |
| 335 |
% \@@_point_intersect_circles_auxvi:nnnnnnnn, |
| 336 |
% \@@_point_intersect_circles_auxvi:ennnnnnn |
| 337 |
% } |
| 338 |
% \begin{macro}[EXP] |
| 339 |
% { |
| 340 |
% \@@_point_intersect_circles_auxvii:nnnnnnn, |
| 341 |
% \@@_point_intersect_circles_auxvii:eeennnn |
| 342 |
% } |
| 343 |
% Another long expansion chain to get the values in the right places. |
| 344 |
% We have two circles, the first with center $(a, b)$ and radius~$r$, |
| 345 |
% the second with center $(c, d)$ and radius~$s$. We use the intermediate |
| 346 |
% values |
| 347 |
% \begin{align*} |
| 348 |
% e &= c - a \\ |
| 349 |
% f &= d - b \\ |
| 350 |
% p &= \sqrt{e^{2} + f^{2}} \\ |
| 351 |
% k &= \frac{p^{2} + r^{2} - s^{2}}{2p} |
| 352 |
% \end{align*} |
| 353 |
% in either |
| 354 |
% \begin{align*} |
| 355 |
% P_{x} &= a + \frac{ek}{p} + \frac{f}{p}\sqrt{r^{2} - k^{2}} \\ |
| 356 |
% P_{y} &= b + \frac{fk}{p} - \frac{e}{p}\sqrt{r^{2} - k^{2}} |
| 357 |
% \end{align*} |
| 358 |
% or |
| 359 |
% \begin{align*} |
| 360 |
% P_{x} &= a + \frac{ek}{p} - \frac{f}{p}\sqrt{r^{2} - k^{2}} \\ |
| 361 |
% P_{y} &= b + \frac{fk}{p} + \frac{e}{p}\sqrt{r^{2} - k^{2}} |
| 362 |
% \end{align*} |
| 363 |
% depending on which solution is required. The rest of the work is simply |
| 364 |
% forcing the appropriate expansion and shuffling arguments. |
| 365 |
% \begin{macrocode} |
| 366 |
\cs_new:Npn \draw_point_intersect_circles:nnnnn #1#2#3#4#5 |
| 367 |
{ |
| 368 |
\@@_point_process:nnn |
| 369 |
{ \@@_point_intersect_circles_auxi:nnnnnnn {#2} {#4} {#5} } |
| 370 |
{ \draw_point:n {#1} } |
| 371 |
{ \draw_point:n {#3} } |
| 372 |
} |
| 373 |
\cs_new:Npn \@@_point_intersect_circles_auxi:nnnnnnn #1#2#3#4#5#6#7 |
| 374 |
{ |
| 375 |
\@@_point_intersect_circles_auxii:eennnnn |
| 376 |
{ \fp_eval:n {#1} } { \fp_eval:n {#2} } {#4} {#5} {#6} {#7} {#3} |
| 377 |
} |
| 378 |
% \end{macrocode} |
| 379 |
% At this stage we have all of the information we need, fully expanded: |
| 380 |
% \begin{enumerate}[label = \#\arabic*, font = \ttfamily] |
| 381 |
% \item $r$ |
| 382 |
% \item $s$ |
| 383 |
% \item $a$ |
| 384 |
% \item $b$ |
| 385 |
% \item $c$ |
| 386 |
% \item $d$ |
| 387 |
% \item $n$ |
| 388 |
% \end{enumerate} |
| 389 |
% Once we evaluate $e$ and $f$, the coordinate $(c,d)$ is no longer |
| 390 |
% required: handy as we will need various intermediate values in the |
| 391 |
% following. |
| 392 |
% \begin{macrocode} |
| 393 |
\cs_new:Npn \@@_point_intersect_circles_auxii:nnnnnnn #1#2#3#4#5#6#7 |
| 394 |
{ |
| 395 |
\@@_point_intersect_circles_auxiii:eennnnn |
| 396 |
{ \fp_eval:n { #5 - #3 } } |
| 397 |
{ \fp_eval:n { #6 - #4 } } |
| 398 |
{#1} {#2} {#3} {#4} {#7} |
| 399 |
} |
| 400 |
\cs_generate_variant:Nn \@@_point_intersect_circles_auxii:nnnnnnn { ee } |
| 401 |
\cs_new:Npn \@@_point_intersect_circles_auxiii:nnnnnnn #1#2#3#4#5#6#7 |
| 402 |
{ |
| 403 |
\@@_point_intersect_circles_auxiv:ennnnnnn |
| 404 |
{ \fp_eval:n { sqrt( #1 * #1 + #2 * #2 ) } } |
| 405 |
{#1} {#2} {#3} {#4} {#5} {#6} {#7} |
| 406 |
} |
| 407 |
\cs_generate_variant:Nn \@@_point_intersect_circles_auxiii:nnnnnnn { ee } |
| 408 |
% \end{macrocode} |
| 409 |
% We now have $p$: we pre-calculate $1/p$ as it is needed a few times and |
| 410 |
% is relatively expensive. We also need $r^{2}$ twice so deal with that |
| 411 |
% here too. |
| 412 |
% \begin{macrocode} |
| 413 |
\cs_new:Npn \@@_point_intersect_circles_auxiv:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 414 |
{ |
| 415 |
\@@_point_intersect_circles_auxv:eennnnnnn |
| 416 |
{ \fp_eval:n { 1 / #1 } } |
| 417 |
{ \fp_eval:n { #4 * #4 } } |
| 418 |
{#1} {#2} {#3} {#5} {#6} {#7} {#8} |
| 419 |
} |
| 420 |
\cs_generate_variant:Nn \@@_point_intersect_circles_auxiv:nnnnnnnn { e } |
| 421 |
\cs_new:Npn \@@_point_intersect_circles_auxv:nnnnnnnnn #1#2#3#4#5#6#7#8#9 |
| 422 |
{ |
| 423 |
\@@_point_intersect_circles_auxvi:ennnnnnn |
| 424 |
{ \fp_eval:n { 0.5 * #1 * ( #2 + #3 * #3 - #6 * #6 ) } } |
| 425 |
{#1} {#2} {#4} {#5} {#7} {#8} {#9} |
| 426 |
} |
| 427 |
\cs_generate_variant:Nn \@@_point_intersect_circles_auxv:nnnnnnnnn { ee } |
| 428 |
% \end{macrocode} |
| 429 |
% We now have all of the intermediate values we require, with one division |
| 430 |
% carried out up-front to avoid doing this expensive step twice: |
| 431 |
% \begin{enumerate}[label = \#\arabic*, font = \ttfamily] |
| 432 |
% \item $k$ |
| 433 |
% \item $1/p$ |
| 434 |
% \item $r^{2}$ |
| 435 |
% \item $e$ |
| 436 |
% \item $f$ |
| 437 |
% \item $a$ |
| 438 |
% \item $b$ |
| 439 |
% \item $n$ |
| 440 |
% \end{enumerate} |
| 441 |
% There are some final pre-calculations, $k/p$, |
| 442 |
% $\frac{\sqrt{r^{2} - k^{2}}}{p}$ and the usage of $n$, then we |
| 443 |
% can yield a result. |
| 444 |
% \begin{macrocode} |
| 445 |
\cs_new:Npn \@@_point_intersect_circles_auxvi:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 446 |
{ |
| 447 |
\@@_point_intersect_circles_auxvii:eeennnn |
| 448 |
{ \fp_eval:n { #1 * #2 } } |
| 449 |
{ \int_if_odd:nTF {#8} { 1 } { -1 } } |
| 450 |
{ \fp_eval:n { sqrt ( #3 - #1 * #1 ) * #2 } } |
| 451 |
{#4} {#5} {#6} {#7} |
| 452 |
} |
| 453 |
\cs_generate_variant:Nn \@@_point_intersect_circles_auxvi:nnnnnnnn { e } |
| 454 |
\cs_new:Npn \@@_point_intersect_circles_auxvii:nnnnnnn #1#2#3#4#5#6#7 |
| 455 |
{ |
| 456 |
\draw_point:n |
| 457 |
{ #6 + #4 * #1 + #2 * #3 * #5 , #7 + #5 * #1 + -1 * #2 * #3 * #4 } |
| 458 |
} |
| 459 |
\cs_generate_variant:Nn \@@_point_intersect_circles_auxvii:nnnnnnn { eee } |
| 460 |
% \end{macrocode} |
| 461 |
% \end{macro} |
| 462 |
% \end{macro} |
| 463 |
% \end{macro} |
| 464 |
% \end{macro} |
| 465 |
% \end{macro} |
| 466 |
% \end{macro} |
| 467 |
% \end{macro} |
| 468 |
% |
| 469 |
% \begin{macro}[EXP]{\draw_point_intersect_line_circle:nnnnn} |
| 470 |
% \begin{macro}[EXP]{\@@_point_intersect_line_circle_auxi:nnnnnnnn} |
| 471 |
% \begin{macro}[EXP] |
| 472 |
% { |
| 473 |
% \@@_point_intersect_line_circle_auxii:nnnnnnnn, |
| 474 |
% \@@_point_intersect_line_circle_auxii:ennnnnnn, |
| 475 |
% \@@_point_intersect_line_circle_auxiii:nnnnnnnn, |
| 476 |
% \@@_point_intersect_line_circle_auxiii:eeennnnn |
| 477 |
% } |
| 478 |
% \begin{macro}[EXP] |
| 479 |
% { |
| 480 |
% \@@_point_intersect_line_circle_auxiv:nnnnnnnn, |
| 481 |
% \@@_point_intersect_line_circle_auxiv:eennnnnn |
| 482 |
% } |
| 483 |
% \begin{macro}[EXP] |
| 484 |
% { |
| 485 |
% \@@_point_intersect_line_circle_auxv:nnnnn, |
| 486 |
% \@@_point_intersect_line_circle_auxv:ennnn |
| 487 |
% } |
| 488 |
% The intersection points~$P_{1}$ and~$P_{2}$ between |
| 489 |
% a line joining points $(x_{1}, y_{1})$ and $(x_{2}, y_{2})$ |
| 490 |
% and a circle with center $(x_{3}, y_{3})$ and radius~$r$. |
| 491 |
% We use the intermediate |
| 492 |
% values |
| 493 |
% \begin{align*} |
| 494 |
% a &= (x_{2} - x_{1})^{2} + (y_{2} - y_{1})^{2} \\ |
| 495 |
% b &= 2 \times ((x_{2} - x_{1}) \times (x_{1} - x_{3}) + (y_{2} - y_{1}) \times (y_{1} - y_{3})) \\ |
| 496 |
% c &= x_{3}^{2} + y_{3}^{2} + x_{1}^{2} + y_{1}^{2} |
| 497 |
% - 2\times(x_{3} \times x_{1} + y_{3} \times y_{1}) - r^{2} \\ |
| 498 |
% d &= b^{2} - 4\times a \times c \\ |
| 499 |
% \mu_{1} &= \frac{-b + \sqrt{d}}{2 \times a}\\ |
| 500 |
% \mu_{2} &= \frac{-b - \sqrt{d}}{2 \times a} |
| 501 |
% \end{align*} |
| 502 |
% in either |
| 503 |
% \begin{align*} |
| 504 |
% P_{1x} &= x_{1} + \mu_{1}\times (x_{2} - x_{1}) \\ |
| 505 |
% P_{1y} &= y_{1} + \mu_{1}\times (y_{2} - y_{1}) |
| 506 |
% \end{align*} |
| 507 |
% or |
| 508 |
% \begin{align*} |
| 509 |
% P_{2x} &= x_{1} + \mu_{2}\times (x_{2} - x_{1}) \\ |
| 510 |
% P_{2y} &= y_{1} + \mu_{2}\times (y_{2} - y_{1}) |
| 511 |
% \end{align*} |
| 512 |
% depending on which solution is required. The rest of the work is simply |
| 513 |
% forcing the appropriate expansion and shuffling arguments. |
| 514 |
% \begin{macrocode} |
| 515 |
\cs_new:Npn \draw_point_intersect_line_circle:nnnnn #1#2#3#4#5 |
| 516 |
{ |
| 517 |
\@@_point_process:nnnn |
| 518 |
{ \@@_point_intersect_line_circle_auxi:nnnnnnnn {#4} {#5} } |
| 519 |
{ \draw_point:n {#1} } |
| 520 |
{ \draw_point:n {#2} } |
| 521 |
{ \draw_point:n {#3} } |
| 522 |
} |
| 523 |
\cs_new:Npn \@@_point_intersect_line_circle_auxi:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 524 |
{ |
| 525 |
\@@_point_intersect_line_circle_auxii:ennnnnnn |
| 526 |
{ \fp_eval:n {#1} } {#3} {#4} {#5} {#6} {#7} {#8} {#2} |
| 527 |
} |
| 528 |
% \end{macrocode} |
| 529 |
% At this stage we have all of the information we need, fully expanded: |
| 530 |
% \begin{enumerate}[label = \#\arabic*, font = \ttfamily] |
| 531 |
% \item $r$ |
| 532 |
% \item $x_{1}$ |
| 533 |
% \item $y_{1}$ |
| 534 |
% \item $x_{2}$ |
| 535 |
% \item $y_{2}$ |
| 536 |
% \item $x_{3}$ |
| 537 |
% \item $y_{3}$ |
| 538 |
% \item $n$ |
| 539 |
% \end{enumerate} |
| 540 |
% Once we evaluate $a$, $b$ and $c$, the coordinate $(x_{3},y_{3})$ |
| 541 |
% and $r$ are no longer required: handy as we will need various |
| 542 |
% intermediate values in the following. |
| 543 |
% \begin{macrocode} |
| 544 |
\cs_new:Npn \@@_point_intersect_line_circle_auxii:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 545 |
{ |
| 546 |
\@@_point_intersect_line_circle_auxiii:eeennnnn |
| 547 |
{ \fp_eval:n { (#4-#2)*(#4-#2)+(#5-#3)*(#5-#3) } } |
| 548 |
{ \fp_eval:n { 2*((#4-#2)*(#2-#6)+(#5-#3)*(#3-#7)) } } |
| 549 |
{ \fp_eval:n { (#6*#6+#7*#7)+(#2*#2+#3*#3)-(2*(#6*#2+#7*#3))-(#1*#1) } } |
| 550 |
{#2} {#3} {#4} {#5} {#8} |
| 551 |
} |
| 552 |
\cs_generate_variant:Nn \@@_point_intersect_line_circle_auxii:nnnnnnnn { e } |
| 553 |
% \end{macrocode} |
| 554 |
% then we can get $d = b^{2} - 4\times a \times c$ and the usage of $n$. |
| 555 |
% \begin{macrocode} |
| 556 |
\cs_new:Npn \@@_point_intersect_line_circle_auxiii:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 557 |
{ |
| 558 |
\@@_point_intersect_line_circle_auxiv:eennnnnn |
| 559 |
{ \fp_eval:n { #2 * #2 - 4 * #1 * #3 } } |
| 560 |
{ \int_if_odd:nTF {#8} { 1 } { -1 } } |
| 561 |
{#1} {#2} {#4} {#5} {#6} {#7} |
| 562 |
} |
| 563 |
\cs_generate_variant:Nn \@@_point_intersect_line_circle_auxiii:nnnnnnnn { eee } |
| 564 |
% \end{macrocode} |
| 565 |
% We now have all of the intermediate values we require, with one division |
| 566 |
% carried out up-front to avoid doing this expensive step twice: |
| 567 |
% \begin{enumerate}[label = \#\arabic*, font = \ttfamily] |
| 568 |
% \item $a$ |
| 569 |
% \item $b$ |
| 570 |
% \item $c$ |
| 571 |
% \item $d$ |
| 572 |
% \item $\pm$(the usage of $n$) |
| 573 |
% \item $x_{1}$ |
| 574 |
% \item $y_{1}$ |
| 575 |
% \item $x_{2}$ |
| 576 |
% \item $y_{2}$ |
| 577 |
% \end{enumerate} |
| 578 |
% There are some final pre-calculations, |
| 579 |
% $\mu = \frac{-b \pm \sqrt{d}}{2 \times a}$ |
| 580 |
% then, we can yield a result. |
| 581 |
% \begin{macrocode} |
| 582 |
\cs_new:Npn \@@_point_intersect_line_circle_auxiv:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 583 |
{ |
| 584 |
\@@_point_intersect_line_circle_auxv:ennnn |
| 585 |
{ \fp_eval:n { (-1 * #4 + #2 * sqrt(#1)) / (2 * #3) } } |
| 586 |
{#5} {#6} {#7} {#8} |
| 587 |
} |
| 588 |
\cs_generate_variant:Nn \@@_point_intersect_line_circle_auxiv:nnnnnnnn { ee } |
| 589 |
\cs_new:Npn \@@_point_intersect_line_circle_auxv:nnnnn #1#2#3#4#5 |
| 590 |
{ |
| 591 |
\draw_point:n |
| 592 |
{ #2 + #1 * (#4 - #2), #3 + #1 * (#5 - #3) } |
| 593 |
} |
| 594 |
\cs_generate_variant:Nn \@@_point_intersect_line_circle_auxv:nnnnn { e } |
| 595 |
% \end{macrocode} |
| 596 |
% \end{macro} |
| 597 |
% \end{macro} |
| 598 |
% \end{macro} |
| 599 |
% \end{macro} |
| 600 |
% \end{macro} |
| 601 |
% |
| 602 |
% \subsection{Interpolation on a line (vector) or arc} |
| 603 |
% |
| 604 |
% \begin{macro}[EXP]{\draw_point_interpolate_line:nnn} |
| 605 |
% \begin{macro}[EXP] |
| 606 |
% { |
| 607 |
% \@@_point_interpolate_line_aux:nnnnn, |
| 608 |
% \@@_point_interpolate_line_aux:ennnn, |
| 609 |
% } |
| 610 |
% \begin{macro}[EXP] |
| 611 |
% { |
| 612 |
% \@@_point_interpolate_line_aux:nnnnnn, |
| 613 |
% \@@_point_interpolate_line_aux:ennnnn, |
| 614 |
% } |
| 615 |
% Simple maths after expansion. |
| 616 |
% \begin{macrocode} |
| 617 |
\cs_new:Npn \draw_point_interpolate_line:nnn #1#2#3 |
| 618 |
{ |
| 619 |
\@@_point_process:nnn |
| 620 |
{ \@@_point_interpolate_line_aux:ennnn { \fp_eval:n {#1} } } |
| 621 |
{ \draw_point:n {#2} } |
| 622 |
{ \draw_point:n {#3} } |
| 623 |
} |
| 624 |
\cs_new:Npn \@@_point_interpolate_line_aux:nnnnn #1#2#3#4#5 |
| 625 |
{ |
| 626 |
\@@_point_interpolate_line_aux:ennnnn { \fp_eval:n { 1 - #1 } } |
| 627 |
{#1} {#2} {#3} {#4} {#5} |
| 628 |
} |
| 629 |
\cs_generate_variant:Nn \@@_point_interpolate_line_aux:nnnnn { e } |
| 630 |
\cs_new:Npn \@@_point_interpolate_line_aux:nnnnnn #1#2#3#4#5#6 |
| 631 |
{ \draw_point:n { #1 * #3 + #2 * #5 , #1 * #4 + #2 * #6 } } |
| 632 |
\cs_generate_variant:Nn \@@_point_interpolate_line_aux:nnnnnn { e } |
| 633 |
% \end{macrocode} |
| 634 |
% \end{macro} |
| 635 |
% \end{macro} |
| 636 |
% \end{macro} |
| 637 |
% |
| 638 |
% \begin{macro}[EXP]{\draw_point_interpolate_distance:nnn} |
| 639 |
% \begin{macro}[EXP]{\@@_point_interpolate_distance:nnnnn} |
| 640 |
% \begin{macro}[EXP] |
| 641 |
% { |
| 642 |
% \@@_point_interpolate_distance:nnnnnn, |
| 643 |
% \@@_point_interpolate_distance:ennnnn, |
| 644 |
% } |
| 645 |
% Same idea but using the normalized length to obtain the scale factor. |
| 646 |
% The start point is needed twice, so we force evaluation, but the end |
| 647 |
% point is needed only the once. |
| 648 |
% \begin{macrocode} |
| 649 |
\cs_new:Npn \draw_point_interpolate_distance:nnn #1#2#3 |
| 650 |
{ |
| 651 |
\@@_point_process:nn |
| 652 |
{ \@@_point_interpolate_distance:nnnn {#1} {#3} } |
| 653 |
{#2} |
| 654 |
} |
| 655 |
\cs_new:Npn \@@_point_interpolate_distance:nnnn #1#2#3#4 |
| 656 |
{ |
| 657 |
\@@_point_process:nn |
| 658 |
{ |
| 659 |
\@@_point_interpolate_distance:ennnn |
| 660 |
{ \fp_eval:n {#1} } {#3} {#4} |
| 661 |
} |
| 662 |
{ \draw_point_unit_vector:n { ( #2 ) - ( #3 , #4 ) } } |
| 663 |
} |
| 664 |
\cs_new:Npn \@@_point_interpolate_distance:nnnnn #1#2#3#4#5 |
| 665 |
{ \draw_point:n { #2 + #1 * #4 , #3 + #1 * #5 } } |
| 666 |
\cs_generate_variant:Nn \@@_point_interpolate_distance:nnnnn { e } |
| 667 |
% \end{macrocode} |
| 668 |
% \end{macro} |
| 669 |
% \end{macro} |
| 670 |
% \end{macro} |
| 671 |
% \end{macro} |
| 672 |
% |
| 673 |
% \begin{macro}[EXP]{\draw_point_interpolate_arc_axes:nnnnnn} |
| 674 |
% \begin{macro}[EXP]{\@@_point_interpolate_arcaxes_auxi:nnnnnnnnn} |
| 675 |
% \begin{macro}[EXP] |
| 676 |
% { |
| 677 |
% \@@_point_interpolate_arcaxes_auxii:nnnnnnnnn, |
| 678 |
% \@@_point_interpolate_arcaxes_auxii:ennnnnnnn |
| 679 |
% } |
| 680 |
% \begin{macro}[EXP] |
| 681 |
% { |
| 682 |
% \@@_point_interpolate_arcaxes_auxiii:nnnnnnn, |
| 683 |
% \@@_point_interpolate_arcaxes_auxiii:ennnnnn |
| 684 |
% } |
| 685 |
% \begin{macro}[EXP] |
| 686 |
% { |
| 687 |
% \@@_point_interpolate_arcaxes_auxiv:nnnnnnnn, |
| 688 |
% \@@_point_interpolate_arcaxes_auxiv:eennnnnn |
| 689 |
% } |
| 690 |
% Finding a point on an ellipse arc is relatively easy: find the correct |
| 691 |
% angle between the two given, use the sine and cosine of that angle, |
| 692 |
% apply to the axes. We just have to work a bit with the coordinate |
| 693 |
% expansion. |
| 694 |
% \begin{macrocode} |
| 695 |
\cs_new:Npn \draw_point_interpolate_arc_axes:nnnnnn #1#2#3#4#5#6 |
| 696 |
{ |
| 697 |
\@@_point_process:nnnn |
| 698 |
{ \@@_point_interpolate_arcaxes_auxi:nnnnnnnnn {#1} {#5} {#6} } |
| 699 |
{ \draw_point:n {#2} } |
| 700 |
{ \draw_point:n {#3} } |
| 701 |
{ \draw_point:n {#4} } |
| 702 |
} |
| 703 |
\cs_new:Npn \@@_point_interpolate_arcaxes_auxi:nnnnnnnnn #1#2#3#4#5#6#7#8#9 |
| 704 |
{ |
| 705 |
\@@_point_interpolate_arcaxes_auxii:ennnnnnnn |
| 706 |
{ \fp_eval:n {#1} } {#2} {#3} {#4} {#5} {#6} {#7} {#8} {#9} |
| 707 |
} |
| 708 |
% \end{macrocode} |
| 709 |
% At this stage, the three coordinate pairs are fully expanded but somewhat |
| 710 |
% re-ordered: |
| 711 |
% \begin{enumerate}[label = \#\arabic*, font = \ttfamily] |
| 712 |
% \item $p$ |
| 713 |
% \item $\theta_{1}$ |
| 714 |
% \item $\theta_{2}$ |
| 715 |
% \item $x_{c}$ |
| 716 |
% \item $y_{c}$ |
| 717 |
% \item $x_{a1}$ |
| 718 |
% \item $y_{a1}$ |
| 719 |
% \item $x_{a2}$ |
| 720 |
% \item $y_{a2}$ |
| 721 |
% \end{enumerate} |
| 722 |
% We are now in a position to find the target angle, and from that |
| 723 |
% the sine and cosine required. |
| 724 |
% \begin{macrocode} |
| 725 |
\cs_new:Npn \@@_point_interpolate_arcaxes_auxii:nnnnnnnnn #1#2#3#4#5#6#7#8#9 |
| 726 |
{ |
| 727 |
\@@_point_interpolate_arcaxes_auxiii:ennnnnn |
| 728 |
{ \fp_eval:n { #1 * (#3) + ( 1 - #1 ) * (#2) } } |
| 729 |
{#4} {#5} {#6} {#7} {#8} {#9} |
| 730 |
} |
| 731 |
\cs_generate_variant:Nn \@@_point_interpolate_arcaxes_auxii:nnnnnnnnn { e } |
| 732 |
\cs_new:Npn \@@_point_interpolate_arcaxes_auxiii:nnnnnnn #1#2#3#4#5#6#7 |
| 733 |
{ |
| 734 |
\@@_point_interpolate_arcaxes_auxiv:eennnnnn |
| 735 |
{ \fp_eval:n { cosd (#1) } } |
| 736 |
{ \fp_eval:n { sind (#1) } } |
| 737 |
{#2} {#3} {#4} {#5} {#6} {#7} |
| 738 |
} |
| 739 |
\cs_generate_variant:Nn \@@_point_interpolate_arcaxes_auxiii:nnnnnnn { e } |
| 740 |
\cs_new:Npn \@@_point_interpolate_arcaxes_auxiv:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 741 |
{ |
| 742 |
\draw_point:n |
| 743 |
{ #3 + #1 * #5 + #2 * #7 , #4 + #1 * #6 + #2 * #8 } |
| 744 |
} |
| 745 |
\cs_generate_variant:Nn \@@_point_interpolate_arcaxes_auxiv:nnnnnnnn { ee } |
| 746 |
% \end{macrocode} |
| 747 |
% \end{macro} |
| 748 |
% \end{macro} |
| 749 |
% \end{macro} |
| 750 |
% \end{macro} |
| 751 |
% \end{macro} |
| 752 |
% |
| 753 |
% \begin{macro}[EXP]{\draw_point_interpolate_curve:nnnn} |
| 754 |
% \begin{macro}[EXP]{\@@_point_interpolate_curve_quad_auxi:nnnnnnn} |
| 755 |
% \begin{macro}[EXP] |
| 756 |
% { |
| 757 |
% \@@_point_interpolate_curve_quad_auxii:nnnnnnn, |
| 758 |
% \@@_point_interpolate_curve_quad_auxii:ennnnnn |
| 759 |
% } |
| 760 |
% \begin{macro}[EXP] |
| 761 |
% { |
| 762 |
% \@@_point_interpolate_curve_quad_auxiii:nnnnnnnnn, |
| 763 |
% \@@_point_interpolate_curve_quad_auxiii:eeennnnnn |
| 764 |
% } |
| 765 |
% Interpolation along a quadratic Bézier curve uses the relation |
| 766 |
% \[ P(t) = (1-t)^2 P_0 + 2(1-t)t P_1 + t^2 P_2 \] |
| 767 |
% where $P_0$ is the start point, $P_1$ is the single control point, and |
| 768 |
% $P_2$ is the end point. To maximize performance and maintain full |
| 769 |
% expandability, the time parameter $t$ is evaluated once up front. |
| 770 |
% The three polynomial coefficients are then pre-calculated via an $e$-type |
| 771 |
% variant before being mapped against the coordinate components processed by |
| 772 |
% \cs{@@_point_process:nnnn}. |
| 773 |
% \begin{macrocode} |
| 774 |
\cs_new:Npn \draw_point_interpolate_curve:nnnn #1#2#3#4 |
| 775 |
{ |
| 776 |
\@@_point_process:nnnn |
| 777 |
{ \@@_point_interpolate_curve_quad_auxi:nnnnnnn {#1} } |
| 778 |
{ \draw_point:n {#2} } |
| 779 |
{ \draw_point:n {#3} } |
| 780 |
{ \draw_point:n {#4} } |
| 781 |
} |
| 782 |
\cs_new:Npn \@@_point_interpolate_curve_quad_auxi:nnnnnnn #1#2#3#4#5#6#7 |
| 783 |
{ |
| 784 |
\@@_point_interpolate_curve_quad_auxii:ennnnnn |
| 785 |
{ \fp_eval:n {#1} } |
| 786 |
{#2} {#3} {#4} {#5} {#6} {#7} |
| 787 |
} |
| 788 |
\cs_new:Npn \@@_point_interpolate_curve_quad_auxii:nnnnnnn #1#2#3#4#5#6#7 |
| 789 |
{ |
| 790 |
\@@_point_interpolate_curve_quad_auxiii:eeennnnnn |
| 791 |
{ \fp_eval:n { (1 - #1)^2 } } |
| 792 |
{ \fp_eval:n { 2 * (1 - #1) * #1 } } |
| 793 |
{ \fp_eval:n { #1^2 } } |
| 794 |
{#2} {#3} {#4} {#5} {#6} {#7} |
| 795 |
} |
| 796 |
\cs_generate_variant:Nn \@@_point_interpolate_curve_quad_auxii:nnnnnnn { e } |
| 797 |
\cs_new:Npn \@@_point_interpolate_curve_quad_auxiii:nnnnnnnnn #1#2#3#4#5#6#7#8#9 |
| 798 |
{ |
| 799 |
\draw_point:n |
| 800 |
{ |
| 801 |
#1 * #4 + #2 * #6 + #3 * #8 , |
| 802 |
#1 * #5 + #2 * #7 + #3 * #9 |
| 803 |
} |
| 804 |
} |
| 805 |
\cs_generate_variant:Nn \@@_point_interpolate_curve_quad_auxiii:nnnnnnnnn { eee } |
| 806 |
% \end{macrocode} |
| 807 |
% \end{macro} |
| 808 |
% \end{macro} |
| 809 |
% \end{macro} |
| 810 |
% \end{macro} |
| 811 |
% |
| 812 |
% \begin{macro}[EXP]{\draw_point_interpolate_curve:nnnnn} |
| 813 |
% \begin{macro}[EXP]{\@@_point_interpolate_curve_auxi:nnnnnnnnn} |
| 814 |
% \begin{macro}[EXP] |
| 815 |
% { |
| 816 |
% \@@_point_interpolate_curve_auxii:nnnnnnnnn, |
| 817 |
% \@@_point_interpolate_curve_auxii:ennnnnnnn, |
| 818 |
% } |
| 819 |
% \begin{macro}[EXP] |
| 820 |
% { |
| 821 |
% \@@_point_interpolate_curve_auxiii:nnnnnn, |
| 822 |
% \@@_point_interpolate_curve_auxiii:ennnnn, |
| 823 |
% } |
| 824 |
% \begin{macro}[EXP]{\@@_point_interpolate_curve_auxiv:nnnnnn} |
| 825 |
% \begin{macro}[EXP] |
| 826 |
% { |
| 827 |
% \@@_point_interpolate_curve_auxv:nnw, |
| 828 |
% \@@_point_interpolate_curve_auxv:eew, |
| 829 |
% } |
| 830 |
% \begin{macro}[EXP]{\@@_point_interpolate_curve_auxvi:n} |
| 831 |
% \begin{macro}[EXP]{\@@_point_interpolate_curve_auxvii:nnnnnnnn} |
| 832 |
% \begin{macro}[EXP] |
| 833 |
% { |
| 834 |
% \@@_point_interpolate_curve_auxviii:nnnnnn, |
| 835 |
% \@@_point_interpolate_curve_auxviii:eennnn, |
| 836 |
% } |
| 837 |
% Here we start with a proportion of the curve ($p$) and four points |
| 838 |
% \begin{enumerate} |
| 839 |
% \item The initial point $(x_{1},y_{1})$ |
| 840 |
% \item The first control point $(x_{2},y_{2})$ |
| 841 |
% \item The second control point $(x_{3},y_{3})$ |
| 842 |
% \item The final point $(x_{4},y_{4})$ |
| 843 |
% \end{enumerate} |
| 844 |
% The first phase is to expand out all of these values. |
| 845 |
% \begin{macrocode} |
| 846 |
\cs_new:Npn \draw_point_interpolate_curve:nnnnn #1#2#3#4#5 |
| 847 |
{ |
| 848 |
\@@_point_process:nnnnn |
| 849 |
{ \@@_point_interpolate_curve_auxi:nnnnnnnnn {#1} } |
| 850 |
{ \draw_point:n {#2} } |
| 851 |
{ \draw_point:n {#3} } |
| 852 |
{ \draw_point:n {#4} } |
| 853 |
{ \draw_point:n {#5} } |
| 854 |
} |
| 855 |
\cs_new:Npn \@@_point_interpolate_curve_auxi:nnnnnnnnn #1#2#3#4#5#6#7#8#9 |
| 856 |
{ |
| 857 |
\@@_point_interpolate_curve_auxii:ennnnnnnn |
| 858 |
{ \fp_eval:n {#1} } |
| 859 |
{#2} {#3} {#4} {#5} {#6} {#7} {#8} {#9} |
| 860 |
} |
| 861 |
% \end{macrocode} |
| 862 |
% At this stage, everything is fully expanded and back in the input order. |
| 863 |
% The approach to finding the required point is iterative. We carry out |
| 864 |
% three phases. In phase one, we need all of the input coordinates |
| 865 |
% \begin{align*} |
| 866 |
% x_{1}' &= (1 - p)x_{1} + px_{2} \\ |
| 867 |
% y_{1}' &= (1 - p)y_{1} + py_{2} \\ |
| 868 |
% x_{2}' &= (1 - p)x_{2} + px_{3} \\ |
| 869 |
% y_{2}' &= (1 - p)y_{2} + py_{3} \\ |
| 870 |
% x_{3}' &= (1 - p)x_{3} + px_{4} \\ |
| 871 |
% y_{3}' &= (1 - p)y_{3} + py_{4} |
| 872 |
% \end{align*} |
| 873 |
% In the second stage, we can drop the final point |
| 874 |
% \begin{align*} |
| 875 |
% x_{1}'' &= (1 - p)x_{1}' + px_{2}' \\ |
| 876 |
% y_{1}'' &= (1 - p)y_{1}' + py_{2}' \\ |
| 877 |
% x_{2}'' &= (1 - p)x_{2}' + px_{3}' \\ |
| 878 |
% y_{2}'' &= (1 - p)y_{2}' + py_{3}' |
| 879 |
% \end{align*} |
| 880 |
% and for the final stage only need one set of calculations |
| 881 |
% \begin{align*} |
| 882 |
% P_{x} &= (1 - p)x_{1}'' + px_{2}'' \\ |
| 883 |
% P_{y} &= (1 - p)y_{1}'' + py_{2}'' |
| 884 |
% \end{align*} |
| 885 |
% Of course, this does mean a lot of calculations and expansion! |
| 886 |
% \begin{macrocode} |
| 887 |
\cs_new:Npn \@@_point_interpolate_curve_auxii:nnnnnnnnn |
| 888 |
#1#2#3#4#5#6#7#8#9 |
| 889 |
{ |
| 890 |
\@@_point_interpolate_curve_auxiii:ennnnn |
| 891 |
{ \fp_eval:n { 1 - #1 } } |
| 892 |
{#1} |
| 893 |
{ {#2} {#3} } { {#4} {#5} } { {#6} {#7} } { {#8} {#9} } |
| 894 |
} |
| 895 |
\cs_generate_variant:Nn \@@_point_interpolate_curve_auxii:nnnnnnnnn { e } |
| 896 |
% \begin{macrocode} |
| 897 |
% We need to do the first cycle, but haven't got enough arguments to keep |
| 898 |
% everything in play at once. So here we use a bit of argument re-ordering |
| 899 |
% and a single auxiliary to get the job done. |
| 900 |
% \begin{macrocode} |
| 901 |
\cs_new:Npn \@@_point_interpolate_curve_auxiii:nnnnnn #1#2#3#4#5#6 |
| 902 |
{ |
| 903 |
\@@_point_interpolate_curve_auxiv:nnnnnn {#1} {#2} #3 #4 |
| 904 |
\@@_point_interpolate_curve_auxiv:nnnnnn {#1} {#2} #4 #5 |
| 905 |
\@@_point_interpolate_curve_auxiv:nnnnnn {#1} {#2} #5 #6 |
| 906 |
\prg_do_nothing: |
| 907 |
\@@_point_interpolate_curve_auxvi:n { {#1} {#2} } |
| 908 |
} |
| 909 |
\cs_generate_variant:Nn \@@_point_interpolate_curve_auxiii:nnnnnn { e } |
| 910 |
\cs_new:Npn \@@_point_interpolate_curve_auxiv:nnnnnn #1#2#3#4#5#6 |
| 911 |
{ |
| 912 |
\@@_point_interpolate_curve_auxv:eew |
| 913 |
{ \fp_eval:n { #1 * #3 + #2 * #5 } } |
| 914 |
{ \fp_eval:n { #1 * #4 + #2 * #6 } } |
| 915 |
} |
| 916 |
\cs_new:Npn \@@_point_interpolate_curve_auxv:nnw |
| 917 |
#1#2#3 \prg_do_nothing: #4#5 |
| 918 |
{ |
| 919 |
#3 |
| 920 |
\prg_do_nothing: |
| 921 |
#4 { #5 {#1} {#2} } |
| 922 |
} |
| 923 |
\cs_generate_variant:Nn \@@_point_interpolate_curve_auxv:nnw { ee } |
| 924 |
% \begin{macrocode} |
| 925 |
% Get the arguments back into the right places and to the second and |
| 926 |
% third cycles directly. |
| 927 |
% \begin{macrocode} |
| 928 |
\cs_new:Npn \@@_point_interpolate_curve_auxvi:n #1 |
| 929 |
{ \@@_point_interpolate_curve_auxvii:nnnnnnnn #1 } |
| 930 |
\cs_new:Npn \@@_point_interpolate_curve_auxvii:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 931 |
{ |
| 932 |
\@@_point_interpolate_curve_auxviii:eeeenn |
| 933 |
{ \fp_eval:n { #1 * #3 + #2 * #5 } } |
| 934 |
{ \fp_eval:n { #1 * #4 + #2 * #6 } } |
| 935 |
{ \fp_eval:n { #1 * #5 + #2 * #7 } } |
| 936 |
{ \fp_eval:n { #1 * #6 + #2 * #8 } } |
| 937 |
{#1} {#2} |
| 938 |
} |
| 939 |
\cs_new:Npn \@@_point_interpolate_curve_auxviii:nnnnnn #1#2#3#4#5#6 |
| 940 |
{ |
| 941 |
\draw_point:n |
| 942 |
{ #5 * #1 + #6 * #3 , #5 * #2 + #6 * #4 } |
| 943 |
} |
| 944 |
\cs_generate_variant:Nn \@@_point_interpolate_curve_auxviii:nnnnnn { eeee } |
| 945 |
% \end{macrocode} |
| 946 |
% \end{macro} |
| 947 |
% \end{macro} |
| 948 |
% \end{macro} |
| 949 |
% \end{macro} |
| 950 |
% \end{macro} |
| 951 |
% \end{macro} |
| 952 |
% \end{macro} |
| 953 |
% \end{macro} |
| 954 |
% \end{macro} |
| 955 |
% |
| 956 |
% \subsection{Vector support} |
| 957 |
% |
| 958 |
% As well as coordinates relative to the drawing |
| 959 |
% |
| 960 |
% \begin{variable} |
| 961 |
% { |
| 962 |
% \l_@@_xvec_x_dim, |
| 963 |
% \l_@@_xvec_y_dim, |
| 964 |
% \l_@@_yvec_x_dim, |
| 965 |
% \l_@@_yvec_y_dim, |
| 966 |
% \l_@@_zvec_x_dim, |
| 967 |
% \l_@@_zvec_y_dim |
| 968 |
% } |
| 969 |
% Base vectors to map to the underlying two-dimensional drawing space. |
| 970 |
% \begin{macrocode} |
| 971 |
\dim_new:N \l_@@_xvec_x_dim |
| 972 |
\dim_new:N \l_@@_xvec_y_dim |
| 973 |
\dim_new:N \l_@@_yvec_x_dim |
| 974 |
\dim_new:N \l_@@_yvec_y_dim |
| 975 |
\dim_new:N \l_@@_zvec_x_dim |
| 976 |
\dim_new:N \l_@@_zvec_y_dim |
| 977 |
% \end{macrocode} |
| 978 |
% \end{variable} |
| 979 |
% |
| 980 |
% \begin{macro}{\draw_xvec:n, \draw_yvec:n, \draw_zvec:n} |
| 981 |
% \begin{macro}{\@@_vec:nn} |
| 982 |
% \begin{macro}{\@@_vec:nnn} |
| 983 |
% Calculate the underlying position and store it. |
| 984 |
% \begin{macrocode} |
| 985 |
\cs_new_protected:Npn \draw_xvec:n #1 |
| 986 |
{ \@@_vec:nn { x } {#1} } |
| 987 |
\cs_new_protected:Npn \draw_yvec:n #1 |
| 988 |
{ \@@_vec:nn { y } {#1} } |
| 989 |
\cs_new_protected:Npn \draw_zvec:n #1 |
| 990 |
{ \@@_vec:nn { z } {#1} } |
| 991 |
\cs_new_protected:Npn \@@_vec:nn #1#2 |
| 992 |
{ \@@_point_process:nn { \@@_vec:nnn {#1} } { \draw_point:n {#2} } } |
| 993 |
\cs_new_protected:Npn \@@_vec:nnn #1#2#3 |
| 994 |
{ |
| 995 |
\dim_set:cn { l_@@_ #1 vec_x_dim } {#2} |
| 996 |
\dim_set:cn { l_@@_ #1 vec_y_dim } {#3} |
| 997 |
} |
| 998 |
% \end{macrocode} |
| 999 |
% \end{macro} |
| 1000 |
% \end{macro} |
| 1001 |
% \end{macro} |
| 1002 |
% |
| 1003 |
% Initialize the vectors. |
| 1004 |
% \begin{macrocode} |
| 1005 |
\draw_xvec:n { 1cm , 0cm } |
| 1006 |
\draw_yvec:n { 0cm , 1cm } |
| 1007 |
\draw_zvec:n { -0.385cm , -0.385cm } |
| 1008 |
% \end{macrocode} |
| 1009 |
% |
| 1010 |
% \begin{macro}[EXP]{\draw_point_vec:nn} |
| 1011 |
% \begin{macro}[EXP]{\@@_point_vec:nn, \@@_point_vec:ee} |
| 1012 |
% \begin{macro}[EXP]{\draw_point_vec:nnn} |
| 1013 |
% \begin{macro}[EXP]{\@@_point_vec:nnn, \@@_point_vec:eee} |
| 1014 |
% Force a single evaluation of each factor, then use these to work out the |
| 1015 |
% underlying point. |
| 1016 |
% \begin{macrocode} |
| 1017 |
\cs_new:Npn \draw_point_vec:nn #1#2 |
| 1018 |
{ \@@_point_vec:ee { \fp_eval:n {#1} } { \fp_eval:n {#2} } } |
| 1019 |
\cs_new:Npn \@@_point_vec:nn #1#2 |
| 1020 |
{ |
| 1021 |
\draw_point:n |
| 1022 |
{ |
| 1023 |
#1 * \l_@@_xvec_x_dim + #2 * \l_@@_yvec_x_dim , |
| 1024 |
#1 * \l_@@_xvec_y_dim + #2 * \l_@@_yvec_y_dim |
| 1025 |
} |
| 1026 |
} |
| 1027 |
\cs_generate_variant:Nn \@@_point_vec:nn { ee } |
| 1028 |
\cs_new:Npn \draw_point_vec:nnn #1#2#3 |
| 1029 |
{ |
| 1030 |
\@@_point_vec:eee |
| 1031 |
{ \fp_eval:n {#1} } { \fp_eval:n {#2} } { \fp_eval:n {#3} } |
| 1032 |
} |
| 1033 |
\cs_new:Npn \@@_point_vec:nnn #1#2#3 |
| 1034 |
{ |
| 1035 |
\draw_point:n |
| 1036 |
{ |
| 1037 |
#1 * \l_@@_xvec_x_dim |
| 1038 |
+ #2 * \l_@@_yvec_x_dim |
| 1039 |
+ #3 * \l_@@_zvec_x_dim |
| 1040 |
, |
| 1041 |
#1 * \l_@@_xvec_y_dim |
| 1042 |
+ #2 * \l_@@_yvec_y_dim |
| 1043 |
+ #3 * \l_@@_zvec_y_dim |
| 1044 |
} |
| 1045 |
} |
| 1046 |
\cs_generate_variant:Nn \@@_point_vec:nnn { eee } |
| 1047 |
% \end{macrocode} |
| 1048 |
% \end{macro} |
| 1049 |
% \end{macro} |
| 1050 |
% \end{macro} |
| 1051 |
% \end{macro} |
| 1052 |
% |
| 1053 |
% \begin{macro}[EXP]{\draw_point_vec_polar:nn} |
| 1054 |
% \begin{macro}[EXP]{\draw_point_vec_polar:nnn} |
| 1055 |
% \begin{macro}[EXP]{\@@_point_vec_polar:nnn, \@@_point_vec_polar:enn} |
| 1056 |
% Much the same as the core polar approach. |
| 1057 |
% \begin{macrocode} |
| 1058 |
\cs_new:Npn \draw_point_vec_polar:nn #1#2 |
| 1059 |
{ \draw_point_vec_polar:nnn {#1} {#1} {#2} } |
| 1060 |
\cs_new:Npn \draw_point_vec_polar:nnn #1#2#3 |
| 1061 |
{ \@@_draw_vec_polar:enn { \fp_eval:n {#3} } {#1} {#2} } |
| 1062 |
\cs_new:Npn \@@_draw_vec_polar:nnn #1#2#3 |
| 1063 |
{ |
| 1064 |
\draw_point:n |
| 1065 |
{ |
| 1066 |
cosd(#1) * (#2) * \l_@@_xvec_x_dim , |
| 1067 |
sind(#1) * (#3) * \l_@@_yvec_y_dim |
| 1068 |
} |
| 1069 |
} |
| 1070 |
\cs_generate_variant:Nn \@@_draw_vec_polar:nnn { e } |
| 1071 |
% \end{macrocode} |
| 1072 |
% \end{macro} |
| 1073 |
% \end{macro} |
| 1074 |
% \end{macro} |
| 1075 |
% |
| 1076 |
% \subsection{Transformations} |
| 1077 |
% |
| 1078 |
% \begin{macro}[EXP]{\draw_point_transform:n} |
| 1079 |
% \begin{macro}[EXP]{\@@_point_transform:nn} |
| 1080 |
% Applies a transformation matrix to a point: see \texttt{l3draw-transforms} |
| 1081 |
% for the business end. Where possible, we avoid the relatively expensive |
| 1082 |
% multiplication step. |
| 1083 |
% \begin{macrocode} |
| 1084 |
\cs_new:Npn \draw_point_transform:n #1 |
| 1085 |
{ |
| 1086 |
\@@_point_process:nn |
| 1087 |
{ \@@_point_transform:nn } { \draw_point:n {#1} } |
| 1088 |
} |
| 1089 |
\cs_new:Npn \@@_point_transform:nn #1#2 |
| 1090 |
{ |
| 1091 |
\bool_if:NTF \l_@@_matrix_active_bool |
| 1092 |
{ |
| 1093 |
\draw_point:n |
| 1094 |
{ |
| 1095 |
( |
| 1096 |
\l_@@_matrix_a_fp * #1 |
| 1097 |
+ \l_@@_matrix_c_fp * #2 |
| 1098 |
+ \l_@@_xshift_dim |
| 1099 |
) |
| 1100 |
, |
| 1101 |
( |
| 1102 |
\l_@@_matrix_b_fp * #1 |
| 1103 |
+ \l_@@_matrix_d_fp * #2 |
| 1104 |
+ \l_@@_yshift_dim |
| 1105 |
) |
| 1106 |
} |
| 1107 |
} |
| 1108 |
{ |
| 1109 |
\draw_point:n |
| 1110 |
{ |
| 1111 |
(#1, #2) |
| 1112 |
+ ( \l_@@_xshift_dim , \l_@@_yshift_dim ) |
| 1113 |
} |
| 1114 |
} |
| 1115 |
} |
| 1116 |
% \end{macrocode} |
| 1117 |
% \end{macro} |
| 1118 |
% \end{macro} |
| 1119 |
% |
| 1120 |
% \begin{macro}[EXP]{\@@_point_transform_noshift:n} |
| 1121 |
% \begin{macro}[EXP]{\@@_point_transform_noshift:nn} |
| 1122 |
% A version with no shift: used for internal purposes. |
| 1123 |
% \begin{macrocode} |
| 1124 |
\cs_new:Npn \@@_point_transform_noshift:n #1 |
| 1125 |
{ |
| 1126 |
\@@_point_process:nn |
| 1127 |
{ \@@_point_transform_noshift:nn } |
| 1128 |
{ \draw_point:n {#1} } |
| 1129 |
} |
| 1130 |
\cs_new:Npn \@@_point_transform_noshift:nn #1#2 |
| 1131 |
{ |
| 1132 |
\bool_if:NTF \l_@@_matrix_active_bool |
| 1133 |
{ |
| 1134 |
\draw_point:n |
| 1135 |
{ |
| 1136 |
( |
| 1137 |
\l_@@_matrix_a_fp * #1 |
| 1138 |
+ \l_@@_matrix_c_fp * #2 |
| 1139 |
) |
| 1140 |
, |
| 1141 |
( |
| 1142 |
\l_@@_matrix_b_fp * #1 |
| 1143 |
+ \l_@@_matrix_d_fp * #2 |
| 1144 |
) |
| 1145 |
} |
| 1146 |
} |
| 1147 |
{ \draw_point:n { (#1, #2) } } |
| 1148 |
} |
| 1149 |
% \end{macrocode} |
| 1150 |
% \end{macro} |
| 1151 |
% \end{macro} |
| 1152 |
% |
| 1153 |
% \begin{macrocode} |
| 1154 |
%</package> |
| 1155 |
% \end{macrocode} |
| 1156 |
% |
| 1157 |
% \end{implementation} |
| 1158 |
% |
| 1159 |
% \PrintIndex |