| 1 |
% Copyright 2019 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesFileRCS{pgfcorepoints.code.tex} |
| 11 |
|
| 12 |
\newdimen\pgf@picminx |
| 13 |
\newdimen\pgf@picmaxx |
| 14 |
\newdimen\pgf@picminy |
| 15 |
\newdimen\pgf@picmaxy |
| 16 |
|
| 17 |
\newdimen\pgf@pathminx |
| 18 |
\newdimen\pgf@pathmaxx |
| 19 |
\newdimen\pgf@pathminy |
| 20 |
\newdimen\pgf@pathmaxy |
| 21 |
|
| 22 |
\newif\ifpgf@relevantforpicturesize |
| 23 |
|
| 24 |
\def\pgf@process#1{{#1\global\pgf@x=\pgf@x\global\pgf@y=\pgf@y}} |
| 25 |
|
| 26 |
% Save a point. |
| 27 |
% |
| 28 |
% #1 = macro for storing point. |
| 29 |
% #2 = code for point (should define x and y) |
| 30 |
% |
| 31 |
% Example: |
| 32 |
% |
| 33 |
% \pgfextract@process\mypoint{\pgf@x=10pt \pgf@y10pt} |
| 34 |
% \pgfextract@process\myarcpoint{\pgfpointpolar{30}{5cm and 2cm}} |
| 35 |
|
| 36 |
\def\pgfextract@process#1#2{% |
| 37 |
\pgf@process{#2}% |
| 38 |
\edef#1{\noexpand\global\pgf@x=\the\pgf@x\noexpand\relax\noexpand\global\pgf@y=\the\pgf@y\noexpand\relax}% |
| 39 |
} |
| 40 |
% This needed until old shapes code changed. |
| 41 |
\let\pgfsavepgf@process\pgfextract@process% |
| 42 |
|
| 43 |
|
| 44 |
% Return a point |
| 45 |
% |
| 46 |
% #1 = x-coordinate of the point |
| 47 |
% #2 = y-coordinate of the point |
| 48 |
% |
| 49 |
% x = #1 |
| 50 |
% y = #2 |
| 51 |
% |
| 52 |
% Example: |
| 53 |
% |
| 54 |
% \pgfpathmoveto{\pgfpoint{2pt+3cm}{3cm}} |
| 55 |
|
| 56 |
\def\pgfpoint#1#2{% |
| 57 |
\pgfmathsetlength\pgf@x{#1}% |
| 58 |
\pgfmathsetlength\pgf@y{#2}\ignorespaces} |
| 59 |
|
| 60 |
|
| 61 |
% Quickly a point |
| 62 |
% |
| 63 |
% #1 = x-coordinate of the point (no calculations done) |
| 64 |
% #2 = y-coordinate of the point (no calculations done) |
| 65 |
% |
| 66 |
% x = #1 |
| 67 |
% y = #2 |
| 68 |
% |
| 69 |
% Example: |
| 70 |
% |
| 71 |
% \pgfpathmoveto{\pgfqpoint{2pt}{3cm}} |
| 72 |
|
| 73 |
\def\pgfqpoint#1#2{\global\pgf@x=#1\relax\global\pgf@y=#2\relax} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
% Return the origin. |
| 78 |
% |
| 79 |
% x = 0 |
| 80 |
% y = 0 |
| 81 |
% |
| 82 |
% Example: |
| 83 |
% |
| 84 |
% \pgfpathmoveto{\pgfpointorigin} |
| 85 |
|
| 86 |
\def\pgfpointorigin{\global\pgf@x=0pt \global\pgf@y=\pgf@x\ignorespaces} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
% Return a transformed point |
| 91 |
% |
| 92 |
% #1 = a point |
| 93 |
% |
| 94 |
% Description: |
| 95 |
% |
| 96 |
% This command applies pgf's current transformation matrix to the |
| 97 |
% given point. Normally, this is done automatically by commands like |
| 98 |
% lineto or moveto, but sometimes you may wish to access a transformed |
| 99 |
% point yourself. In the below example, this command is used for a low level |
| 100 |
% coordinate system shift. |
| 101 |
% |
| 102 |
% Example: |
| 103 |
% |
| 104 |
% \begin{pgflowleveltransformshiftscope}{\pgfpointtransformed{\pgfpointorigin}} |
| 105 |
% \pgfbox[center,center]{Hi!} |
| 106 |
% \end{pgflowleveltransformshiftscope} |
| 107 |
|
| 108 |
\def\pgfpointtransformed#1{% |
| 109 |
\pgf@process{% |
| 110 |
#1% |
| 111 |
\pgf@pos@transform@glob% |
| 112 |
}% |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
% Return the difference vector of two points. |
| 117 |
% |
| 118 |
% #1 = start of vector |
| 119 |
% #2 = end of vector |
| 120 |
% |
| 121 |
% x = x-component of difference |
| 122 |
% y = y-component of difference |
| 123 |
% |
| 124 |
% Example: |
| 125 |
% |
| 126 |
% \pgfpathmoveto{\pgfpointdiff{\pgfpointxy{1}{1}}{\pgfpointxy{2}{3}}} |
| 127 |
|
| 128 |
\def\pgfpointdiff#1#2{% |
| 129 |
\pgf@process{#1}% |
| 130 |
\pgf@xa=\pgf@x% |
| 131 |
\pgf@ya=\pgf@y% |
| 132 |
\pgf@process{#2}% |
| 133 |
\global\advance\pgf@x by-\pgf@xa\relax% |
| 134 |
\global\advance\pgf@y by-\pgf@ya\relax\ignorespaces} |
| 135 |
|
| 136 |
% Add two vectors. |
| 137 |
% |
| 138 |
% #1 = first vector |
| 139 |
% #2 = second vector |
| 140 |
% |
| 141 |
% x = x-component of addition |
| 142 |
% y = y-component of addition |
| 143 |
% |
| 144 |
% Example: |
| 145 |
% |
| 146 |
% \pgfpathmoveto{\pgfpointadd{\pgfpointxy{0}{1}}{\pgfpointxy{2}{3}}} |
| 147 |
|
| 148 |
\def\pgfpointadd#1#2{% |
| 149 |
\pgf@process{#1}% |
| 150 |
\pgf@xa=\pgf@x% |
| 151 |
\pgf@ya=\pgf@y% |
| 152 |
\pgf@process{#2}% |
| 153 |
\global\advance\pgf@x by\pgf@xa% |
| 154 |
\global\advance\pgf@y by\pgf@ya} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
% Multiply a vector by a factor. |
| 159 |
% |
| 160 |
% #1 = factor |
| 161 |
% #2 = vector |
| 162 |
% |
| 163 |
% Example: |
| 164 |
% |
| 165 |
% \pgfpointscale{2}{\pgfpointxy{0}{1}} |
| 166 |
|
| 167 |
\def\pgfpointscale#1#2{% |
| 168 |
\pgf@process{#2}% |
| 169 |
\pgfmathparse{#1}% |
| 170 |
\global\pgf@x=\pgfmathresult\pgf@x% |
| 171 |
\global\pgf@y=\pgfmathresult\pgf@y% |
| 172 |
} |
| 173 |
% A "quick" variant of \pgfpointscale which doesn't invoke the math parser for '#1'. |
| 174 |
% #1 must be a number without units, no registers are accepted. |
| 175 |
\def\pgfqpointscale#1#2{% |
| 176 |
\pgf@process{#2}% |
| 177 |
\global\pgf@x=#1\pgf@x% |
| 178 |
\global\pgf@y=#1\pgf@y% |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
% The intersection of two lines |
| 183 |
% |
| 184 |
% #1 = point on first line |
| 185 |
% #2 = another point on first line |
| 186 |
% #3 = point on second line |
| 187 |
% #4 = another point on second line |
| 188 |
% |
| 189 |
% Returns the intersection of the two lines. If there is no |
| 190 |
% intersection or if the points #1 and #2 or the points #3 and #4 are |
| 191 |
% identical, the behaviour is not specified. |
| 192 |
% |
| 193 |
% Example: |
| 194 |
% |
| 195 |
% \pgfpointintersectionoflines{\pgfpointxy{0}{1}}{\pgfpointxy{1}{0}}{\pgfpointxy{2}{2}}{\pgfpointxy{3}{4}} |
| 196 |
|
| 197 |
\def\pgfpointintersectionoflines#1#2#3#4{% |
| 198 |
{% |
| 199 |
% |
| 200 |
% Compute orthogonal vector to #1--#2 |
| 201 |
% |
| 202 |
\pgf@process{#2}% |
| 203 |
\pgf@xa=\pgf@x% |
| 204 |
\pgf@ya=\pgf@y% |
| 205 |
\pgf@process{#1}% |
| 206 |
\advance\pgf@xa by-\pgf@x% |
| 207 |
\advance\pgf@ya by-\pgf@y% |
| 208 |
\pgf@ya=-\pgf@ya% |
| 209 |
% Normalise a bit |
| 210 |
\c@pgf@counta=\pgf@xa% |
| 211 |
\ifnum\c@pgf@counta<0\relax% |
| 212 |
\c@pgf@counta=-\c@pgf@counta\relax% |
| 213 |
\fi% |
| 214 |
\c@pgf@countb=\pgf@ya% |
| 215 |
\ifnum\c@pgf@countb<0\relax% |
| 216 |
\c@pgf@countb=-\c@pgf@countb\relax% |
| 217 |
\fi% |
| 218 |
\advance\c@pgf@counta by\c@pgf@countb\relax% |
| 219 |
\divide\c@pgf@counta by 65536\relax% |
| 220 |
\ifnum\c@pgf@counta>0\relax% |
| 221 |
\divide\pgf@xa by\c@pgf@counta\relax% |
| 222 |
\divide\pgf@ya by\c@pgf@counta\relax% |
| 223 |
\fi% |
| 224 |
% |
| 225 |
% Compute projection |
| 226 |
% |
| 227 |
\pgf@xc=\pgf@sys@tonumber{\pgf@ya}\pgf@x% |
| 228 |
\advance\pgf@xc by\pgf@sys@tonumber{\pgf@xa}\pgf@y% |
| 229 |
% |
| 230 |
% The orthogonal vector is (\pgf@ya,\pgf@xa) |
| 231 |
% |
| 232 |
% |
| 233 |
% Compute orthogonal vector to #3--#4 |
| 234 |
% |
| 235 |
\pgf@process{#4}% |
| 236 |
\pgf@xb=\pgf@x% |
| 237 |
\pgf@yb=\pgf@y% |
| 238 |
\pgf@process{#3}% |
| 239 |
\advance\pgf@xb by-\pgf@x% |
| 240 |
\advance\pgf@yb by-\pgf@y% |
| 241 |
\pgf@yb=-\pgf@yb% |
| 242 |
% Normalise a bit |
| 243 |
\c@pgf@counta=\pgf@xb% |
| 244 |
\ifnum\c@pgf@counta<0\relax% |
| 245 |
\c@pgf@counta=-\c@pgf@counta\relax% |
| 246 |
\fi% |
| 247 |
\c@pgf@countb=\pgf@yb% |
| 248 |
\ifnum\c@pgf@countb<0\relax% |
| 249 |
\c@pgf@countb=-\c@pgf@countb\relax% |
| 250 |
\fi% |
| 251 |
\advance\c@pgf@counta by\c@pgf@countb\relax% |
| 252 |
\divide\c@pgf@counta by 65536\relax% |
| 253 |
\ifnum\c@pgf@counta>0\relax% |
| 254 |
\divide\pgf@xb by\c@pgf@counta\relax% |
| 255 |
\divide\pgf@yb by\c@pgf@counta\relax% |
| 256 |
\fi% |
| 257 |
% |
| 258 |
% Compute projection |
| 259 |
% |
| 260 |
\pgf@yc=\pgf@sys@tonumber{\pgf@yb}\pgf@x% |
| 261 |
\advance\pgf@yc by\pgf@sys@tonumber{\pgf@xb}\pgf@y% |
| 262 |
% |
| 263 |
% The orthogonal vector is (\pgf@yb,\pgf@xb) |
| 264 |
% |
| 265 |
% Setup transformation matrix (this is just to use the matrix |
| 266 |
% inversion) |
| 267 |
% |
| 268 |
\pgfsettransform{{\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@xb}{0pt}{0pt}}% |
| 269 |
\pgftransforminvert% |
| 270 |
\pgf@process{\pgfpointtransformed{\pgfpoint{\pgf@xc}{\pgf@yc}}}% |
| 271 |
}% |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
% The intersection of two circles |
| 276 |
% |
| 277 |
% #1 = center of first circle |
| 278 |
% #2 = center of second circle |
| 279 |
% #3 = radius of first circle |
| 280 |
% #4 = radius of second circle |
| 281 |
% #5 = solution number |
| 282 |
% |
| 283 |
% Returns the intersection of the two circles. If #5 is to "1", the |
| 284 |
% first intersection is returned, otherwise the second. If the circles |
| 285 |
% do not intersect, an error may occur. |
| 286 |
% |
| 287 |
% Example: |
| 288 |
% |
| 289 |
% \pgfpointintersectionofcircles{\pgfpointxy{0}{1}}{\pgfpointxy{1}{0}}{1cm}{1cm}{1} |
| 290 |
|
| 291 |
\def\pgfpointintersectionofcircles#1#2#3#4#5{% |
| 292 |
{% |
| 293 |
% Store first point in (xa,ya) and radius in xc. |
| 294 |
\pgf@process{#1}% |
| 295 |
\pgf@xa=\pgf@x% |
| 296 |
\pgf@ya=\pgf@y% |
| 297 |
\pgfmathsetlength{\pgf@xc}{#3}% |
| 298 |
% Store second point in (xb,yb) and radius in yc. |
| 299 |
\pgf@process{#2}% |
| 300 |
\pgf@xb=\pgf@x% |
| 301 |
\pgf@yb=\pgf@y% |
| 302 |
\pgfmathsetlength{\pgf@yc}{#4}% |
| 303 |
% |
| 304 |
% Ok, now make numbers smaller, in case they are too large |
| 305 |
% |
| 306 |
\c@pgf@counta=1\relax% |
| 307 |
\loop% |
| 308 |
\pgf@scale@downfalse% |
| 309 |
\ifdim\pgf@xc>50pt\relax% |
| 310 |
\pgf@scale@downtrue% |
| 311 |
\fi% |
| 312 |
\ifdim\pgf@yc>50pt\relax% |
| 313 |
\pgf@scale@downtrue% |
| 314 |
\fi% |
| 315 |
\ifpgf@scale@down% |
| 316 |
\multiply\c@pgf@counta by2\relax% |
| 317 |
\divide\pgf@xa by2\relax% |
| 318 |
\divide\pgf@ya by2\relax% |
| 319 |
\divide\pgf@xb by2\relax% |
| 320 |
\divide\pgf@yb by2\relax% |
| 321 |
\divide\pgf@xc by2\relax% |
| 322 |
\divide\pgf@yc by2\relax% |
| 323 |
\repeat% |
| 324 |
% The following code is taken from the Dr. Math internet forum: |
| 325 |
% |
| 326 |
% Let the centers be: (a,b), (c,d) |
| 327 |
% Let the radii be: r, s |
| 328 |
% |
| 329 |
% e = c - a [difference in x coordinates] |
| 330 |
% f = d - b [difference in y coordinates] |
| 331 |
% p = sqrt(e^2 + f^2) [distance between centers] |
| 332 |
% k = (p^2 + r^2 - s^2)/(2p) [distance from center 1 to line |
| 333 |
% joining points of intersection] |
| 334 |
% x = a + ek/p + (f/p)sqrt(r^2 - k^2) |
| 335 |
% y = b + fk/p - (e/p)sqrt(r^2 - k^2) |
| 336 |
% OR |
| 337 |
% x = a + ek/p - (f/p)sqrt(r^2 - k^2) |
| 338 |
% y = b + fk/p + (e/p)sqrt(r^2 - k^2) |
| 339 |
% |
| 340 |
% Since we are running low on registers, use |
| 341 |
% \dimen0 for e |
| 342 |
% \dimen1 for f |
| 343 |
% \dimen2 for p |
| 344 |
% \dimen3 for p^2 |
| 345 |
% \dimen4 for k |
| 346 |
% \dimen5 for 1/p |
| 347 |
% \dimen6 for sqrt(r^2 - k^2) |
| 348 |
% \dimen7 for k^2 |
| 349 |
% \dimen8 for k/p |
| 350 |
% \dimen9 for sqrt(r^2 - k^2)/p |
| 351 |
% Also note that: |
| 352 |
% \pgf@xa for a |
| 353 |
% \pgf@ya for b |
| 354 |
% \pgf@xb for c |
| 355 |
% \pgf@yb for d |
| 356 |
% \pgf@xc for r |
| 357 |
% \pgf@yc for s |
| 358 |
% |
| 359 |
% Now: |
| 360 |
% e = c - a |
| 361 |
\dimen0=\pgf@xb% |
| 362 |
\advance\dimen0 by-\pgf@xa% |
| 363 |
% f = d - b |
| 364 |
\dimen1=\pgf@yb% |
| 365 |
\advance\dimen1 by-\pgf@ya% |
| 366 |
% p^2 = e^2 + f^2 |
| 367 |
\pgf@x=\dimen0\relax% |
| 368 |
\pgf@x=\pgf@sys@tonumber{\pgf@x}\pgf@x% |
| 369 |
\dimen3=\pgf@x% |
| 370 |
\pgf@x=\dimen1\relax% |
| 371 |
\advance\dimen3 by\pgf@sys@tonumber{\pgf@x}\pgf@x% |
| 372 |
% p = sqrt(p^2) |
| 373 |
\pgfmathparse{sqrt(\the\dimen3)}% |
| 374 |
\dimen2=\pgfmathresult pt% |
| 375 |
% 1/p = 1/p |
| 376 |
\pgfmathreciprocal@{\pgfmathresult}% |
| 377 |
\dimen5=\pgfmathresult pt% |
| 378 |
% k = (p^2 + r^2 - s^2)/(2p) |
| 379 |
\dimen4=\dimen3\relax% |
| 380 |
\pgf@x=\pgf@xc% |
| 381 |
\advance\dimen4 by\pgf@sys@tonumber{\pgf@x}\pgf@x\relax% |
| 382 |
\pgf@x=\pgf@yc% |
| 383 |
\advance\dimen4 by-\pgf@sys@tonumber{\pgf@x}\pgf@x\relax% |
| 384 |
\dimen4=.5\dimen4% |
| 385 |
\dimen4=\pgf@sys@tonumber{\dimen5}\dimen4% |
| 386 |
% dimen7 is k^2 |
| 387 |
\dimen7=\pgf@sys@tonumber{\dimen4}\dimen4\relax% |
| 388 |
% dimen6 is sqrt(r^2 - k^2) |
| 389 |
\pgfmathparse{sqrt(\pgf@sys@tonumber{\pgf@xc}\pgf@xc-\the\dimen7)}% |
| 390 |
\dimen6=\pgfmathresult pt% |
| 391 |
% dimen8 is k/p |
| 392 |
\dimen8=\pgf@sys@tonumber{\dimen4}\dimen5\relax% |
| 393 |
% dimen9 is sqrt(r^2 - k^2)/p |
| 394 |
\dimen9=\pgf@sys@tonumber{\dimen6}\dimen5\relax% |
| 395 |
\ifnum#5=1\relax% |
| 396 |
% x = a + ek/p + (f/p)sqrt(r^2 - k^2) |
| 397 |
\pgf@x=\pgf@xa% |
| 398 |
\advance\pgf@x by\pgf@sys@tonumber{\dimen0}\dimen8\relax% |
| 399 |
\advance\pgf@x by\pgf@sys@tonumber{\dimen1}\dimen9\relax% |
| 400 |
% y = b + fk/p - (e/p)sqrt(r^2 - k^2) |
| 401 |
\pgf@y=\pgf@ya% |
| 402 |
\advance\pgf@y by\pgf@sys@tonumber{\dimen1}\dimen8\relax% |
| 403 |
%temp |
| 404 |
\pgf@xb=\pgf@sys@tonumber{\dimen0}\dimen9% |
| 405 |
\pgf@xb=-\pgf@xb% |
| 406 |
\advance\pgf@y by\pgf@xb\relax% |
| 407 |
\else% |
| 408 |
% x = a + ek/p - (f/p)sqrt(r^2 - k^2) |
| 409 |
\pgf@x=\pgf@xa% |
| 410 |
\advance\pgf@x by\pgf@sys@tonumber{\dimen0}\dimen8\relax% |
| 411 |
%temp |
| 412 |
\pgf@xb=\pgf@sys@tonumber{\dimen1}\dimen9% |
| 413 |
\pgf@xb=-\pgf@xb% |
| 414 |
\advance\pgf@x by\pgf@xb\relax% |
| 415 |
% y = b + fk/p + (e/p)sqrt(r^2 - k^2) |
| 416 |
\pgf@y=\pgf@ya% |
| 417 |
\advance\pgf@y by\pgf@sys@tonumber{\dimen1}\dimen8\relax% |
| 418 |
\advance\pgf@y by\pgf@sys@tonumber{\dimen0}\dimen9\relax% |
| 419 |
\fi% |
| 420 |
\pgf@x=\c@pgf@counta\pgf@x% |
| 421 |
\pgf@y=\c@pgf@counta\pgf@y% |
| 422 |
\pgf@process{}% get results outside |
| 423 |
}% |
| 424 |
} |
| 425 |
\newif\ifpgf@scale@down |
| 426 |
|
| 427 |
|
| 428 |
% Returns point on a line from #2 to #3 at time #1. |
| 429 |
% |
| 430 |
% #1 = a time, where 0 is the start and 1 is the end |
| 431 |
% #2 = start point |
| 432 |
% #3 = end point |
| 433 |
% |
| 434 |
% x = x-component of #1*start + (1-#1)*end |
| 435 |
% y = y-component of #1*start + (1-#1)*end |
| 436 |
% xa/ya = #1*start + (1-#1)*end |
| 437 |
% xb/yb = start point |
| 438 |
% xc/yc = end point |
| 439 |
% |
| 440 |
% Example: |
| 441 |
% |
| 442 |
% % Middle of (1,1) and (2,3) |
| 443 |
% \pgfpathmoveto{\pgfpointlineattime{0.5}{\pgfpointxy{0}{1}}{\pgfpointxy{2}{3}}} |
| 444 |
|
| 445 |
\def\pgfpointlineattime#1#2#3{% |
| 446 |
\pgf@process{#3}% |
| 447 |
\pgf@xa\pgf@x% |
| 448 |
\pgf@ya\pgf@y% |
| 449 |
\pgf@xc\pgf@x% |
| 450 |
\pgf@yc\pgf@y% |
| 451 |
\pgf@process{#2}% |
| 452 |
\pgf@xb\pgf@x% |
| 453 |
\pgf@yb\pgf@y% |
| 454 |
\pgfmathsetmacro\pgf@temp{#1}% |
| 455 |
\advance\pgf@xa by-\pgf@x% |
| 456 |
\advance\pgf@ya by-\pgf@y% |
| 457 |
\global\advance\pgf@x by\pgf@temp\pgf@xa% |
| 458 |
\global\advance\pgf@y by\pgf@temp\pgf@ya% |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
% Move point #2 #1 many units in the direction of #3. |
| 463 |
% |
| 464 |
% #1 = a distance |
| 465 |
% #2 = start point |
| 466 |
% #3 = end point |
| 467 |
% |
| 468 |
% Description: |
| 469 |
% |
| 470 |
% Computes |
| 471 |
% |
| 472 |
% x/y = start + #1*(normalise(end-start)) |
| 473 |
% |
| 474 |
% and additionally |
| 475 |
% |
| 476 |
% xa/ya = #1*(normalise(end-start)) |
| 477 |
% xb/yb = start |
| 478 |
% xc/yc = end |
| 479 |
% |
| 480 |
% Example: |
| 481 |
% |
| 482 |
% \pgfpathmoveto{\pgfpointlineatdistance{2pt}{\pgfpointxy{0}{1}}{\pgfpointxy{2}{3}}} |
| 483 |
% \pgfpathlineto{\pgfpointlineatdistance{3pt}{\pgfpointxy{2}{3}}{\pgfpointxy{0}{1}}} |
| 484 |
|
| 485 |
\def\pgfpointlineatdistance#1#2#3{% |
| 486 |
\pgfmathsetlength\pgf@xa{#1}% |
| 487 |
\pgf@process{#2}% |
| 488 |
\pgf@xb\pgf@x% xb/yb = start point |
| 489 |
\pgf@yb\pgf@y% |
| 490 |
\pgf@process{#3}% |
| 491 |
\pgf@xc\pgf@x% |
| 492 |
\pgf@yc\pgf@y% |
| 493 |
\global\advance\pgf@x by-\pgf@xb\relax% |
| 494 |
\global\advance\pgf@y by-\pgf@yb\relax% |
| 495 |
\pgf@process{\pgfpointnormalised{}}% x/y = normalised vector |
| 496 |
\pgf@ya=\pgf@xa\relax% |
| 497 |
\pgf@xa=\pgf@sys@tonumber{\pgf@x}\pgf@xa% |
| 498 |
\pgf@ya=\pgf@sys@tonumber{\pgf@y}\pgf@ya% |
| 499 |
\global\pgf@x=\pgf@xb\relax% |
| 500 |
\global\pgf@y=\pgf@yb\relax% |
| 501 |
\global\advance\pgf@x by\pgf@xa\relax% |
| 502 |
\global\advance\pgf@y by\pgf@ya\relax% |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
% Returns point on a curve from #2 to #5 with controls #3 and #4 at time #1. |
| 507 |
% |
| 508 |
% #1 = a time |
| 509 |
% #2 = start point |
| 510 |
% #3 = first control point |
| 511 |
% #4 = second control point |
| 512 |
% #5 = end point |
| 513 |
% |
| 514 |
% x = x-component of place on the curve at time t |
| 515 |
% y = y-component of place on the curve at time t |
| 516 |
% |
| 517 |
% Additionally, (\pgf@xa,\pgf@ya) and (\pgf@xb,\pgf@yb) will be on a |
| 518 |
% tangent to the point on the curve (this can be useful for computing |
| 519 |
% a label rotation). (\pgf@xc,\pgf@yc) will be equal to the end |
| 520 |
% point. \pgf@time@s will equal the value of #1 and \pgf@time@t will |
| 521 |
% equal 1-#1. |
| 522 |
% |
| 523 |
% Example: |
| 524 |
% |
| 525 |
% % Middle of (1,1) and (2,3) |
| 526 |
% \pgfpathmoveto{\pgfpointcurveattime{0.5}{\pgfpointxy{0}{1}}{\pgfpointxy{1}{1}}{\pgfpointxy{1}{1}}{\pgfpointxy{2}{3}}} |
| 527 |
|
| 528 |
\def\pgfpointcurveattime#1#2#3#4#5{% |
| 529 |
\pgfmathparse{#1}% |
| 530 |
\let\pgf@time@s=\pgfmathresult% |
| 531 |
\global\pgf@x=\pgfmathresult pt% |
| 532 |
\global\pgf@x=-\pgf@x% |
| 533 |
\advance\pgf@x by 1pt% |
| 534 |
\edef\pgf@time@t{\pgf@sys@tonumber{\pgf@x}}% |
| 535 |
\pgf@process{#5}% |
| 536 |
\pgf@xc=\pgf@x% |
| 537 |
\pgf@yc=\pgf@y% |
| 538 |
\pgf@process{#4}% |
| 539 |
\pgf@xb=\pgf@x% |
| 540 |
\pgf@yb=\pgf@y% |
| 541 |
\pgf@process{#3}% |
| 542 |
\pgf@xa=\pgf@x% |
| 543 |
\pgf@ya=\pgf@y% |
| 544 |
\pgf@process{#2}% |
| 545 |
% First iteration: |
| 546 |
\global\pgf@x=\pgf@time@t\pgf@x\global\advance\pgf@x by\pgf@time@s\pgf@xa% |
| 547 |
\global\pgf@y=\pgf@time@t\pgf@y\global\advance\pgf@y by\pgf@time@s\pgf@ya% |
| 548 |
\pgf@xa=\pgf@time@t\pgf@xa\advance\pgf@xa by\pgf@time@s\pgf@xb% |
| 549 |
\pgf@ya=\pgf@time@t\pgf@ya\advance\pgf@ya by\pgf@time@s\pgf@yb% |
| 550 |
\pgf@xb=\pgf@time@t\pgf@xb\advance\pgf@xb by\pgf@time@s\pgf@xc% |
| 551 |
\pgf@yb=\pgf@time@t\pgf@yb\advance\pgf@yb by\pgf@time@s\pgf@yc% |
| 552 |
% Second iteration: |
| 553 |
\global\pgf@x=\pgf@time@t\pgf@x\global\advance\pgf@x by\pgf@time@s\pgf@xa% |
| 554 |
\global\pgf@y=\pgf@time@t\pgf@y\global\advance\pgf@y by\pgf@time@s\pgf@ya% |
| 555 |
\pgf@xa=\pgf@time@t\pgf@xa\advance\pgf@xa by\pgf@time@s\pgf@xb% |
| 556 |
\pgf@ya=\pgf@time@t\pgf@ya\advance\pgf@ya by\pgf@time@s\pgf@yb% |
| 557 |
% Save x/y |
| 558 |
\pgf@xb=\pgf@x% |
| 559 |
\pgf@yb=\pgf@y% |
| 560 |
% Third iteration: |
| 561 |
\global\pgf@x=\pgf@time@t\pgf@x\global\advance\pgf@x by\pgf@time@s\pgf@xa% |
| 562 |
\global\pgf@y=\pgf@time@t\pgf@y\global\advance\pgf@y by\pgf@time@s\pgf@ya% |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
% Returns point on an arc at a certain "time" |
| 568 |
% |
| 569 |
% #1 = a time |
| 570 |
% #2 = center of a ellipse |
| 571 |
% #3 = 0-degree axis of the ellipse |
| 572 |
% #4 = 90-degree axis of the ellipse |
| 573 |
% #5 = start angle of an arc on the ellipse |
| 574 |
% #6 = end angle of an arc on the ellipse |
| 575 |
% |
| 576 |
% Result: |
| 577 |
% |
| 578 |
% \pgf@x = x-component of place on the arc at time t |
| 579 |
% \pgf@y = y-component of place on the arc at time t |
| 580 |
% |
| 581 |
% Additionally, (\pgf@xa,\pgf@ya) will be a tangent to the |
| 582 |
% point on the arc (this can be useful for computing a label rotation). |
| 583 |
% |
| 584 |
% Example: |
| 585 |
% |
| 586 |
% \pgfpointarcaxesattime{0.25}{\pgfpoint{1cm}{1cm}}{\pgfpoint{1cm}{0cm}}{\pgfpoint{0cm}{1cm}}{1cm}{30}{40} |
| 587 |
|
| 588 |
\def\pgfpointarcaxesattime#1#2#3#4#5#6{% |
| 589 |
\pgfmathsetmacro\pgf@angle@start{#5}% |
| 590 |
\pgfmathsetmacro\pgf@angle@end{#6}% |
| 591 |
\pgfmathparse{#1}% |
| 592 |
\global\pgf@x=\pgfmathresult pt% |
| 593 |
\global\pgf@x=-\pgf@x% |
| 594 |
\advance\pgf@x by 1pt% |
| 595 |
\pgfmathsetmacro\pgf@angle@mid{\pgf@angle@end*\pgfmathresult+\pgf@angle@start*\pgf@sys@tonumber{\pgf@x}}% |
| 596 |
\pgfmathcos@{\pgf@angle@mid}% |
| 597 |
\let\pgf@angle@cos\pgfmathresult% |
| 598 |
\pgfmathsin@{\pgf@angle@mid}% |
| 599 |
\let\pgf@angle@sin\pgfmathresult% |
| 600 |
\pgf@process{#3}% |
| 601 |
\edef\pgf@angle@zero@axis{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}} |
| 602 |
\pgf@process{#4}% |
| 603 |
\edef\pgf@angle@ninety@axis{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}} |
| 604 |
% Compute tangent |
| 605 |
\pgf@process{\pgfpointadd{\pgfpointscale{\pgf@angle@sin}{\pgf@angle@zero@axis}}% |
| 606 |
{\pgfpointscale{-\pgf@angle@cos}{\pgf@angle@ninety@axis}}}% |
| 607 |
\ifdim\pgf@angle@start pt>\pgf@angle@end pt% |
| 608 |
\pgf@xa=\pgf@x% |
| 609 |
\pgf@ya=\pgf@y% |
| 610 |
\else% |
| 611 |
\pgf@xa=-\pgf@x% |
| 612 |
\pgf@ya=-\pgf@y% |
| 613 |
\fi% |
| 614 |
% Compute position |
| 615 |
\pgf@process{\pgfpointadd{#2}{% |
| 616 |
\pgfpointadd{\pgfpointscale{\pgf@angle@cos}{\pgf@angle@zero@axis}}% |
| 617 |
{\pgfpointscale{\pgf@angle@sin}{\pgf@angle@ninety@axis}}}}% |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
% Internal registers |
| 623 |
\newdimen\pgf@xx |
| 624 |
\newdimen\pgf@xy |
| 625 |
\newdimen\pgf@yx |
| 626 |
\newdimen\pgf@yy |
| 627 |
\newdimen\pgf@zx |
| 628 |
\newdimen\pgf@zy |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
% A polar coordinate |
| 633 |
% |
| 634 |
% #1 = a degree |
| 635 |
% #2 = a radius -- either a dimension or two dimensions separated by |
| 636 |
% " and ". |
| 637 |
% |
| 638 |
% x = (first dimension in #2) * cos(#1) |
| 639 |
% y = (second dimension in #2) * sin(#2) |
| 640 |
% |
| 641 |
% Example: |
| 642 |
% |
| 643 |
% \pgfpathmoveto{\pgfpointpolar{30}{1cm}} |
| 644 |
% \pgfpathlineto{\pgfpointpolar{30}{1cm and 2cm}} |
| 645 |
|
| 646 |
\def\pgfpointpolar#1#2{% |
| 647 |
\pgfutil@in@{and }{#2}% |
| 648 |
\ifpgfutil@in@% |
| 649 |
\pgf@polar@#2\@@% |
| 650 |
\else% |
| 651 |
\pgf@polar@#2 and #2\@@% |
| 652 |
\fi% |
| 653 |
\pgfmathparse{#1}% |
| 654 |
\let\pgfpoint@angle=\pgfmathresult% |
| 655 |
\pgfmathcos@{\pgfpoint@angle}% |
| 656 |
\global\pgf@x=\pgfmathresult\pgf@x% |
| 657 |
\pgfmathsin@{\pgfpoint@angle}% |
| 658 |
\global\pgf@y=\pgfmathresult\pgf@y% |
| 659 |
} |
| 660 |
|
| 661 |
\def\pgf@polar@#1and #2\@@{% |
| 662 |
\pgfmathsetlength{\pgf@y}{#2}% |
| 663 |
\pgfmathsetlength{\pgf@x}{#1}% |
| 664 |
} |
| 665 |
|
| 666 |
% Quick version of the polar coordinate method |
| 667 |
|
| 668 |
\def\pgfqpointpolar#1#2{% |
| 669 |
\global\pgf@x=#2% |
| 670 |
\global\pgf@y=\pgf@x% |
| 671 |
\pgfmathcos@{#1}% |
| 672 |
\global\pgf@x=\pgfmathresult\pgf@x% |
| 673 |
\pgfmathsin@{#1}% |
| 674 |
\global\pgf@y=\pgfmathresult\pgf@y\relax% |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
% A polar coordinate in the xy plane. |
| 681 |
% |
| 682 |
% #1 = a degree |
| 683 |
% #2 = a radius given as a number or two radii |
| 684 |
% |
| 685 |
% result = (first dim in #2) * x-vector * cos(#1) + |
| 686 |
% (second dim in #2) * y-vector * sin(#1) |
| 687 |
% |
| 688 |
% Example: |
| 689 |
% |
| 690 |
% \pgfpathmoveto{\pgfpointpolarxy{30}{2}} |
| 691 |
|
| 692 |
\def\pgfpointpolarxy#1#2{% |
| 693 |
\pgfutil@in@{and }{#2}% |
| 694 |
\ifpgfutil@in@% |
| 695 |
\pgf@polarxy@#2\@@% |
| 696 |
\else% |
| 697 |
\pgf@polarxy@#2and #2\@@% |
| 698 |
\fi% |
| 699 |
\pgfmathparse{#1}% |
| 700 |
\let\pgfpoint@angle=\pgfmathresult% |
| 701 |
\pgfmathcos@{\pgfpoint@angle}% |
| 702 |
\pgf@xa=\pgfmathresult\pgf@xa% |
| 703 |
\pgfmathsin@{\pgfpoint@angle}% |
| 704 |
\pgf@ya=\pgfmathresult\pgf@ya% |
| 705 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@xa}\pgf@xx% |
| 706 |
\global\advance\pgf@x by \pgf@sys@tonumber{\pgf@ya}\pgf@yx% |
| 707 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@xa}\pgf@xy% |
| 708 |
\global\advance\pgf@y by \pgf@sys@tonumber{\pgf@ya}\pgf@yy} |
| 709 |
|
| 710 |
\def\pgf@polarxy@#1and #2\@@{% |
| 711 |
\pgfmathsetlength{\pgf@xa}{#1}% |
| 712 |
\pgfmathsetlength{\pgf@ya}{#2}% |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
% A cylindrical coordinate. |
| 718 |
% |
| 719 |
% #1 = a degree |
| 720 |
% #2 = a radius given as a number |
| 721 |
% #3 = a height given as a number |
| 722 |
% |
| 723 |
% result = #2*(x-vector * cos(#1) + y-vector * sin(#1)) + #3*z-vector |
| 724 |
% |
| 725 |
% Example: |
| 726 |
% |
| 727 |
% \pgfpathmoveto{\pgfpointcylindrical{30}{2}{1}} |
| 728 |
|
| 729 |
\def\pgfpointcylindrical#1#2#3{% |
| 730 |
\pgfpointpolarxy{#1}{#2}% |
| 731 |
\pgfmathparse{#3}% |
| 732 |
\global\advance\pgf@x by \pgfmathresult\pgf@zx% |
| 733 |
\global\advance\pgf@y by \pgfmathresult\pgf@zy} |
| 734 |
|
| 735 |
|
| 736 |
% A spherical coordinate. |
| 737 |
% |
| 738 |
% #1 = a longitude |
| 739 |
% #2 = a latitude |
| 740 |
% #3 = a radius |
| 741 |
% |
| 742 |
% result = #3*(cos(#2)*(x-vector * cos(#1) + y-vector * sin(#1)) + sin(#2)*z-vector) |
| 743 |
% |
| 744 |
% Example: |
| 745 |
% |
| 746 |
% \pgfpathmoveto{\pgfpointspherical{30}{30}{2}} |
| 747 |
|
| 748 |
\def\pgfpointspherical#1#2#3{% |
| 749 |
\pgfmathparse{#1}% |
| 750 |
\let\pgfpoint@angle=\pgfmathresult% |
| 751 |
\pgfmathsin@{\pgfpoint@angle}% |
| 752 |
\pgf@xb=\pgfmathresult\pgf@xx% |
| 753 |
\pgf@yb=\pgfmathresult\pgf@xy% |
| 754 |
\pgfmathcos@{\pgfpoint@angle}% |
| 755 |
\advance\pgf@xb by \pgfmathresult\pgf@yx% |
| 756 |
\advance\pgf@yb by \pgfmathresult\pgf@yy% |
| 757 |
% |
| 758 |
\pgfmathparse{#2}% |
| 759 |
\let\pgfpoint@angle=\pgfmathresult% |
| 760 |
\pgfmathcos@{\pgfpoint@angle}% |
| 761 |
\pgf@xc=\pgfmathresult\pgf@xb% |
| 762 |
\pgf@yc=\pgfmathresult\pgf@yb% |
| 763 |
\pgfmathsin@{\pgfpoint@angle}% |
| 764 |
\advance\pgf@xc by \pgfmathresult\pgf@zx% |
| 765 |
\advance\pgf@yc by \pgfmathresult\pgf@zy% |
| 766 |
\pgfmathparse{#3}% |
| 767 |
\global\pgf@x=\pgfmathresult\pgf@xc% |
| 768 |
\global\pgf@y=\pgfmathresult\pgf@yc\relax% |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
% Store the vector #1 * x-vec + #2 * y-vec |
| 773 |
% |
| 774 |
% #1 = a factor for the x-vector |
| 775 |
% #2 = a factor for the y-vector |
| 776 |
% |
| 777 |
% x = x-component of result vector |
| 778 |
% y = y-component of result vector |
| 779 |
% |
| 780 |
% Description: |
| 781 |
% |
| 782 |
% This command can be used to create a new coordinate system |
| 783 |
% without using the rotate/translate/scale commands. This |
| 784 |
% may be useful, if you do not want arrows and line width to |
| 785 |
% be scaled/transformed together with the coordinate system. |
| 786 |
% |
| 787 |
% Example: |
| 788 |
% |
| 789 |
% % Create a slanted rectangle |
| 790 |
% |
| 791 |
% \pgfsetxvec{\pgfpoint{1cm}{1cm}} |
| 792 |
% \pgfsetyvec{\pgfpoint{0cm}{1cm}} |
| 793 |
% |
| 794 |
% \pgfpathmoveto{\pgfpointxy{0}{0}} |
| 795 |
% \pgfpathlineto{\pgfpointxy{1}{0}} |
| 796 |
% \pgfpathlineto{\pgfpointxy{1}{1}} |
| 797 |
% \pgfpathlineto{\pgfpointxy{0}{1}} |
| 798 |
% \pgfclosestroke |
| 799 |
|
| 800 |
\def\pgfpointxy#1#2{% |
| 801 |
\pgfmathparse{#1}% |
| 802 |
\let\pgftemp@x=\pgfmathresult% |
| 803 |
\pgfmathparse{#2}% |
| 804 |
\let\pgftemp@y=\pgfmathresult% |
| 805 |
\global\pgf@x=\pgftemp@x\pgf@xx% |
| 806 |
\global\advance\pgf@x by \pgftemp@y\pgf@yx% |
| 807 |
\global\pgf@y=\pgftemp@x\pgf@xy% |
| 808 |
\global\advance\pgf@y by \pgftemp@y\pgf@yy} |
| 809 |
|
| 810 |
|
| 811 |
% "Quick" variant for \pgfpointxy. |
| 812 |
% |
| 813 |
% Only numbers without unit are allowed here. |
| 814 |
\def\pgfqpointxy#1#2{% |
| 815 |
\global\pgf@x=#1\pgf@xx% |
| 816 |
\global\advance\pgf@x by #2\pgf@yx% |
| 817 |
\global\pgf@y=#1\pgf@xy% |
| 818 |
\global\advance\pgf@y by #2\pgf@yy} |
| 819 |
|
| 820 |
% Store the vector #1 * x-vec + #2 * y-vec + #3 * z-vec |
| 821 |
% |
| 822 |
% #1 = a factor for the x-vector |
| 823 |
% #2 = a factor for the y-vector |
| 824 |
% #3 = a factor for the z-vector |
| 825 |
% |
| 826 |
% x = x-component of result vector |
| 827 |
% y = y-component of result vector |
| 828 |
% |
| 829 |
% |
| 830 |
% Description: |
| 831 |
% |
| 832 |
% This command allows you to use a 3d coordinate system. |
| 833 |
% |
| 834 |
% |
| 835 |
% Example: |
| 836 |
% |
| 837 |
% % Draw a cubus |
| 838 |
% |
| 839 |
% \pgfline{\pgfpointxyz{0}{0}{0}}{\pgfpointxyz{0}{0}{1}} |
| 840 |
% \pgfline{\pgfpointxyz{0}{1}{0}}{\pgfpointxyz{0}{1}{1}} |
| 841 |
% \pgfline{\pgfpointxyz{1}{0}{0}}{\pgfpointxyz{1}{0}{1}} |
| 842 |
% \pgfline{\pgfpointxyz{1}{1}{0}}{\pgfpointxyz{1}{1}{1}} |
| 843 |
% \pgfline{\pgfpointxyz{0}{0}{0}}{\pgfpointxyz{0}{1}{0}} |
| 844 |
% \pgfline{\pgfpointxyz{0}{0}{1}}{\pgfpointxyz{0}{1}{1}} |
| 845 |
% \pgfline{\pgfpointxyz{1}{0}{0}}{\pgfpointxyz{1}{1}{0}} |
| 846 |
% \pgfline{\pgfpointxyz{1}{0}{1}}{\pgfpointxyz{1}{1}{1}} |
| 847 |
% \pgfline{\pgfpointxyz{0}{0}{0}}{\pgfpointxyz{1}{0}{0}} |
| 848 |
% \pgfline{\pgfpointxyz{0}{0}{1}}{\pgfpointxyz{1}{0}{1}} |
| 849 |
% \pgfline{\pgfpointxyz{0}{1}{0}}{\pgfpointxyz{1}{1}{0}} |
| 850 |
% \pgfline{\pgfpointxyz{0}{1}{1}}{\pgfpointxyz{1}{1}{1}} |
| 851 |
|
| 852 |
\def\pgfpointxyz#1#2#3{% |
| 853 |
\pgfmathparse{#1}% |
| 854 |
\let\pgftemp@x=\pgfmathresult% |
| 855 |
\pgfmathparse{#2}% |
| 856 |
\let\pgftemp@y=\pgfmathresult% |
| 857 |
\pgfmathparse{#3}% |
| 858 |
\let\pgftemp@z=\pgfmathresult% |
| 859 |
\global\pgf@x=\pgftemp@x\pgf@xx% |
| 860 |
\global\advance\pgf@x by \pgftemp@y\pgf@yx% |
| 861 |
\global\advance\pgf@x by \pgftemp@z\pgf@zx% |
| 862 |
\global\pgf@y=\pgftemp@x\pgf@xy% |
| 863 |
\global\advance\pgf@y by \pgftemp@y\pgf@yy% |
| 864 |
\global\advance\pgf@y by \pgftemp@z\pgf@zy} |
| 865 |
|
| 866 |
% "Quick" variant for \pgfpointxyz. |
| 867 |
% |
| 868 |
% Only numbers without unit are allowed. |
| 869 |
\def\pgfqpointxyz#1#2#3{% |
| 870 |
\global\pgf@x=#1\pgf@xx% |
| 871 |
\global\advance\pgf@x by #2\pgf@yx% |
| 872 |
\global\advance\pgf@x by #3\pgf@zx% |
| 873 |
\global\pgf@y=#1\pgf@xy% |
| 874 |
\global\advance\pgf@y by #2\pgf@yy% |
| 875 |
\global\advance\pgf@y by #3\pgf@zy} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
% Set the x-vector |
| 880 |
% |
| 881 |
% #1 = a point the is the new x-vector |
| 882 |
% |
| 883 |
% Example: |
| 884 |
% |
| 885 |
% \pgfsetxvec{\pgfpoint{1cm}{0cm}} |
| 886 |
|
| 887 |
\def\pgfsetxvec#1{% |
| 888 |
\pgf@process{#1}% |
| 889 |
\pgf@xx=\pgf@x% |
| 890 |
\pgf@xy=\pgf@y% |
| 891 |
\ignorespaces} |
| 892 |
|
| 893 |
|
| 894 |
% Set the y-vector |
| 895 |
% |
| 896 |
% #1 = a point the is the new y-vector |
| 897 |
% |
| 898 |
% Example: |
| 899 |
% |
| 900 |
% \pgfsetyvec{\pgfpoint{0cm}{1cm}} |
| 901 |
|
| 902 |
\def\pgfsetyvec#1{% |
| 903 |
\pgf@process{#1}% |
| 904 |
\pgf@yx=\pgf@x% |
| 905 |
\pgf@yy=\pgf@y% |
| 906 |
\ignorespaces} |
| 907 |
|
| 908 |
|
| 909 |
% Set the z-vector |
| 910 |
% |
| 911 |
% #1 = a point the is the new z-vector |
| 912 |
% |
| 913 |
% Example: |
| 914 |
% |
| 915 |
% \pgfsetzvec{\pgfpoint{-0.385cm}{-0.385cm}} |
| 916 |
|
| 917 |
\def\pgfsetzvec#1{% |
| 918 |
\pgf@process{#1}% |
| 919 |
\pgf@zx=\pgf@x% |
| 920 |
\pgf@zy=\pgf@y% |
| 921 |
\ignorespaces} |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
% Default values |
| 926 |
\pgfsetxvec{\pgfpoint{1cm}{0cm}} |
| 927 |
\pgfsetyvec{\pgfpoint{0cm}{1cm}} |
| 928 |
\pgfsetzvec{\pgfpoint{-0.385cm}{-0.385cm}} |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
% Normalise a point. |
| 934 |
% |
| 935 |
% #1 = point with coordinates (a,b) |
| 936 |
% |
| 937 |
% x = a/\sqrt(a*a+b*b) |
| 938 |
% y = b/\sqrt(a*a+b*b) |
| 939 |
% |
| 940 |
% Example: |
| 941 |
% |
| 942 |
% \pgfpointnormalised{\pgfpointxy{2}{1}} |
| 943 |
|
| 944 |
\def\pgfpointnormalised#1{% |
| 945 |
\pgf@process{#1}% |
| 946 |
\pgfmathatantwo{\the\pgf@y}{\the\pgf@x}% |
| 947 |
\let\pgf@tmp=\pgfmathresult% |
| 948 |
\pgfmathcos@{\pgf@tmp}% |
| 949 |
\pgf@x=\pgfmathresult pt\relax% |
| 950 |
\pgfmathsin@{\pgf@tmp}% |
| 951 |
\pgf@y=\pgfmathresult pt\relax% |
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
% A point on a rectangle in a certain direction. |
| 959 |
% |
| 960 |
% #1 = a point pointing in some direction (length should be about 1pt, |
| 961 |
% but need not be exact) |
| 962 |
% #2 = upper right corner of a rectangle centered at the origin |
| 963 |
% |
| 964 |
% Returns the intersection of a line starting at the origin going in |
| 965 |
% the given direction and the rectangle's border. |
| 966 |
% |
| 967 |
% Example: |
| 968 |
% |
| 969 |
% \pgfpointborderrectangle{\pgfpointnormalised{\pgfpointxy{2}{1}} |
| 970 |
% {\pgfpoint{1cm}{2cm}} |
| 971 |
|
| 972 |
\def\pgfpointborderrectangle#1#2{% |
| 973 |
\pgf@process{#2}% |
| 974 |
\pgf@xb=\pgf@x% |
| 975 |
\pgf@yb=\pgf@y% |
| 976 |
\pgf@process{#1}% |
| 977 |
% Ok, let's find out about the direction: |
| 978 |
\pgf@xa=\pgf@x% |
| 979 |
\pgf@ya=\pgf@y% |
| 980 |
\ifnum\pgf@xa<0\relax% move into first quadrant |
| 981 |
\global\pgf@x=-\pgf@x% |
| 982 |
\fi% |
| 983 |
\ifnum\pgf@ya<0\relax% |
| 984 |
\global\pgf@y=-\pgf@y% |
| 985 |
\fi% |
| 986 |
\pgf@xc=.125\pgf@x% |
| 987 |
\pgf@yc=.125\pgf@y% |
| 988 |
\c@pgf@counta=\pgf@xc% |
| 989 |
\c@pgf@countb=\pgf@yc% |
| 990 |
\ifnum\c@pgf@countb<\c@pgf@counta% |
| 991 |
\ifnum\c@pgf@counta<255\relax% |
| 992 |
\global\pgf@y=\pgf@yb\relax% |
| 993 |
\global\pgf@x=0pt\relax% |
| 994 |
\else% |
| 995 |
\pgf@xc=8192pt% |
| 996 |
\divide\pgf@xc by\c@pgf@counta% \pgf@xc = 1/\pgf@x |
| 997 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@xc}\pgf@y% |
| 998 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@xb}\pgf@y% |
| 999 |
\ifnum\pgf@y<\pgf@yb% |
| 1000 |
\global\pgf@x=\pgf@xb% |
| 1001 |
\else% rats, calculate intersection on upper side |
| 1002 |
\ifnum\c@pgf@countb<255\relax% |
| 1003 |
\global\pgf@x=\pgf@xb\relax% |
| 1004 |
\global\pgf@y=0pt\relax% |
| 1005 |
\else% |
| 1006 |
\pgf@yc=8192pt% |
| 1007 |
\divide\pgf@yc by\c@pgf@countb% \pgf@xc = 1/\pgf@x |
| 1008 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@yc}\pgf@x% |
| 1009 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@yb}\pgf@x% |
| 1010 |
\global\pgf@y=\pgf@yb% |
| 1011 |
\fi% |
| 1012 |
\fi% |
| 1013 |
\fi% |
| 1014 |
\else% |
| 1015 |
\ifnum\c@pgf@countb<255\relax% |
| 1016 |
\global\pgf@x=\pgf@xb\relax% |
| 1017 |
\global\pgf@y=0pt\relax% |
| 1018 |
\else% |
| 1019 |
\pgf@yc=8192pt% |
| 1020 |
\divide\pgf@yc by\c@pgf@countb% \pgf@xc = 1/\pgf@x |
| 1021 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@yc}\pgf@x% |
| 1022 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@yb}\pgf@x% |
| 1023 |
\ifnum\pgf@x<\pgf@xb% |
| 1024 |
\global\pgf@y=\pgf@yb% |
| 1025 |
\else% |
| 1026 |
\ifnum\c@pgf@counta<255\relax% |
| 1027 |
\global\pgf@y=\pgf@yb\relax% |
| 1028 |
\global\pgf@x=0pt\relax% |
| 1029 |
\else% |
| 1030 |
\pgf@xc=8192pt% |
| 1031 |
\divide\pgf@xc by\c@pgf@counta% \pgf@xc = 1/\pgf@x |
| 1032 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@xc}\pgf@y% |
| 1033 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@xb}\pgf@y% |
| 1034 |
\global\pgf@x=\pgf@xb% |
| 1035 |
\fi% |
| 1036 |
\fi% |
| 1037 |
\fi% |
| 1038 |
\fi% |
| 1039 |
\ifnum\pgf@xa<0\relax\global\pgf@x=-\pgf@x\fi% |
| 1040 |
\ifnum\pgf@ya<0\relax\global\pgf@y=-\pgf@y\fi% |
| 1041 |
} |
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
% An approximation to a point on an ellipse in a certain |
| 1047 |
% direction. Will be exact only if the ellipse is a circle. |
| 1048 |
% |
| 1049 |
% #1 = a point pointing in some direction |
| 1050 |
% #2 = upper right corner of a bounding box for the ellipse |
| 1051 |
% |
| 1052 |
% Returns the intersection of a line starting at the origin going in |
| 1053 |
% the given direction and the ellipses border. |
| 1054 |
% |
| 1055 |
% Example: |
| 1056 |
% |
| 1057 |
% \pgfpointborderellipse{\pgfpointnormalised{\pgfpointxy{2}{1}} |
| 1058 |
% {\pgfpoint{1cm}{2cm}} |
| 1059 |
|
| 1060 |
\def\pgfpointborderellipse#1#2{% |
| 1061 |
\pgf@process{#2}% |
| 1062 |
\pgf@xa=\pgf@x% |
| 1063 |
\pgf@ya=\pgf@y% |
| 1064 |
\ifdim\pgf@xa=\pgf@ya% circle. that's easy! |
| 1065 |
\pgf@process{\pgfpointnormalised{#1}}% |
| 1066 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@xa}\pgf@x% |
| 1067 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@xa}\pgf@y% |
| 1068 |
\else% |
| 1069 |
\ifdim\pgf@xa<\pgf@ya% |
| 1070 |
% Ok, first, let's compute x/y: |
| 1071 |
\c@pgf@countb=\pgf@ya% |
| 1072 |
\divide\c@pgf@countb by65536\relax% |
| 1073 |
\global\divide\pgf@x by\c@pgf@countb% |
| 1074 |
\global\divide\pgf@y by\c@pgf@countb% |
| 1075 |
\pgf@xc=\pgf@x% |
| 1076 |
\pgf@yc=8192pt% |
| 1077 |
\global\pgf@y=.125\pgf@y% |
| 1078 |
\c@pgf@countb=\pgf@y% |
| 1079 |
\divide\pgf@yc by\c@pgf@countb% |
| 1080 |
\pgf@process{#1}% |
| 1081 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@yc}\pgf@y% |
| 1082 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@xc}\pgf@y% |
| 1083 |
\pgf@process{\pgfpointnormalised{}}% |
| 1084 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@xa}\pgf@x% |
| 1085 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@ya}\pgf@y% |
| 1086 |
\else% |
| 1087 |
% Ok, now let's compute y/x: |
| 1088 |
\c@pgf@countb=\pgf@xa% |
| 1089 |
\divide\c@pgf@countb by65536\relax% |
| 1090 |
\global\divide\pgf@x by\c@pgf@countb% |
| 1091 |
\global\divide\pgf@y by\c@pgf@countb% |
| 1092 |
\pgf@yc=\pgf@y% |
| 1093 |
\pgf@xc=8192pt% |
| 1094 |
\global\pgf@x=.125\pgf@x% |
| 1095 |
\c@pgf@countb=\pgf@x% |
| 1096 |
\divide\pgf@xc by\c@pgf@countb% |
| 1097 |
\pgf@process{#1}% |
| 1098 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@yc}\pgf@x% |
| 1099 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@xc}\pgf@x% |
| 1100 |
\pgf@process{\pgfpointnormalised{}}% |
| 1101 |
\global\pgf@x=\pgf@sys@tonumber{\pgf@xa}\pgf@x% |
| 1102 |
\global\pgf@y=\pgf@sys@tonumber{\pgf@ya}\pgf@y% |
| 1103 |
\fi% |
| 1104 |
\fi% |
| 1105 |
} |
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
% Extract the x-coordinate of a point to a dimensions |
| 1112 |
% |
| 1113 |
% #1 = a TeX dimension |
| 1114 |
% #2 = a point |
| 1115 |
% |
| 1116 |
% Example: |
| 1117 |
% |
| 1118 |
% \newdimen\mydim |
| 1119 |
% \pgfextractx{\mydim}{\pgfpoint{2cm}{4pt}} |
| 1120 |
% % \mydim is now 2cm |
| 1121 |
|
| 1122 |
\def\pgfextractx#1#2{% |
| 1123 |
\pgf@process{#2}% |
| 1124 |
#1=\pgf@x\relax} |
| 1125 |
|
| 1126 |
|
| 1127 |
% Extract the y-coordinate of a point to a dimensions |
| 1128 |
% |
| 1129 |
% #1 = a TeX dimension |
| 1130 |
% #2 = a point |
| 1131 |
% |
| 1132 |
% Example: |
| 1133 |
% |
| 1134 |
% \newdimen\mydim |
| 1135 |
% \pgfextracty{\mydim}{\pgfpoint{2cm}{4pt}} |
| 1136 |
% % \mydim is now 4pt |
| 1137 |
|
| 1138 |
\def\pgfextracty#1#2{% |
| 1139 |
\pgf@process{#2}% |
| 1140 |
#1=\pgf@y\relax} |
| 1141 |
|
| 1142 |
|
| 1143 |
% Stores the most recently used (x,y) coordinates into two macros, #1 and #2. |
| 1144 |
\def\pgfgetlastxy#1#2{% |
| 1145 |
\edef#1{\the\pgf@x}% |
| 1146 |
\edef#2{\the\pgf@y}% |
| 1147 |
}% |
| 1148 |
|
| 1149 |
|
| 1150 |
\def\pgf@def#1#2#3{\expandafter\def\csname pgf@#1#2\endcsname{#3}} |
| 1151 |
\pgf@def{cosfrac}{0}{1} |
| 1152 |
\pgf@def{cosfrac}{1}{0.99995} \pgf@def{cosfrac}{2}{0.9998} |
| 1153 |
\pgf@def{cosfrac}{3}{0.99955} \pgf@def{cosfrac}{4}{0.999201} |
| 1154 |
\pgf@def{cosfrac}{5}{0.998752} \pgf@def{cosfrac}{6}{0.998205} |
| 1155 |
\pgf@def{cosfrac}{7}{0.997559} \pgf@def{cosfrac}{8}{0.996815} |
| 1156 |
\pgf@def{cosfrac}{9}{0.995974} \pgf@def{cosfrac}{10}{0.995037} |
| 1157 |
\pgf@def{cosfrac}{11}{0.994004} \pgf@def{cosfrac}{12}{0.992877} |
| 1158 |
\pgf@def{cosfrac}{13}{0.991656} \pgf@def{cosfrac}{14}{0.990342} |
| 1159 |
\pgf@def{cosfrac}{15}{0.988936} \pgf@def{cosfrac}{16}{0.987441} |
| 1160 |
\pgf@def{cosfrac}{17}{0.985856} \pgf@def{cosfrac}{18}{0.984183} |
| 1161 |
\pgf@def{cosfrac}{19}{0.982424} \pgf@def{cosfrac}{20}{0.980581} |
| 1162 |
\pgf@def{cosfrac}{21}{0.978653} \pgf@def{cosfrac}{22}{0.976644} |
| 1163 |
\pgf@def{cosfrac}{23}{0.974555} \pgf@def{cosfrac}{24}{0.972387} |
| 1164 |
\pgf@def{cosfrac}{25}{0.970143} \pgf@def{cosfrac}{26}{0.967823} |
| 1165 |
\pgf@def{cosfrac}{27}{0.965429} \pgf@def{cosfrac}{28}{0.962964} |
| 1166 |
\pgf@def{cosfrac}{29}{0.960429} \pgf@def{cosfrac}{30}{0.957826} |
| 1167 |
\pgf@def{cosfrac}{31}{0.955157} \pgf@def{cosfrac}{32}{0.952424} |
| 1168 |
\pgf@def{cosfrac}{33}{0.949629} \pgf@def{cosfrac}{34}{0.946773} |
| 1169 |
\pgf@def{cosfrac}{35}{0.943858} \pgf@def{cosfrac}{36}{0.940887} |
| 1170 |
\pgf@def{cosfrac}{37}{0.937862} \pgf@def{cosfrac}{38}{0.934784} |
| 1171 |
\pgf@def{cosfrac}{39}{0.931655} \pgf@def{cosfrac}{40}{0.928477} |
| 1172 |
\pgf@def{cosfrac}{41}{0.925252} \pgf@def{cosfrac}{42}{0.921982} |
| 1173 |
\pgf@def{cosfrac}{43}{0.918669} \pgf@def{cosfrac}{44}{0.915315} |
| 1174 |
\pgf@def{cosfrac}{45}{0.911922} \pgf@def{cosfrac}{46}{0.90849} |
| 1175 |
\pgf@def{cosfrac}{47}{0.905024} \pgf@def{cosfrac}{48}{0.901523} |
| 1176 |
\pgf@def{cosfrac}{49}{0.89799} \pgf@def{cosfrac}{50}{0.894427} |
| 1177 |
\pgf@def{cosfrac}{51}{0.890835} \pgf@def{cosfrac}{52}{0.887217} |
| 1178 |
\pgf@def{cosfrac}{53}{0.883573} \pgf@def{cosfrac}{54}{0.879905} |
| 1179 |
\pgf@def{cosfrac}{55}{0.876216} \pgf@def{cosfrac}{56}{0.872506} |
| 1180 |
\pgf@def{cosfrac}{57}{0.868777} \pgf@def{cosfrac}{58}{0.865031} |
| 1181 |
\pgf@def{cosfrac}{59}{0.861269} \pgf@def{cosfrac}{60}{0.857493} |
| 1182 |
\pgf@def{cosfrac}{61}{0.853704} \pgf@def{cosfrac}{62}{0.849903} |
| 1183 |
\pgf@def{cosfrac}{63}{0.846092} \pgf@def{cosfrac}{64}{0.842271} |
| 1184 |
\pgf@def{cosfrac}{65}{0.838444} \pgf@def{cosfrac}{66}{0.834609} |
| 1185 |
\pgf@def{cosfrac}{67}{0.83077} \pgf@def{cosfrac}{68}{0.826927} |
| 1186 |
\pgf@def{cosfrac}{69}{0.82308} \pgf@def{cosfrac}{70}{0.819232} |
| 1187 |
\pgf@def{cosfrac}{71}{0.815383} \pgf@def{cosfrac}{72}{0.811534} |
| 1188 |
\pgf@def{cosfrac}{73}{0.807687} \pgf@def{cosfrac}{74}{0.803842} |
| 1189 |
\pgf@def{cosfrac}{75}{0.8} \pgf@def{cosfrac}{76}{0.796162} |
| 1190 |
\pgf@def{cosfrac}{77}{0.792329} \pgf@def{cosfrac}{78}{0.788502} |
| 1191 |
\pgf@def{cosfrac}{79}{0.784682} \pgf@def{cosfrac}{80}{0.780869} |
| 1192 |
\pgf@def{cosfrac}{81}{0.777064} \pgf@def{cosfrac}{82}{0.773268} |
| 1193 |
\pgf@def{cosfrac}{83}{0.769481} \pgf@def{cosfrac}{84}{0.765705} |
| 1194 |
\pgf@def{cosfrac}{85}{0.761939} \pgf@def{cosfrac}{86}{0.758185} |
| 1195 |
\pgf@def{cosfrac}{87}{0.754443} \pgf@def{cosfrac}{88}{0.750714} |
| 1196 |
\pgf@def{cosfrac}{89}{0.746997} \pgf@def{cosfrac}{90}{0.743294} |
| 1197 |
\pgf@def{cosfrac}{91}{0.739605} \pgf@def{cosfrac}{92}{0.735931} |
| 1198 |
\pgf@def{cosfrac}{93}{0.732272} \pgf@def{cosfrac}{94}{0.728628} |
| 1199 |
\pgf@def{cosfrac}{95}{0.724999} \pgf@def{cosfrac}{96}{0.721387} |
| 1200 |
\pgf@def{cosfrac}{97}{0.717792} \pgf@def{cosfrac}{98}{0.714213} |
| 1201 |
\pgf@def{cosfrac}{99}{0.710651} \pgf@def{cosfrac}{100}{0.707107} |
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
% Forward declarations for nonlinear stuff (have no effect till module |
| 1207 |
% nonlineartransformations is loaded) |
| 1208 |
|
| 1209 |
\let\pgfpointtransformednonlinear\pgfpointtransformed |
| 1210 |
|
| 1211 |
|
| 1212 |
\endinput |