| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2015 Daan Leijen |
| 4 |
% ------------------------------------------------------- |
| 5 |
% |
| 6 |
% This file may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either version 1.2 |
| 8 |
% of this license or (at your option) any later version. |
| 9 |
% The latest version of this license is in: |
| 10 |
% |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% |
| 13 |
% and version 1.2 or later is part of all distributions of LaTeX |
| 14 |
% version 1999/12/01 or later. |
| 15 |
% |
| 16 |
% \fi |
| 17 |
% |
| 18 |
% \iffalse |
| 19 |
%<*driver> |
| 20 |
\ProvidesFile{ellipse.dtx} |
| 21 |
%</driver> |
| 22 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 23 |
%<package>\ProvidesPackage{ellipse} |
| 24 |
%<*package> |
| 25 |
[2004/11/05 v1.0 .dtx ellipse file] |
| 26 |
%</package> |
| 27 |
%<package>\RequirePackage{pict2e} |
| 28 |
% |
| 29 |
%<*driver> |
| 30 |
\documentclass{ltxdoc} |
| 31 |
\usepackage{graphicx} |
| 32 |
\usepackage{ellipse}[2004/11/05] |
| 33 |
\usepackage{amsmath} |
| 34 |
\usepackage{amssymb} |
| 35 |
\usepackage{hyperref} |
| 36 |
\usepackage{lmodern} |
| 37 |
\usepackage{xcolor} |
| 38 |
\usepackage{wrapfig} |
| 39 |
\newcommand\kk[1]{\iota_{#1}} |
| 40 |
\newcommand\sk[1]{\rho_{#1}} |
| 41 |
\newcommand\sint[1]{\textit{sint}_{#1}} |
| 42 |
\newcommand\cost[1]{\textit{cost}_{#1}} |
| 43 |
\newcommand\sign[1]{\pm_{#1}} |
| 44 |
\newcommand\csqrt{\textit{csqrt}} |
| 45 |
\renewcommand\cos{\textit{cos}}\renewcommand\sin{\textit{sin}} |
| 46 |
\renewcommand\arctan{\textit{arctan}}\renewcommand\tan{\textit{tan}} |
| 47 |
\renewcommand\max{\textit{max}}\renewcommand\sin{\textit{sin}} |
| 48 |
\providecolor{teal}{HTML}{008080} |
| 49 |
\providecolor{purple}{HTML}{800080} |
| 50 |
\providecolor{navy}{HTML}{000080} |
| 51 |
\providecolor{maroon}{HTML}{800000} |
| 52 |
\providecolor{floralwhite}{HTML}{FFFAF0} |
| 53 |
\providecolor{ivory}{HTML}{FFFFF0} |
| 54 |
\providecolor{white}{HTML}{FFFFFF} |
| 55 |
\providecolor{transparent}{named}{white} |
| 56 |
\providecolor{gainsboro}{HTML}{DCDCDC} |
| 57 |
\hypersetup{colorlinks=true,citecolor=navy,linkcolor=navy,urlcolor=navy,filecolor=navy,bookmarksdepth=3,bookmarksopenlevel=1} |
| 58 |
\makeatletter |
| 59 |
\DeclareRobustCommand*\package[2][]{% |
| 60 |
\def\@tempa{#1}% |
| 61 |
\ifx\@tempa\@empty |
| 62 |
\textsf{#2}% |
| 63 |
\else |
| 64 |
\href{http://mirrors.ctan.org/macros/latex/#1}{\textsf{#2}}% |
| 65 |
\fi |
| 66 |
}% |
| 67 |
\DeclareRobustCommand*\pkgpicte{\package[contrib/pict2e/pict2e.pdf]{pict2e}} |
| 68 |
\newsavebox{\@ebox} |
| 69 |
\newcommand*\@unit[1]{\strip@pt\dimexpr#1\relax}% |
| 70 |
\newcommand*\ellipbox[1]{% |
| 71 |
\begingroup |
| 72 |
\savebox{\@ebox}{#1}% |
| 73 |
\setlength{\unitlength}{1pt}% |
| 74 |
\hspace*{0.8ex}% |
| 75 |
\begin{picture}(0,0)% |
| 76 |
\put(\@unit{0.5\wd\@ebox},\@unit{0.5\ht\@ebox - 0.5\dp\@ebox}){% |
| 77 |
\ellipse{\@unit{0.8ex + 0.5\wd\@ebox}}{\@unit{0.8ex + 0.5\ht\@ebox}}% |
| 78 |
}% |
| 79 |
\end{picture}% |
| 80 |
\usebox{\@ebox}% |
| 81 |
\hspace{0.8ex}% |
| 82 |
\endgroup% |
| 83 |
} |
| 84 |
\makeatother |
| 85 |
\EnableCrossrefs |
| 86 |
\CodelineIndex |
| 87 |
\RecordChanges |
| 88 |
\begin{document} |
| 89 |
\setlength\emergencystretch{3em} |
| 90 |
\DocInput{ellipse.dtx} |
| 91 |
\PrintChanges |
| 92 |
\setcounter{IndexColumns}{2}% |
| 93 |
\PrintIndex |
| 94 |
\end{document} |
| 95 |
%</driver> |
| 96 |
% \fi |
| 97 |
% |
| 98 |
% \CheckSum{0} |
| 99 |
% |
| 100 |
% \CharacterTable |
| 101 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 102 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 103 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 104 |
% Exclamation \! Double quote \" Hash (number) \# |
| 105 |
% Dollar \$ Percent \% Ampersand \& |
| 106 |
% Acute accent \' Left paren \( Right paren \) |
| 107 |
% Asterisk \* Plus \+ Comma \, |
| 108 |
% Minus \- Point \. Solidus \/ |
| 109 |
% Colon \: Semicolon \; Less than \< |
| 110 |
% Equals \= Greater than \> Question mark \? |
| 111 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 112 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 113 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 114 |
% Right brace \} Tilde \~} |
| 115 |
% |
| 116 |
% |
| 117 |
% \changes{v1.0}{2015/03/24}{Initial version} |
| 118 |
% |
| 119 |
% \GetFileInfo{ellipse.dtx} |
| 120 |
% |
| 121 |
% \DoNotIndex{\newcommand,\renewcommand,\newenvironment,\renewenvironment} |
| 122 |
% \DoNotIndex{\providecommand,\def,\edef,\let,\gdef,\xdef,\global,\newtoks} |
| 123 |
% \DoNotIndex{\RequirePackage,\DeclareOption,\ProcessOptions,\ExecuteOptions} |
| 124 |
% \DoNotIndex{\input,\InputIfFileExists} |
| 125 |
% \DoNotIndex{\@ifdefinable,\@ifundefined,\@percentchar} |
| 126 |
% \DoNotIndex{\AtBeginDocument,\AtEndOfPackage} |
| 127 |
% \DoNotIndex{\PackageError,\PackageWarning,\PackageWarningNoLine,\PackageInfo} |
| 128 |
% \DoNotIndex{\MessageBreak,\typeout} |
| 129 |
% |
| 130 |
% \DoNotIndex{\z@,\z@skip,\p@,\@ne,\tw@,\thr@@,\@iv,\two@fourteen,\strip@pt} |
| 131 |
% \DoNotIndex{\the,\if,\else,\or,\fi,\ifnum,\ifdim,\ifcase,\ifodd} |
| 132 |
% \DoNotIndex{\advance,\multiply,\divide} |
| 133 |
% \DoNotIndex{\@tfor,\do} |
| 134 |
% \DoNotIndex{\csname,\endcsname,\begingroup,\endgroup} |
| 135 |
% \DoNotIndex{\expandafter,\afterassignment,\noexpand} |
| 136 |
% \DoNotIndex{\@ovxx,\@ovyy,\@ovdx,\@ovdy} |
| 137 |
% \DoNotIndex{\undefined,\dimexpr,\relax,\space,\protect,\begin} |
| 138 |
% \DoNotIndex{\@tempdima,\@tempdimb,\@tempdimc,\@tempdimd,\dimen@,\@tempa} |
| 139 |
% \DoNotIndex{\@tempswafalse,\@tempswatrue,\if@tempswa,\iffalse,\ifx,\ignorespaces} |
| 140 |
% |
| 141 |
% \title{The {\linethickness{0.6pt}\ellipbox{\textsf{ellipse}}} package} |
| 142 |
% \author{Daan Leijen \\ \texttt{[email protected]}} |
| 143 |
% |
| 144 |
% \maketitle |
| 145 |
% |
| 146 |
% \newcommand\pictexample[1]{% |
| 147 |
% \setlength{\unitlength}{10pt}% |
| 148 |
% \raisebox{-30pt}{\begin{picture}(6,8)% |
| 149 |
% \linethickness{0.4pt}\roundjoin% |
| 150 |
% \color{gainsboro}% |
| 151 |
% \put(0,0){\multiput(0,0)(1,0){9}{\line(0,1){6}}% |
| 152 |
% \multiput(0,0)(0,1){7}{\line(1,0){8}}% |
| 153 |
% }% |
| 154 |
% \put(0,0){\color{gray}% |
| 155 |
% {\vector(1,0){8}}\put(-0.5,6.5){$y$}% |
| 156 |
% {\vector(0,1){6}}\put(8.5,-0.5){$x$}% |
| 157 |
% }% |
| 158 |
% \color{black}% |
| 159 |
% \linethickness{0.8pt}% |
| 160 |
% #1\end{picture}}% |
| 161 |
% } |
| 162 |
% |
| 163 |
% \section{Introduction} |
| 164 |
% |
| 165 |
% \LaTeX{} has many advanced graphics packages now, the most extensive are |
| 166 |
% \href{https://www.ctan.org/pkg/pgf}{\textsf{tikz}} |
| 167 |
% and \href{https://www.ctan.org/pkg/pstricks-base}{\textsf{pstricks}}. |
| 168 |
% However, these are also large packages that take long to load and |
| 169 |
% may not always work on all drivers. The standard \pkgpicte{} package removes many of the previous |
| 170 |
% limitations of the `old' \LaTeX{} |picture| environment and makes it a \emph{lean |
| 171 |
% and portable} alternative to the more full featured packages. However, even though it can |
| 172 |
% draw circles and circle arcs well, it lacks the ability to draw ellipses and elliptical |
| 173 |
% arcs. This package adds these functions on top of the standard \pkgpicte{} primitives |
| 174 |
% (i.e. the |\cbezier| command). |
| 175 |
% |
| 176 |
% \section{Drawing ellipses} |
| 177 |
% |
| 178 |
% \noindent |
| 179 |
% \DescribeMacro\ellipse |
| 180 |
% \DescribeMacro{\ellipse*} |
| 181 |
% \marg{x-radius}\marg{y-radius}\\ |
| 182 |
% \strut\\ |
| 183 |
% These commands draw an ellipse with the specified radi\"\i. The |\ellipse| command draws |
| 184 |
% a stroked ellipse with the current |\linethickness| while |\ellipse*| draws a filled |
| 185 |
% ellipse with the current |\color|. For example: |
| 186 |
% |
| 187 |
% \noindent\begin{minipage}{0.7\linewidth}% |
| 188 |
% \begin{verbatim} |
| 189 |
% \setlength{\unitlength}{10pt}% |
| 190 |
% \begin{picture}(6,8) |
| 191 |
% \linethickness{0.8pt}% |
| 192 |
% \put(6,3){\color{teal}\ellipse*{2}{3}}% |
| 193 |
% \put(3,3){\color{blue}\ellipse{3}{2}}% |
| 194 |
% \end{picture} |
| 195 |
% \end{verbatim}\end{minipage} |
| 196 |
% \pictexample{% |
| 197 |
% \put(6,3){\color{teal}\ellipse*{2}{3}}% |
| 198 |
% \put(3,3){\color{blue}\ellipse{3}{2}}% |
| 199 |
% }\\[2ex] |
| 200 |
% |
| 201 |
% \noindent |
| 202 |
% \DescribeMacro\earc |
| 203 |
% \DescribeMacro{\earc*} |
| 204 |
% \oarg{start-angle$\rangle$|,|$\langle$end-angle}\marg{x-radius}\marg{y-radius}\\ |
| 205 |
% \strut\\ |
| 206 |
% These commands draw part of an ellipse with the specified radi\"\i. |
| 207 |
% The |\earc| command draws |
| 208 |
% a stroked elliptical arc with the current |\linethickness| while |\earc*| draws a filled |
| 209 |
% elliptical `pie slice' with the current |\color|. The optional argument specifies a start and |
| 210 |
% end-angle in degrees which must be between $-720$ and $720$ (but can be fractional). |
| 211 |
% The endings of the arcs are determined by the \emph{cap} setting: |\buttcap| (default), |
| 212 |
% |\roundcap| (add half disc), or |\squarecap| (add half square). |
| 213 |
% |
| 214 |
% \noindent\begin{minipage}{0.7\linewidth}% |
| 215 |
% \begin{verbatim} |
| 216 |
% \put(3,3){% |
| 217 |
% \color{blue}\roundcap\earc[135,330]{3}{2}}% |
| 218 |
% \put(6,3){% |
| 219 |
% \color{teal}\earc*[-45,90]{2}{3}}% |
| 220 |
% \end{verbatim} |
| 221 |
% \end{minipage} |
| 222 |
% \pictexample{% |
| 223 |
% \put(3,3){\color{blue}\roundcap\earc[135,330]{3}{2}}% |
| 224 |
% \put(6,3){\color{teal}\earc*[-45,90]{2}{3}}% |
| 225 |
% }\\[2ex] |
| 226 |
% |
| 227 |
% \noindent |
| 228 |
% \DescribeMacro\elliparc |
| 229 |
% \oarg{initial}\marg{center-x}\marg{center-y}\marg{x-rad}\marg{y-rad}\marg{start-angle}\marg{end-angle}\\ |
| 230 |
% |
| 231 |
% \noindent The core elliptical arc routine. These are to be used with path commands, like |
| 232 |
% |\lineto|, |\moveto|, |\strokepath|, etc, and can draw an elliptical arc at any center point. |
| 233 |
% The optional argument specifies the initial drawing |
| 234 |
% action: the default is $0$ (|\lineto|) which draws a line to the arc starting point, |
| 235 |
% the value $1$ |
| 236 |
% (|\moveto|) just moves to the starting point, and $2$ does nothing as an initial action. |
| 237 |
% If the start angle is larger than the end angle, the arc is drawn clockwise, and otherwise |
| 238 |
% anti-clockwise.\\[1ex] |
| 239 |
% |
| 240 |
% \noindent\begin{minipage}{0.7\linewidth}% |
| 241 |
% \begin{verbatim} |
| 242 |
% \elliparc[1]{3}{3}{3}{2}{90}{270}% |
| 243 |
% \elliparc{5}{3}{2}{2}{-90}{90}% |
| 244 |
% \closepath\strokepath |
| 245 |
% \color{teal}% |
| 246 |
% \moveto(1,3) |
| 247 |
% \elliparc{3}{3}{2}{1}{-135}{135}% |
| 248 |
% \closepath |
| 249 |
% \fillpath |
| 250 |
% \end{verbatim}\end{minipage} |
| 251 |
% \pictexample{% |
| 252 |
% \elliparc[1]{3}{3}{3}{2}{90}{270}% |
| 253 |
% \elliparc{5}{3}{2}{2}{-90}{90}% |
| 254 |
% \closepath\strokepath |
| 255 |
% \color{teal}% |
| 256 |
% \moveto(1,3) |
| 257 |
% \elliparc{3}{3}{2}{1}{-135}{135}% |
| 258 |
% \closepath |
| 259 |
% \fillpath |
| 260 |
% }\\[2ex] |
| 261 |
% |
| 262 |
% \noindent Note how the two initial arcs are automatically connected by a line |
| 263 |
% segment from $(3,1)$ to $(5,1)$ (due to the default optional argument of $0$ that |
| 264 |
% uses a |\lineto| command to the starting point of the arc). Similarly, we use |
| 265 |
% such initial line segment and a |\closepath| to draw the triangular side of the |
| 266 |
% inner ellipse. |
| 267 |
% |
| 268 |
% \subsection{Rotated ellipses} |
| 269 |
% |
| 270 |
% There is no direct command to rotate an ellipse but you can use the |
| 271 |
% standard |\rotatebox| command from the \package[required/graphics/grfguide.pdf]{graphicx} package. For example: |
| 272 |
% |
| 273 |
% \noindent\begin{minipage}{0.7\linewidth}% |
| 274 |
% \begin{verbatim} |
| 275 |
% \put(3,3){% |
| 276 |
% \rotatebox[origin=c]{45}{\ellipse{3}{2}}% |
| 277 |
% }% |
| 278 |
% \end{verbatim}\end{minipage} |
| 279 |
% \pictexample{% |
| 280 |
% \put(3,3){\rotatebox[origin=c]{45}{\ellipse{3}{2}}% |
| 281 |
% }% |
| 282 |
% }\\[2ex] |
| 283 |
% |
| 284 |
% \subsection{Using the picture environment inline} |
| 285 |
% |
| 286 |
% The standard \LaTeX{} |picture| environment is nowadays quite |
| 287 |
% powerful and convenient. Read the latest \pkgpicte{} documentation |
| 288 |
% and ``The unknown \emph{picture} environment'' \cite{picture} for more information. |
| 289 |
% One particularly nice feature is that we |
| 290 |
% can create a picture as |\begin{picture}(0,0)| to give it zero |
| 291 |
% space. This can be used for example to define an |\ellipbox| command |
| 292 |
% like:\\[1ex] |
| 293 |
% |
| 294 |
% \noindent\begin{minipage}{0.6\linewidth}% |
| 295 |
% \begin{verbatim} |
| 296 |
% Boxed numbers: |
| 297 |
% \ellipbox{1}, \ellipbox{123}. |
| 298 |
% \end{verbatim} |
| 299 |
% \end{minipage} |
| 300 |
% \begin{minipage}{0.38\linewidth}% |
| 301 |
% Boxed numbers: \ellipbox{1}, \ellipbox{123}. |
| 302 |
% \end{minipage}\\[1ex] |
| 303 |
% |
| 304 |
% \noindent We also used this command to draw the ellipse in the title |
| 305 |
% of this article, and it is defined as: |
| 306 |
% \begin{verbatim} |
| 307 |
%\newsavebox{\@ebox} |
| 308 |
%\newcommand*\@unit[1]{\strip@pt\dimexpr#1\relax}% |
| 309 |
%\newcommand*\ellipbox[1]{% |
| 310 |
% \begingroup |
| 311 |
% \savebox{\@ebox}{#1}% |
| 312 |
% \setlength{\unitlength}{1pt}% |
| 313 |
% \hspace*{0.8ex}% |
| 314 |
% \begin{picture}(0,0)% |
| 315 |
% \put(\@unit{0.5\wd\@ebox},\@unit{0.5\ht\@ebox - 0.5\dp\@ebox}){% |
| 316 |
% \ellipse{\@unit{0.8ex + 0.5\wd\@ebox}}{\@unit{0.8ex + 0.5\ht\@ebox}}% |
| 317 |
% }% |
| 318 |
% \end{picture}% |
| 319 |
% \usebox{\@ebox}\hspace{0.25ex}\endgroup} |
| 320 |
% \end{verbatim} |
| 321 |
% \noindent This is not the best code possible but it hopefully gives you a good |
| 322 |
% idea on how to implement your own boxes. Note the use of the |\@unit| macro |
| 323 |
% to convert dimensions to units, which is also why we need to set the |\unitlength| |
| 324 |
% to |1pt| here. |
| 325 |
% |
| 326 |
% \StopEventually{} |
| 327 |
% |
| 328 |
% \begin{thebibliography}{9} |
| 329 |
% \raggedright |
| 330 |
% |
| 331 |
% \bibitem{abst} M.~Abramowitz and I.A.~Stegun: \textit{Handbook of Mathematical Functions}, |
| 332 |
% \url{people.math.sfu.ca/~cbm/aands}, 1964 |
| 333 |
% |
| 334 |
% \bibitem{picture} Claudio Beccari: \emph{The unknown \emph{picture} environment}, |
| 335 |
% TUGBoat, vol. 33(1), 2012. \url{tug.org/TUGboat/tb33-1/tb103becc-picture.pdf} |
| 336 |
% |
| 337 |
% \bibitem{ellipse} Luc Maisonobe: \textit{Drawing an elliptical arc using polylines, quadratic or cubic B\'ezier lines.} |
| 338 |
% \url{www.spaceroots.org/documents/ellipse/elliptical-arc.pdf}, 2003 |
| 339 |
% |
| 340 |
% \bibitem{rajan:atan} S.~Rajan, Sichun Wang, R.~Inkol, and A.~Joyal: \textit{Efficient approximations for the arctangent function}. |
| 341 |
% In Signal Processing Magazine, vol. 23(3), pages 108--111, May 2006 |
| 342 |
% |
| 343 |
% \end{thebibliography} |
| 344 |
% |
| 345 |
% \clearpage |
| 346 |
% |
| 347 |
% \newcommand\abs[1]{\lvert #1\rvert} |
| 348 |
% \newcommand\rarg[1]{$\langle$\textit{#1}$\rangle$} |
| 349 |
% \newcommand\xellipse{\mathcal{E}} |
| 350 |
% |
| 351 |
% \section{Elliptical arcs as B\'ezier curves} |
| 352 |
% \begin{figure}\begin{center} |
| 353 |
% \setlength\unitlength{18pt} |
| 354 |
% \begin{picture}(12,9)(-1.5,-0.5)% |
| 355 |
% \linethickness{0.4pt}\roundjoin% |
| 356 |
% \iffalse |
| 357 |
% \color{gainsboro}% |
| 358 |
% \put(0,0){% |
| 359 |
% \multiput(-2,-1)(1,0){13}{\line(0,1){9}}% |
| 360 |
% \multiput(-2,-1)(0,1){10}{\line(1,0){12}}% |
| 361 |
% }% |
| 362 |
% \fi |
| 363 |
% \color{black}% |
| 364 |
% \put(0,0){% |
| 365 |
% \put(0,-0.5){\vector(0,1){8}}\put(8.5,-0.5){$x$}% |
| 366 |
% \put(-1.5,0){\vector(1,0){11}}\put(-0.5,6.5){$y$}% |
| 367 |
% }% |
| 368 |
% \put(4,3.3){\color{navy}\earc{5}{3} |
| 369 |
% \put(3,-2){$\xellipse$}%% |
| 370 |
% \color{teal}% |
| 371 |
% \put(-5.5,0){\line(1,0){11}}% |
| 372 |
% \put(0,-3.5){\line(0,1){8}}% |
| 373 |
% \put(3,0){\vector(-1,0){3}\vector(1,0){2}\raisebox{0.3ex}{$a$}}% |
| 374 |
% \put(0,-1.5){\vector(0,1){1.5}\vector(0,-1){1.5}$\,b$}% |
| 375 |
% \color{maroon}% |
| 376 |
% \put(0,0){\moveto(0,0)\elliparc{0}{0}{5}{3}{30}{120}\closepath\strokepath}% |
| 377 |
% {\linethickness{2pt}\earc[30,120]{5}{3}}% |
| 378 |
% \put(3.7,2.2){$p_1$}\put(-2,3.1){$p_2$}% |
| 379 |
% \put(2.25,2.92){\moveto(0,0)\lineto(1.35,-0.84)\strokepath\circle*{0.1}$\;q_1$}% |
| 380 |
% \put(-0.075,3.22){\moveto(0,0)\lineto(-1.56,-0.39)\strokepath\circle*{0.1}$\,q_2$}% |
| 381 |
% \color{black} |
| 382 |
% \linethickness{0.2pt}\arc[0,30]{1}\arc[0,120]{2}% |
| 383 |
% \put(1,0.2){$\alpha_1$}\put(1,1.8){$\alpha_2$}% |
| 384 |
% }% |
| 385 |
% \color{navy}\put(4,-0.3){$\,c_x$}\put(0,2.9){$\,c_y$}% |
| 386 |
% % |
| 387 |
% \end{picture}\end{center} |
| 388 |
% \caption{Approximating an elliptical arc with a cubic B\'ezier curve. The center of the ellipse |
| 389 |
% is at $(c_x,c_y)$ with a horizontal radius of $a$ and a vertical one $b$. The elliptical arc goes |
| 390 |
% from $\alpha_1$ to $\alpha_2$ and is approximated with a thick red cubic B\'ezier curve. The curve |
| 391 |
% starts at $p_1$ and ends in $p_2$ with two control points $q_1$ and $q_2$. The curve was drawn |
| 392 |
% using the command \texttt{\textbackslash{}elliparc\{4\}\{3.3\}\{5\}\{3\}\{30\}\{120\}}.} |
| 393 |
% \label{fig:ellipse} |
| 394 |
% \end{figure} |
| 395 |
% \begin{figure} |
| 396 |
% \setlength\unitlength{20pt}\begin{center} |
| 397 |
% \begin{picture}(12,8)(-1.5,-0.5)% |
| 398 |
% \linethickness{0.4pt}\roundjoin% |
| 399 |
% \iffalse |
| 400 |
% \put(0,0){\color{gainsboro}% |
| 401 |
% \multiput(-2,-1)(1,0){13}{\line(0,1){8}}% |
| 402 |
% \multiput(-2,-1)(0,1){9}{\line(1,0){12}}% |
| 403 |
% }% |
| 404 |
% \fi |
| 405 |
% \put(4,3){\color{navy}\earc{5}{3}\put(-4,1){$\xellipse$}\color{teal}% |
| 406 |
% \put(-5.5,0){\line(1,0){11}}% |
| 407 |
% \put(0,-3.5){\line(0,1){7}}% |
| 408 |
% \put(-2,0){\vector(-1,0){3}\vector(1,0){2}\raisebox{0.3ex}{$a$}}% |
| 409 |
% \put(0,-1.5){\vector(0,1){1.5}\vector(0,-1){1.5}$\,b$}% |
| 410 |
% \color{black}% |
| 411 |
% \put(0,0){\circle{6}}% |
| 412 |
% \put(0,0){\vector(3.6,2.08){3.6}\vector(2.16,2.08){2.16}}% |
| 413 |
% \put(0,0){\color{maroon}% |
| 414 |
% \put(3.6,0){\line(0,1){2.08}\circle*{0.1}}% |
| 415 |
% \put(3.2,-0.5){$a\cos(t_1)$}% |
| 416 |
% \put(2.16,0){\line(0,1){2.08}\circle*{0.1}}% |
| 417 |
% \put(1.3,-0.5){$\cos(t_1)$}% |
| 418 |
% }% |
| 419 |
% \linethickness{0.2pt}\arc[0,30]{1}\arc[0,43.9]{2}% |
| 420 |
% \put(1,0.2){$\alpha_1$}\put(1.65,1.25){$t_1$}% |
| 421 |
% }% |
| 422 |
% % |
| 423 |
% \end{picture}\end{center} |
| 424 |
% \caption{The relation between the parametric angle $t_1$ and the angle $\alpha_1$ to the point on the ellipse. |
| 425 |
% All points on the ellipse are defined by the parametric equation $\xellipse(t) = (c_x + a\cdot\cos(t), c_y + b\cdot\sin(t))$} |
| 426 |
% \label{fig:parametric} |
| 427 |
% \end{figure} |
| 428 |
% % |
| 429 |
% % |
| 430 |
% Drawing an ellipse or part of an ellipse (\emph{elliptical arc}) using B\'ezier |
| 431 |
% curves requires some math to determine the right control points of the B\'ezier curve. |
| 432 |
% Figure~\ref{fig:ellipse} establishes some notation. We do not consider rotated |
| 433 |
% ellipses here and always use $a$ for the $x$-radius and $b$ for the $y$-radius. |
| 434 |
% We are interested in finding the B\'ezier curve between the $\alpha_1$ and |
| 435 |
% $\alpha_2$ angles, which implies finding the starting |
| 436 |
% point $p_1$, the end point $p_2$ and the control points $q_1$ and $q_2$. |
| 437 |
% |
| 438 |
% Each point on an ellipse is determined by the following parametric equation: |
| 439 |
% \[ \xellipse(t) = (c_x + a\cdot\cos(t), c_y + b\cdot\sin(t)) \] |
| 440 |
% where $t$ is the |
| 441 |
% parametric angle. The parametric angle $t$ is just a property of the ellipse and has no |
| 442 |
% `real' counterpart. Figure~\ref{fig:parametric} gives some helpful intuition how |
| 443 |
% the $\alpha$ angles and $t$ angles are related: we can imagine drawing a unit circle inside |
| 444 |
% an ellipse where for every $t$ angle on the unit circle we have a corresponding point |
| 445 |
% and angle $\alpha$ on the ellipse. From the definition of $\xellipse$ it |
| 446 |
% is straightforward to derive a parametric angle $t_i$ for some $\alpha_i$: |
| 447 |
% \[ t_i = \arctan_2(\frac{\sin(\alpha_i)}{b},\frac{\cos(\alpha_i)}{a}) \] |
| 448 |
% |
| 449 |
% \noindent Given this relation, the start and end points of our curve are simply: |
| 450 |
% \begin{align*} |
| 451 |
% p_1 &= \xellipse(t_1)\\ |
| 452 |
% p_2 &= \xellipse(t_2) |
| 453 |
% \end{align*} |
| 454 |
% |
| 455 |
% \noindent To be able to calculate optimal control points $q$ we need to also determine the |
| 456 |
% tangent of each point on the ellipse, which is given by the derivative of $\xellipse$: |
| 457 |
% \[ \xellipse'(t) = (-a\cdot\sin(t), b\cdot\cos(t)) \] |
| 458 |
% |
| 459 |
% \noindent |
| 460 |
% The derivation of the optimal B\'ezier control points for an ellipse is quite involved, |
| 461 |
% see~\cite{ellipse} for a nice overview. |
| 462 |
% For a quadratic B\'ezier curve, it turns out the optimal control points are determined as: |
| 463 |
% \begin{align*} |
| 464 |
% q_1 &= p_1 + \tan(\frac{t_2 - t_1}{2})\cdot\xellipse'(t_1)\\ |
| 465 |
% &= p_2 - \tan(\frac{t_2 - t_1}{2})\cdot\xellipse'(t_2) |
| 466 |
% \end{align*} |
| 467 |
% % |
| 468 |
% \noindent while for a cubic B\'ezier curve, one solution for optimal control points is: |
| 469 |
% % |
| 470 |
% \begin{align*} |
| 471 |
% q_1 &= p_1 + \kappa\cdot\xellipse'(t_1)\\ |
| 472 |
% q_2 &= p_2 - \kappa\cdot\xellipse'(t_2)\\ |
| 473 |
% \kappa &= \sin(t_2 - t_1)\frac{\sqrt{4 + 3\tan^2(\frac{t_2 - t_1}{2})}-1}{3} |
| 474 |
% \end{align*} |
| 475 |
% \noindent We will use cubic bezier curves since they look best. However, a na\"\i{}ve implementation |
| 476 |
% may be too expensive in \LaTeX: if we count the expensive operations, we need about 11 $\cos$/$\sin$ |
| 477 |
% operations, plus a $\sqrt{}$ and 2 $\arctan$ operations. |
| 478 |
% % |
| 479 |
% \subsection{Optimizing elliptic arc equations} |
| 480 |
% Fortunately, we can improve upon this. First we note: |
| 481 |
% \begin{flalign*} |
| 482 |
% t_i &= \arctan_2(\frac{\sin(\alpha_i)}{b},\frac{\cos(\alpha_i)}{a}) & \hfill\\ |
| 483 |
% &= \arctan(\frac{a}{b}\tan(\alpha_i)) \\ |
| 484 |
% &= \arctan(\kk{i}) & \mbox{(introducing $\kk{i}$ for $\frac{a}{b}\tan(\alpha_i)$)} |
| 485 |
% \end{flalign*} |
| 486 |
% \noindent where we write $\kk{i}$ for $\frac{a}{b}\tan(\alpha_i)$. Now, |
| 487 |
% \begin{flalign*} |
| 488 |
% \cost{i} &= \cos(t_i)\\ |
| 489 |
% &= \cos(\arctan(\kk{i})) & \mbox{(geometry and pythagorean theorem)}\\ |
| 490 |
% &= \sign{i}\frac{1}{\sqrt{1 + \kk{i}^2}} \\ |
| 491 |
% \mbox{with}\\ |
| 492 |
% \sign{i} &= \textsf{if}\; \cos(\alpha_i) < 0\; \textsf{then}\; -\; \textsf{else}\; + |
| 493 |
% \end{flalign*} |
| 494 |
% Later we will see how we can efficiently calculate the square root term, but first |
| 495 |
% do the same derivation for the $\sin$ function: |
| 496 |
% \begin{flalign*} |
| 497 |
% \sint{i}&= \sin(t_i) \\ |
| 498 |
% &= \sin(\arctan(\frac{a}{b}\tan(\alpha_i))) & \\ |
| 499 |
% &= \sin(\arctan(\kk{i})) \\ |
| 500 |
% &= \sign{i}\frac{\kk{i}}{\sqrt{1 + \kk{i}^2}} |
| 501 |
% \end{flalign*} |
| 502 |
% \noindent Note that the interaction between the $\sin$ and $\kk{i}$ term (whose sign is determined by $\tan(\alpha_i)$) allows us to reuse the sign function used for $\cost{i}$. |
| 503 |
% % |
| 504 |
% Using the previous equalities we can restate the parametric equations in terms of $\sint{i}$ |
| 505 |
% and $\cost{i}$: |
| 506 |
% \begin{flalign*} |
| 507 |
% \xellipse_i &= (c_x + a\cdot\cost{i}), c_y + b\cdot\sint{i}) \\ |
| 508 |
% \xellipse'_i &= (-a\cdot\sint{i}, b\cdot\cost{i}) |
| 509 |
% \end{flalign*} |
| 510 |
% % |
| 511 |
% \noindent This takes care of $p_1$ and $p_2$. The control points $q$ still need $\sin(t_2 - t_1)$ and $\tan(\frac{t_2 - t_1}{2})$. |
| 512 |
% The halving rule on $\tan$ gives us: |
| 513 |
% \[ |
| 514 |
% \tan(\frac{t_2 - t_1}{2}) = \frac{1 - \cos(t_2 - t_1)}{\sin(t_2 - t_1)} \mbox{\quad(\cite[page 71, 4.3.20]{abst})} |
| 515 |
% \] |
| 516 |
% \noindent So that leaves $\sin(t_2 - t_1)$ and $\cos(t_2 - t_1)$. Using the addition laws it follows: |
| 517 |
% \begin{flalign*} |
| 518 |
% \sin(t_2 - t_1) = \sint2\cost1 - \cost2\sint1 & \mbox{\quad(\cite[page 72, 4.3.16]{abst})}\\ |
| 519 |
% \cos(t_2 - t_1) = \cost2\cost1 + \sint2\sint1 & \mbox{\quad(\cite[page 72, 4.3.17]{abst})} |
| 520 |
% \end{flalign*} |
| 521 |
% |
| 522 |
% \subsection{Circular square roots} |
| 523 |
% \noindent Now, we only need two $\tan$ operations to calculate the initial $\kk{1}$ and $\kk{2}$ terms but we still have |
| 524 |
% three square roots: $\sqrt{1 + \kk{i}^2}$ and $\sqrt{4 + 3\tan^2(\frac{t_2 - t_1}{2})}$. |
| 525 |
% Fortunately, both have the form $\sqrt{x^2 + y^2}$. For this form, we can make a very good |
| 526 |
% \begin{wrapfigure}[10]{o}{0.3\textwidth} |
| 527 |
% \setlength\unitlength{3pt} |
| 528 |
% \begin{picture}(30,30)(-15,-15)% |
| 529 |
% \linethickness{0.4pt}\roundjoin% |
| 530 |
% \iffalse |
| 531 |
% \put(0,0){\color{gainsboro}% |
| 532 |
% \multiput(-15,-15)(1,0){31}{\line(0,1){30}}% |
| 533 |
% \multiput(-15,-15)(0,1){31}{\line(1,0){30}}% |
| 534 |
% }% |
| 535 |
% \fi |
| 536 |
% \color{gainsboro}% |
| 537 |
% \put(0,0){\put(0,-15){\line(0,1){30}}% |
| 538 |
% \put(-15,0){\line(1,0){30}}% |
| 539 |
% }% |
| 540 |
% \color{black}% |
| 541 |
% \put(0,0){\circle{20}\put(-9,3){$\,x^2 + y^2$}% |
| 542 |
% \color{maroon}\moveto(14.14,0)\lineto(0,14.14)\lineto(-14.14,0)\lineto(0,-14.14) |
| 543 |
% \closepath\strokepath |
| 544 |
% \put(3,13){$\frac{1}{\sqrt{2}}(x+y)$}% |
| 545 |
% \color{navy}\moveto(10,10)\lineto(-10,10)\lineto(-10,-10)\lineto(10,-10) |
| 546 |
% \closepath\strokepath |
| 547 |
% \put(6,-12){$\,\max(x,y)$}% |
| 548 |
% } |
| 549 |
% % |
| 550 |
% \end{picture}\iffalse\caption{Estimating an initial value for $\sqrt{x^2+y^2}$}\fi |
| 551 |
% \end{wrapfigure} |
| 552 |
% initial guess for the square root, since this is the parametric equation for a circle. |
| 553 |
% The two good initial guesses form a `square' and `diamond' around this circle, namely |
| 554 |
% $\max(\abs{x},\abs{y})$ and $\frac{1}{\sqrt{2}}\abs{x+y}$. Each one can be superior depending if $x$ and $y$ |
| 555 |
% are close or not, but it can be shown that the best choice is always the largest of these. |
| 556 |
% Using this guess as an initial seed, we can do a standard Newton-Raphson iteration to |
| 557 |
% find a the square root where we only need 2 or 3 steps to achieve the desired precision. |
| 558 |
% Let's define a `circular square root' function $\csqrt$ such that |
| 559 |
% $\csqrt(x,y) \approx \sqrt{x^2 + y^2}$ as: |
| 560 |
% \begin{align*} |
| 561 |
% \csqrt(x,y) = &\textsf{let} & sqr & = x^2 + y^2 & \hfill \\ |
| 562 |
% & & x_0 & = \max(\abs{x},\abs{y},\frac{1}{\sqrt{2}}\abs{x+y}) & \\ |
| 563 |
% & & x_1 & = (x_0 + \frac{sqr}{x_0})/2 & \hspace{\textwidth}\\ |
| 564 |
% & & x_2 & = (x_1 + \frac{sqr}{x_1})/2 &\\ |
| 565 |
% & \textsf{in} & x_2 & |
| 566 |
% \end{align*} |
| 567 |
% |
| 568 |
% \subsection{The optimized elliptical B\'ezier equations} |
| 569 |
% \noindent Taking it all together, we get the following equations for a cubic B\'ezier curve approximation of an elliptical arc, |
| 570 |
% where we assume as input the center point $(c_x,c_y)$, the $x$- and $y$-radius $(a,b)$, and a start and end angle |
| 571 |
% $\alpha_1$ and $\alpha_2$. % It is assumed that $\alpha_1 \ne \alpha_2$ and $a \ge 0, b \ge 0$. Of course, |
| 572 |
% with bezier curves one should build a full ellipse of parts where for each part $\rvert\alpha_1 - \alpha_2\lvert \le 90$. |
| 573 |
% Given these parameters, the start and end point $p_1$ and $p_2$, and the control points $q_1$ and $q_2$ are |
| 574 |
% defined as: |
| 575 |
% \begin{flalign*} |
| 576 |
% p_1 &= \xellipse_1 & \\ |
| 577 |
% p_2 &= \xellipse_2\\ |
| 578 |
% q_1 &= p_1 + \kappa\cdot\xellipse'_1\\ |
| 579 |
% q_2 &= p_2 - \kappa\cdot\xellipse'_2\\ |
| 580 |
% \xellipse_i &= (c_x + a\cdot\cost{i}, c_y + b\cdot\sint{i})\\ |
| 581 |
% \xellipse'_i &= (-a\cdot\sint{i}, b\cdot\cost{i}) |
| 582 |
% \end{flalign*} |
| 583 |
% The $\cost{i}$ and $\sint{i}$ are calculated as: |
| 584 |
% \begin{flalign*} |
| 585 |
% \sint{i} & = \sign{i}\frac{\kk{i}}{\sk{i}} & \\ |
| 586 |
% \cost{i} & = \sign{i}\frac{1}{\sk{i}} |
| 587 |
% \end{flalign*} |
| 588 |
% with |
| 589 |
% \begin{flalign*} |
| 590 |
% \kk{i} &= \frac{a}{b}\tan(\alpha_i) & \\ |
| 591 |
% \sk{i} &= \csqrt(1,\kk{i}) \;\;(\approx \sqrt{1 + \kk{i}^2}) \\ |
| 592 |
% \sign{i} &= \textsf{if}\; \cos(\alpha_i) < 0\; \textsf{then}\; -\; \textsf{else}\; + |
| 593 |
% \end{flalign*} |
| 594 |
% And finally, the $\kappa$ term can be defined as: |
| 595 |
% \begin{flalign*} |
| 596 |
% \kappa &= \sint{21}\frac{\kappa_{sqrt}-1}{3} & |
| 597 |
% \end{flalign*} |
| 598 |
% with |
| 599 |
% \begin{flalign*} |
| 600 |
% \sint{21} & = \sint2\cost1 - \cost2\sint1 \;\;(=\sin(t_2 - t_1)) & \\ |
| 601 |
% \cost{21} & = \cost2\cost1 + \sint2\sint1 \;\;(=\cos(t_2 - t_1))\\ |
| 602 |
% \kappa_{tan} &= \frac{1 - \cost{21}}{\sint{21}} \;\;\mbox{(note: divides by zero if $\alpha_1 = \alpha_2$)}\\ |
| 603 |
% \kappa_{sqrt} &= \csqrt(\sqrt{4},\sqrt{3}\cdot\kappa_{tan}) \;\;(\approx \sqrt{4 + 3\kappa_{tan}^2}) |
| 604 |
% \end{flalign*} |
| 605 |
% |
| 606 |
%\section{Implementation} |
| 607 |
% |
| 608 |
% Generally, we use e-\TeX{} division to divide dimensions, where we |
| 609 |
% divide \rarg{dim$_1$} by \rarg{dim$_2$} using: |
| 610 |
% |\dimexpr 1pt * |\rarg{dim$_1$}|/|\rarg{dim$_2$}|\relax| |
| 611 |
% since it keeps a 64-bit intermediate result for such `scaling' expressions. |
| 612 |
% Note that both \rarg{dim} |
| 613 |
% expressions occur in an integer context and \TeX{} will convert |
| 614 |
% them to numbers automatically (i.e. in |sp| units). |
| 615 |
% |
| 616 |
|
| 617 |
% \subsection{Generic math and trigonometry routines} |
| 618 |
% |
| 619 |
% \begin{macro}{\pIIe@csedef} |
| 620 |
% \marg{csname}\textit{pattern}\marg{body}\\ |
| 621 |
% Define a macro by a \textit{csname}. Just like the |\csedef| function |
| 622 |
% from \textsf{etoolbox} package |
| 623 |
% \begin{macrocode} |
| 624 |
\providecommand*\pIIe@csedef[1]{\expandafter\edef\csname #1\endcsname} |
| 625 |
% \end{macrocode} |
| 626 |
% \end{macro} |
| 627 |
% |
| 628 |
%\begin{macro}{\pIIe@ellip@csqrt} |
| 629 |
% \marg{dimen$_x$}\marg{dimen$_y$}\marg{dimreg$_{res}$}\\ |
| 630 |
% Calculates $res \approx \sqrt{x^2 + y^2}$ and caches previous results |
| 631 |
% for efficiency. |
| 632 |
% |
| 633 |
% Overwrites |\@ovxx|,|\@ovyy|,|\@ovdx|,|\@ovdy|,|\@tempa|, and |\dimen@|. |
| 634 |
% \begin{macrocode} |
| 635 |
\newcommand*\pIIe@ellip@csqrt[3]{% |
| 636 |
\@ovxx=#1\relax |
| 637 |
\ifdim\@ovxx<\z@\@ovxx-\@ovxx\fi |
| 638 |
\@ovyy=#2\relax |
| 639 |
\ifdim\@ovyy<\z@\@ovyy-\@ovyy\fi |
| 640 |
\edef\pIIe@csname{@csqrt(\number\@ovxx,\number\@ovyy)}% |
| 641 |
\expandafter\ifx\csname\pIIe@csname\endcsname\relax |
| 642 |
\pIIe@ellip@csqrt@% |
| 643 |
\pIIe@csedef{\pIIe@csname}{\the\dimen@}% |
| 644 |
#3\dimen@ |
| 645 |
\else |
| 646 |
#3\dimexpr\csname\pIIe@csname\endcsname\relax |
| 647 |
\fi |
| 648 |
} |
| 649 |
% \end{macrocode} |
| 650 |
%\end{macro} |
| 651 |
%\begin{macro}{\pIIe@ellip@csqrt@} |
| 652 |
% Internal routine: calculates |\dimen@| $\approx \sqrt{x^2 + y^2}$. |
| 653 |
% where $x \ge 0$ and $y \ge 0$, and |\@ovxx| $=x$ and |\@ovyy| $=y$. |
| 654 |
% |
| 655 |
% Overwrites |\@ovdx|,|\@ovdy|, and |\@tempa|. |
| 656 |
% \begin{macrocode} |
| 657 |
\newcommand*\pIIe@ellip@csqrt@{% |
| 658 |
% \end{macrocode} |
| 659 |
% First determine $\max(x,y,\frac{1}{\sqrt{2}}(x+y))$ in |\dimen@|. |
| 660 |
% Put the sum $x+y$ in |\@ovdx|. |
| 661 |
% \begin{macrocode} |
| 662 |
\@ovdx\@ovxx |
| 663 |
\advance\@ovdx by \@ovyy |
| 664 |
% \end{macrocode} |
| 665 |
% Put initial guess in |\dimen@| $=\max(\abs{x},\abs{y},\frac{1}{\sqrt{2}}(x+y))$. |
| 666 |
% \begin{macrocode} |
| 667 |
\[email protected]\@ovdx |
| 668 |
\ifdim\dimen@<\@ovyy\dimen@\@ovyy\fi |
| 669 |
\ifdim\dimen@<\@ovxx\dimen@\@ovxx\fi |
| 670 |
% \end{macrocode} |
| 671 |
% To prevent overflowing \TeX{} dimensions we only do |
| 672 |
% a further Newton-Raphson approximation if the sum $x+y$ is less than 128pt. |
| 673 |
% Otherwise, for our application, the initial guess is still very precise since $x \ll y$ in that case. |
| 674 |
% \begin{macrocode} |
| 675 |
\ifdim\@ovdx<128\p@ |
| 676 |
% \end{macrocode} |
| 677 |
% Set |\@ovxx| to $x^2 + y^2$ |
| 678 |
% \begin{macrocode} |
| 679 |
\edef\@tempa{\strip@pt\@ovxx}% |
| 680 |
\@ovxx\@tempa\@ovxx |
| 681 |
\edef\@tempa{\strip@pt\@ovyy}% |
| 682 |
\@ovyy\@tempa\@ovyy |
| 683 |
\advance\@ovxx by \@ovyy |
| 684 |
% \end{macrocode} |
| 685 |
% Do two steps of Newton-Raphson (should we do three?) |
| 686 |
% \begin{macrocode} |
| 687 |
\advance\dimen@ by \dimexpr1pt * \@ovxx/\dimen@\relax |
| 688 |
\divide\dimen@ by 2% |
| 689 |
\advance\dimen@ by \dimexpr1pt * \@ovxx/\dimen@\relax |
| 690 |
\divide\dimen@ by 2% |
| 691 |
\fi |
| 692 |
% \end{macrocode} |
| 693 |
% Result is |\dimen@|. |
| 694 |
% \begin{macrocode} |
| 695 |
} |
| 696 |
% \end{macrocode} |
| 697 |
% \end{macro} |
| 698 |
% |
| 699 |
|
| 700 |
|
| 701 |
% \begin{macro}{\pIIe@atan@} |
| 702 |
% |
| 703 |
% Approximate the $\arctan$ using |
| 704 |
% \[x\cdot\frac{\pi}{4} - x \cdot (\abs{x} - 1) \cdot (0.2447 + 0.0663\cdot\abs{x})\] |
| 705 |
% This approximation was described by Rajan et al.~\cite{rajan:atan}. |
| 706 |
% |
| 707 |
% The \cmd{pIIe@atan@} computes the arctan of |\dimen@| which must be between $-1$ and $1$, and stores it in |\dimen@| again. |
| 708 |
% Overwrites |\@tempdim|(|a|,|b|,|c|,|d|),|\@tempa|, and |\dimen@|. |
| 709 |
% \begin{macrocode} |
| 710 |
\newcommand*\pIIe@atan@{% |
| 711 |
% \end{macrocode} |
| 712 |
% |\dimen@| contains $x$. |
| 713 |
% \begin{macrocode} |
| 714 |
\@tempdima\dimen@ |
| 715 |
% \end{macrocode} |
| 716 |
% Set |\@dimtmpb| to $\abs{x}$ |
| 717 |
% \begin{macrocode} |
| 718 |
\@tempdimb\@tempdima |
| 719 |
\ifdim\@tempdimb<\z@\@tempdimb-\@tempdimb\fi |
| 720 |
\[email protected]\@tempdimb |
| 721 |
\advance\dimen@ 0.2447pt\relax |
| 722 |
\advance\@tempdimb -1pt\relax |
| 723 |
\edef\@tempa{\strip@pt\@tempdimb}% |
| 724 |
\dimen@\@tempa\dimen@ |
| 725 |
\edef\@tempa{\strip@pt\@tempdima}% |
| 726 |
\dimen@\@tempa\dimen@ |
| 727 |
\dimen@-\dimen@ |
| 728 |
% \end{macrocode} |
| 729 |
% Add $x\cdot\frac{\pi}{4}$ ($\approx 0.7853\cdot x$). |
| 730 |
% \begin{macrocode} |
| 731 |
\advance\dimen@ 0.7853\@tempdima |
| 732 |
} |
| 733 |
% \end{macrocode} |
| 734 |
% \end{macro} |
| 735 |
|
| 736 |
% \begin{macro}{\pIIe@atantwo} |
| 737 |
% \marg{dimen$_y$}\marg{dimen$_x$}\marg{dimreg$_{res}$}\\ |
| 738 |
% Calculate \rarg{res} $= \arctan_2(y,x)$ and caches the result for later use. |
| 739 |
% |
| 740 |
% Overwrites |\@tempdim|(|a|,|b|,|c|,|d|),|\@tempa|, and |\dimen@|. |
| 741 |
% Both $y$ and $x$ must be dimensions. |
| 742 |
% \begin{macrocode} |
| 743 |
\newcommand*\pIIe@atantwo[3]{% |
| 744 |
\edef\pIIe@csname{@atan2(\number\dimexpr#1\relax,\number\dimexpr#2\relax)}% |
| 745 |
\expandafter\ifx\csname\pIIe@csname\endcsname\relax |
| 746 |
\pIIe@atantwo@{#1}{#2}{#3}% |
| 747 |
\pIIe@csedef{\pIIe@csname}{\the\dimexpr#3\relax}% |
| 748 |
\else |
| 749 |
#3\dimexpr\csname\pIIe@csname\endcsname\relax |
| 750 |
\fi |
| 751 |
} |
| 752 |
% \end{macrocode} |
| 753 |
% \end{macro} |
| 754 |
|
| 755 |
% \begin{macro}{\pIIe@atantwo@} |
| 756 |
% \marg{dimen$_y$}\marg{dimen$_x$}\marg{dimreg$_{res}$}\\ |
| 757 |
% Calculate \rarg{res} $= \arctan_2(y,x)$. |
| 758 |
% Overwrites |\@tempdim|(|a|,|b|,|c|,|d|),|\@tempa|, and |\dimen@|. |
| 759 |
% Both $y$ and $x$ must be dimensions. |
| 760 |
% \begin{macrocode} |
| 761 |
\newcommand*\pIIe@atantwo@[3]{% |
| 762 |
\@tempdima\dimexpr#2\relax |
| 763 |
\@tempdimb\dimexpr#1\relax |
| 764 |
% \end{macrocode} |
| 765 |
% Handle extremes |
| 766 |
% \begin{macrocode} |
| 767 |
\ifdim\@tempdima=\z@\relax |
| 768 |
\ifdim\@tempdimb>\z@\relax\dimen@90\p@ |
| 769 |
\else\ifdim\@tempdimb<\z@\relax\dimen@-90\p@ |
| 770 |
\else\dimen@0\p@ |
| 771 |
\fi\fi |
| 772 |
\else |
| 773 |
% \end{macrocode} |
| 774 |
% Save angle adjustment term in |\@tempdimd|. |
| 775 |
% \begin{macrocode} |
| 776 |
\@tempdimd\z@ |
| 777 |
\ifdim\@tempdima<\z@\relax |
| 778 |
\ifdim\@tempdimb<\z@\relax\@tempdimd-180\p@ |
| 779 |
\else\@tempdimd180\p@ |
| 780 |
\fi |
| 781 |
\fi |
| 782 |
% \end{macrocode} |
| 783 |
% Divide $\frac{y}{x}$ and check if $-1 \le \frac{y}{x} \le 1$. |
| 784 |
% \begin{macrocode} |
| 785 |
\dimen@\dimexpr1pt * \@tempdimb/\@tempdima\relax |
| 786 |
\@tempdimc\dimen@ |
| 787 |
\ifdim\@tempdimc<\z@\relax\@tempdimc-\@tempdimc\fi |
| 788 |
\ifdim\@tempdimc>\p@\relax |
| 789 |
% \end{macrocode} |
| 790 |
% Use the equality $\arctan(x) = \pm\frac{1}{2}\pi - \arctan(\frac{1}{x})$ |
| 791 |
% to stay within the valid domain of |\pIIe@atan@|. The sign $\pm$ is |
| 792 |
% positive when $x \ge 0$ and negative otherwise. |
| 793 |
% \begin{macrocode} |
| 794 |
\dimen@\dimexpr1pt * \@tempdima/\@tempdimb\relax |
| 795 |
\ifdim\dimen@<\z@\relax\def\@tempsign{-}\else\def\@tempsign{}\fi |
| 796 |
\pIIe@atan@ |
| 797 |
\dimen@-\dimen@ |
| 798 |
\advance\dimen@ by \@tempsign1.5707pt\relax |
| 799 |
\else |
| 800 |
\pIIe@atan@ |
| 801 |
\fi |
| 802 |
% \end{macrocode} |
| 803 |
% And convert back to degrees ($\frac{180}{\pi} \approx 57.29578$) |
| 804 |
% \begin{macrocode} |
| 805 |
\[email protected]\dimen@ |
| 806 |
% \end{macrocode} |
| 807 |
% Apply angle adjustment |
| 808 |
% \begin{macrocode} |
| 809 |
\advance\dimen@ by \@tempdimd |
| 810 |
\fi |
| 811 |
#3\dimen@% |
| 812 |
} |
| 813 |
% \end{macrocode} |
| 814 |
% \end{macro} |
| 815 |
|
| 816 |
% \subsection{Sub routines for drawing an elliptical arc} |
| 817 |
% |
| 818 |
% |
| 819 |
% \begin{macro}{\pIIe@noneto} |
| 820 |
% \marg{dimen$_x$}\marg{dimen$_y$}\\ |
| 821 |
% Ignores its arguments. Used as a no-op instead of |\pIIe@lineto| or |pIIe@moveto|. |
| 822 |
% \begin{macrocode} |
| 823 |
\newcommand*\pIIe@noneto[2]{} |
| 824 |
% \end{macrocode} |
| 825 |
% \end{macro} |
| 826 |
% |
| 827 |
%\begin{macro}{\pIIe@ellip@sincost@} |
| 828 |
% \marg{$\alpha_i$}\marg{$i$ = |one| or |two|}\\ |
| 829 |
% Calculate $\sint{i}$ and $\cost{i}$ into the |\@ellip|(|sin|/|cos|)$i$. |
| 830 |
% Assumes |\@ellipratio| $=\frac{a}{b}$. |
| 831 |
% \begin{macrocode} |
| 832 |
\newcommand*\pIIe@ellip@sincost@[2]{% |
| 833 |
% \end{macrocode} |
| 834 |
% Put the $\sin(\alpha_i)$ and $\cos(\alpha_i)$ into |\@tempdima| and |\@tempdimb|. |
| 835 |
% \begin{macrocode} |
| 836 |
\CalculateSin{#1}% |
| 837 |
\CalculateCos{#1}% |
| 838 |
\@tempdima\UseSin{#1}\p@ |
| 839 |
\@tempdimb\UseCos{#1}\p@ |
| 840 |
% \end{macrocode} |
| 841 |
% Check for extremes where $\tan = \pm\infty$. |
| 842 |
% \begin{macrocode} |
| 843 |
\ifdim\@tempdima=\p@\relax |
| 844 |
\pIIe@csedef{@ellipsin#2}{1}% |
| 845 |
\pIIe@csedef{@ellipcos#2}{0}% |
| 846 |
\else\ifdim\@tempdima=-\p@\relax |
| 847 |
\pIIe@csedef{@ellipsin#2}{-1}% |
| 848 |
\pIIe@csedef{@ellipcos#2}{0}% |
| 849 |
\else |
| 850 |
% \end{macrocode} |
| 851 |
% Calculate $\kk{i}$ in |\@tempdimc| and $\sqrt{1 + \kk{i}^2}$ in |\@tempdimd|, |
| 852 |
% and derive $\sint{i}$ and $\cost{i}$. |
| 853 |
% \begin{macrocode} |
| 854 |
\@tempdimc\@ellipratio\dimexpr1pt * \@tempdima/\@tempdimb\relax |
| 855 |
%\typeout{ i#2=\the\@tempdimc, sin(#1)=\the\@tempdima}% |
| 856 |
\pIIe@ellip@csqrt{\p@}{\@tempdimc}\@tempdimd |
| 857 |
\ifdim\@tempdimb<\z@\relax\@tempdimd-\@tempdimd\fi |
| 858 |
\pIIe@csedef{@ellipsin#2}{\strip@pt\dimexpr1pt * \@tempdimc/\@tempdimd\relax}% |
| 859 |
\pIIe@csedef{@ellipcos#2}{\strip@pt\dimexpr1pt * \p@/\@tempdimd\relax}% |
| 860 |
\fi\fi |
| 861 |
} |
| 862 |
% \end{macrocode} |
| 863 |
% \end{macro} |
| 864 |
|
| 865 |
%\begin{macro}{\pIIe@ellip@sincost} |
| 866 |
% \marg{$\alpha_1$}\marg{$\alpha_2$}\\ |
| 867 |
% Calculate $\sint{i}$ and $\cost{i}$ into the |\@ellip|(|sin|/|cos|)(|one|/|two|). |
| 868 |
% Assumes |\@ovro|$=a$ and |\@ovri|$=b$ with $b \ne 0$. |
| 869 |
% \begin{macrocode} |
| 870 |
\newcommand*\pIIe@ellip@sincost[2]{% |
| 871 |
% \end{macrocode} |
| 872 |
% Set |\@ellipratio| to the ratio $\frac{a}{b}$. |
| 873 |
% \begin{macrocode} |
| 874 |
%\typeout{ calc sin cos: angles (#1,#2), radii: (\the\@ovro,\the\@ovri)}% |
| 875 |
\edef\@ellipratio{\strip@pt\dimexpr1pt * \@ovro/\@ovri\relax}% |
| 876 |
% \end{macrocode} |
| 877 |
% And calculate $\sint{i}$ and $\cost{i}$ |
| 878 |
% \begin{macrocode} |
| 879 |
\pIIe@ellip@sincost@{#1}{one}% |
| 880 |
\pIIe@ellip@sincost@{#2}{two}% |
| 881 |
%\typeout{ sincos(a=#1)=(\@ellipsinone,\@ellipcosone), sincos(a=#2)=(\@ellipsintwo,\@ellipcostwo), }% |
| 882 |
} |
| 883 |
% \end{macrocode} |
| 884 |
% \end{macro} |
| 885 |
% |
| 886 |
% |
| 887 |
%\begin{macro}{\pIIe@omega} |
| 888 |
% \marg{$i$ = |one| or |two|}\\ |
| 889 |
% Calculates $\xellipse_i$ into |\@tempdima| and |\@tempdimb|. |
| 890 |
% Assumes |\@ovro|$=a$ and |\@ovri|$=b$. |
| 891 |
% \begin{macrocode} |
| 892 |
\newcommand*\pIIe@omega[3]{% |
| 893 |
\@tempdima\csname @ellipcos#3\endcsname\@ovro |
| 894 |
\advance\@tempdima by #1\relax |
| 895 |
\@tempdimb\csname @ellipsin#3\endcsname\@ovri |
| 896 |
\advance\@tempdimb by #2\relax |
| 897 |
} |
| 898 |
% \end{macrocode} |
| 899 |
% \end{macro} |
| 900 |
|
| 901 |
%\begin{macro}{\pIIe@omegai} |
| 902 |
% \marg{$i$ = |one| or |two|}\\ |
| 903 |
% Calculates $\xellipse'_i$ into |\@tempdimc| and |\@tempdimd|. |
| 904 |
% Assumes |\@ovro|$=a$ and |\@ovri|$=b$. |
| 905 |
% \begin{macrocode} |
| 906 |
\newcommand*\pIIe@omegai[1]{% |
| 907 |
\@tempdimc\csname @ellipsin#1\endcsname\@ovro |
| 908 |
\@tempdimc-\@tempdimc |
| 909 |
\@tempdimd\csname @ellipcos#1\endcsname\@ovri |
| 910 |
} |
| 911 |
% \end{macrocode} |
| 912 |
% \end{macro} |
| 913 |
|
| 914 |
%\begin{macro}{\pIIe@ellip@kappa} |
| 915 |
% Calculates $\kappa$, expects |\@ellip|(|sin|/|cos|)(|one|/|two|) to be defined. |
| 916 |
% \begin{macrocode} |
| 917 |
\newcommand*\pIIe@ellip@kappa{% |
| 918 |
% \end{macrocode} |
| 919 |
% Calculate $\sint{21}$ and $\cost{21}$ in |\@tempdima| and |\@tempdimb|. |
| 920 |
% \begin{macrocode} |
| 921 |
\@ovyy\@ellipsinone\p@ |
| 922 |
\@ovxx\@ellipcosone\p@ |
| 923 |
\@tempdima\@ellipcostwo\@ovyy |
| 924 |
\@tempdima-\@tempdima |
| 925 |
\advance\@tempdima by \@ellipsintwo\@ovxx |
| 926 |
\@tempdimb\@ellipcostwo\@ovxx |
| 927 |
\advance\@tempdimb by \@ellipsintwo\@ovyy |
| 928 |
% \end{macrocode} |
| 929 |
% First test if $\sint{21} = 0$ to prevent division by zero. In that |
| 930 |
% case, it must have been that $\alpha_1 = \alpha_2$ and we set $\kappa$ to zero |
| 931 |
% so it the control points become equal to the start and end point. |
| 932 |
% \begin{macrocode} |
| 933 |
\ifdim\@tempdima=\z@\relax |
| 934 |
\edef\@ellipkappa{0}% |
| 935 |
\else |
| 936 |
% \end{macrocode} |
| 937 |
% Calculate $\kappa_{tan}$ in |\dimen@| |
| 938 |
% \begin{macrocode} |
| 939 |
\dimen@\dimexpr1pt - \@tempdimb\relax |
| 940 |
\dimen@\dimexpr1pt * \dimen@/\@tempdima\relax |
| 941 |
% \end{macrocode} |
| 942 |
% Calculate $\kappa_{sqrt}$ in |\dimen@| |
| 943 |
% \begin{macrocode} |
| 944 |
\pIIe@ellip@csqrt{2\p@}{1.73205\dimen@}{\dimen@}% |
| 945 |
% \end{macrocode} |
| 946 |
% Calculate $\kappa$ in |\dimen@| |
| 947 |
% \begin{macrocode} |
| 948 |
\advance\dimen@ by -\p@ |
| 949 |
\divide\dimen@ by 3% |
| 950 |
\edef\@tempa{\strip@pt\@tempdima}% |
| 951 |
\dimen@\@tempa\dimen@ |
| 952 |
\edef\@ellipkappa{\strip@pt\dimen@}% |
| 953 |
\fi |
| 954 |
%\typeout{ calculated kappa: \@ellipkappa}% |
| 955 |
} |
| 956 |
% \end{macrocode} |
| 957 |
% \end{macro} |
| 958 |
|
| 959 |
% \subsection{Core routines for drawing elliptical arcs} |
| 960 |
% |
| 961 |
%\begin{macro}{\pIIe@elliparc@} |
| 962 |
% \oarg{start}\marg{$c_x$}\marg{$c_y$}\marg{$\alpha_1$}\marg{$\alpha_2$}\\ |
| 963 |
% Assumes that the radii are set as |\@ovro|$=a$ and |\@ovri|$=b$. |
| 964 |
% This is the main routine for drawing an elliptic arc, where $\abs{\alpha_2 - \alpha_1}\,\le 90$. |
| 965 |
% \begin{macrocode} |
| 966 |
\newcommand*\pIIe@elliparc@[5]{% |
| 967 |
%\typeout{elliparc: #1, center: (#2, #3), radius (\the\@ovro, \the\@ovri),angle (#4, #5)}% |
| 968 |
% \end{macrocode} |
| 969 |
% Define initial action: 0 (lineto), 1(moveto), or 2 (nothing) |
| 970 |
% \begin{macrocode} |
| 971 |
\ifcase #1\relax |
| 972 |
\let\@ellip@startto\pIIe@lineto |
| 973 |
\or \let\@ellip@startto\pIIe@moveto |
| 974 |
\or \let\@ellip@startto\pIIe@noneto% |
| 975 |
\else\PackageWarning{ellipse}{Illegal initial action in \protect\elliparc: % |
| 976 |
must be one of 0 (lineto), 1 (moveto) or 2 (do nothing) but I got: #1}% |
| 977 |
\fi |
| 978 |
% \end{macrocode} |
| 979 |
% Perform just the start action if the radii are zero |
| 980 |
% \begin{macrocode} |
| 981 |
\ifdim\@ovro=\z@\relax\@ovri\z@\fi |
| 982 |
\ifdim\@ovri=\z@\relax |
| 983 |
\@ellip@startto{#2}{#3}% |
| 984 |
\else |
| 985 |
% \end{macrocode} |
| 986 |
% Calculate $\sint{i}$ and $\cost{i}$ first into the |\@ellip|(|sin|/|cos|)(|one|/|two|) registers. |
| 987 |
% \begin{macrocode} |
| 988 |
\pIIe@ellip@sincost{#4}{#5}% |
| 989 |
% \end{macrocode} |
| 990 |
% And draw.. |
| 991 |
% \begin{macrocode} |
| 992 |
\pIIe@elliparc@draw{#2}{#3}% |
| 993 |
\fi |
| 994 |
} |
| 995 |
% \end{macrocode} |
| 996 |
% \end{macro} |
| 997 |
% |
| 998 |
%\begin{macro}{\pIIe@elliparc@t} |
| 999 |
% \oarg{start}\marg{$c_x$}\marg{$c_y$}\marg{$t_1$}\marg{$t_2$}\\ |
| 1000 |
% Assumes that the radii are set as |\@ovro|$=a$ and |\@ovri|$=b$. |
| 1001 |
% Moreover, this routine take $t_1$ and $t_2$ as the angles of the ellipse equation (instead of real angles $\alpha_i$). |
| 1002 |
% This routine is mainly for other libraries that may already have computed the $t$ angles |
| 1003 |
% and need a bit more efficiency. |
| 1004 |
% \begin{macrocode} |
| 1005 |
\newcommand*\pIIe@elliparc@t[5]{% |
| 1006 |
% \end{macrocode} |
| 1007 |
% Define initial action: 0 (lineto), 1(moveto), or 2 (nothing) |
| 1008 |
% \begin{macrocode} |
| 1009 |
\ifcase #1\relax |
| 1010 |
\let\@ellip@startto\pIIe@lineto |
| 1011 |
\or \let\@ellip@startto\pIIe@moveto |
| 1012 |
\or \let\@ellip@startto\pIIe@noneto% |
| 1013 |
\else\PackageWarning{ellipse}{Illegal initial action in \protect\elliparc: % |
| 1014 |
must be one of 0 (lineto), 1 (moveto) or 2 (do nothing) but I got: #1}% |
| 1015 |
\fi |
| 1016 |
% \end{macrocode} |
| 1017 |
% Perform just the start action if the radii are zero |
| 1018 |
% \begin{macrocode} |
| 1019 |
\ifdim\@ovro=\z@\relax\@ovri\z@\fi |
| 1020 |
\ifdim\@ovri=\z@\relax |
| 1021 |
\@ellip@startto{#2}{#3}% |
| 1022 |
\else |
| 1023 |
% \end{macrocode} |
| 1024 |
% Calculate $\sint{i}$ and $\cost{i}$ first into the |\@ellip|(|sin|/|cos|)(|one|/|two|) registers. |
| 1025 |
% \begin{macrocode} |
| 1026 |
\CalculateSin{#4}\CalculateCos{#4}% |
| 1027 |
\edef\@ellipsinone{\UseSin{#4}}% |
| 1028 |
\edef\@ellipcosone{\UseCos{#4}}% |
| 1029 |
\CalculateSin{#5}\CalculateCos{#5}% |
| 1030 |
\edef\@ellipsintwo{\UseSin{#5}}% |
| 1031 |
\edef\@ellipcostwo{\UseCos{#5}}% |
| 1032 |
% \end{macrocode} |
| 1033 |
% And draw.. |
| 1034 |
% \begin{macrocode} |
| 1035 |
\pIIe@elliparc@draw{#2}{#3}% |
| 1036 |
\fi |
| 1037 |
} |
| 1038 |
% \end{macrocode} |
| 1039 |
% \end{macro} |
| 1040 |
% |
| 1041 |
% \begin{macro}{pIIe@elliparc@draw} |
| 1042 |
% \marg{$c_x$}\marg{$c_y$}\\ |
| 1043 |
% Expects $a =$|\@ovro|, $b$ = |\@ovri|, and |\@ellip|(|sin|/|cos|)(|one|/|two|) defined. |
| 1044 |
% |\@ellipstarto| should contain the initial drawing action and is called with an initial |
| 1045 |
% $x$ and $y$ coordinate (usually equal to |\pIIe@lineto|,|\pIIe@moveto|, or |pIIe@noneto|). |
| 1046 |
% \begin{macrocode} |
| 1047 |
\newcommand*\pIIe@elliparc@draw[2]{% |
| 1048 |
% Calculate $\kappa$. |
| 1049 |
% \begin{macrocode} |
| 1050 |
\pIIe@ellip@kappa% |
| 1051 |
% \end{macrocode} |
| 1052 |
% Now we are ready to compute the control points. First $p_1$. |
| 1053 |
% \begin{macrocode} |
| 1054 |
\pIIe@omega{#1}{#2}{one}% |
| 1055 |
%\typeout{ point one: (\the\@tempdima,\the\@tempdimb)}% |
| 1056 |
% \end{macrocode} |
| 1057 |
% The coordinates are added to the path if and how necessary: |
| 1058 |
% \begin{macrocode} |
| 1059 |
\@ellip@startto\@tempdima\@tempdimb |
| 1060 |
% \end{macrocode} |
| 1061 |
% Add control point $q_1$ |
| 1062 |
% \begin{macrocode} |
| 1063 |
\pIIe@omegai{one}% |
| 1064 |
\advance\@tempdima by \@ellipkappa\@tempdimc |
| 1065 |
\advance\@tempdimb by \@ellipkappa\@tempdimd |
| 1066 |
\pIIe@add@nums\@tempdima\@tempdimb |
| 1067 |
%\typeout{ control one: (\the\@tempdima,\the\@tempdimb)}% |
| 1068 |
% \end{macrocode} |
| 1069 |
% Calculate $p_2$ |
| 1070 |
% \begin{macrocode} |
| 1071 |
\pIIe@omega{#1}{#2}{two}% |
| 1072 |
% \end{macrocode} |
| 1073 |
% Add control point $q_1$ |
| 1074 |
% \begin{macrocode} |
| 1075 |
\pIIe@omegai{two}% |
| 1076 |
\@tempdimc\@ellipkappa\@tempdimc |
| 1077 |
\@tempdimd\@ellipkappa\@tempdimd |
| 1078 |
\@tempdimc-\@tempdimc |
| 1079 |
\@tempdimd-\@tempdimd |
| 1080 |
\advance\@tempdimc by \@tempdima |
| 1081 |
\advance\@tempdimd by \@tempdimb |
| 1082 |
\pIIe@add@nums\@tempdimc\@tempdimd |
| 1083 |
%\typeout{ control two: (\the\@tempdimc,\the\@tempdimd)}% |
| 1084 |
% \end{macrocode} |
| 1085 |
% And finally add $p_2$ to the path |
| 1086 |
% \begin{macrocode} |
| 1087 |
\pIIe@add@CP\@tempdima\@tempdimb |
| 1088 |
%\typeout{ point two: (\the\@tempdima,\the\@tempdimb)}% |
| 1089 |
\pIIe@addtoGraph\pIIe@curveto@op |
| 1090 |
} |
| 1091 |
% \end{macrocode} |
| 1092 |
% \end{macro} |
| 1093 |
% |
| 1094 |
% |
| 1095 |
% \subsection{Normalizing elliptical arcs} |
| 1096 |
% |
| 1097 |
% \begin{macro}{pIIe@elliparc} |
| 1098 |
% \begin{macro}{pIIe@@elliparc} |
| 1099 |
% \oarg{start}\marg{$c_x$}\marg{$c_y$}\marg{a}\marg{b}\marg{$\alpha_1$}\marg{$\alpha_2$}\\ |
| 1100 |
% \strut\\ |
| 1101 |
% These two macros check the arguments and normalize the angles. |
| 1102 |
% \begin{macrocode} |
| 1103 |
\newcommand*\pIIe@elliparc[7][0]{% |
| 1104 |
% \end{macrocode} |
| 1105 |
% Store the radii in registers, where |\@ovro|$=a$ and |\@ovri|$=b$. |
| 1106 |
% \begin{macrocode} |
| 1107 |
\@ovro #4\relax |
| 1108 |
\@ovri #5\relax |
| 1109 |
\iffalse%dim\@ovro=\@ovri |
| 1110 |
% \end{macrocode} |
| 1111 |
% Call the circular arc routine if the x- and y-radius are equal |
| 1112 |
% \begin{macrocode} |
| 1113 |
\pIIe@arc[#1]{#2}{#3}{#4}{#6}{#7} |
| 1114 |
\else |
| 1115 |
% \end{macrocode} |
| 1116 |
% Normalize angles such that the arc angle $\abs{\alpha_2 - \alpha_1}\,\le 720$. |
| 1117 |
% Store the arc angle in |\@arclen|. |
| 1118 |
% \begin{macrocode} |
| 1119 |
\ifdim \@ovro<\z@ \pIIe@badcircarg\else |
| 1120 |
\ifdim \@ovri<\z@ \pIIe@badcircarg\else |
| 1121 |
\@arclen #7\p@ \advance\@arclen -#6\p@ |
| 1122 |
\ifdim \@arclen<\z@ \def\@tempsign{-}\else\def\@tempsign{}\fi |
| 1123 |
\ifdim \@tempsign\@arclen>720\p@ |
| 1124 |
\PackageWarning {ellipse}{The arc angle is reduced to -720..720}% |
| 1125 |
\@whiledim \@tempsign\@arclen>720\p@ \do {\advance\@arclen-\@tempsign360\p@}% |
| 1126 |
\@tempdima #6\p@ \advance\@tempdima \@arclen |
| 1127 |
\edef\@angleend{\strip@pt\@tempdima}% |
| 1128 |
\pIIe@@elliparc{#1}{#2}{#3}{#6}{\@angleend}% |
| 1129 |
\else |
| 1130 |
\pIIe@@elliparc{#1}{#2}{#3}{#6}{#7}% |
| 1131 |
\fi |
| 1132 |
\fi |
| 1133 |
\fi |
| 1134 |
\fi |
| 1135 |
} |
| 1136 |
% \end{macrocode} |
| 1137 |
% |\pIIe@@elliparc| divides the total angle in parts of at most $90$ degrees. |
| 1138 |
% Assumes |\@ovro|$=a$ and |\@ovri|$=b$, and |\@arclen| the arc angle, with |\@tempsign| |
| 1139 |
% sign of the arc angle. |
| 1140 |
% \begin{macrocode} |
| 1141 |
\newcommand*\pIIe@@elliparc[5]{% |
| 1142 |
\begingroup |
| 1143 |
\ifdim \@tempsign\@arclen>90\p@ |
| 1144 |
% \end{macrocode} |
| 1145 |
% If the arc angle is too large, the arc is recursively |
| 1146 |
% divided into 2 parts until the arc angle is at most 90~degrees. |
| 1147 |
% \begin{macrocode} |
| 1148 |
\divide\@arclen 2% |
| 1149 |
\@tempdima #4\p@\advance\@tempdima by \@arclen |
| 1150 |
\edef\@anglemid{\strip@pt\@tempdima}% |
| 1151 |
\def\@tempa{\pIIe@@elliparc{#1}{#2}{#3}{#4}}% |
| 1152 |
\expandafter\@tempa\expandafter{\@anglemid}% |
| 1153 |
\def\@tempa{\pIIe@@elliparc{2}{#2}{#3}}% |
| 1154 |
\expandafter\@tempa\expandafter{\@anglemid}{#5}% |
| 1155 |
\else |
| 1156 |
% \end{macrocode} |
| 1157 |
% The arc angle is smaller than 90 degrees. |
| 1158 |
% \begin{macrocode} |
| 1159 |
\pIIe@elliparc@{#1}{#2}{#3}{#4}{#5}% |
| 1160 |
\fi |
| 1161 |
\endgroup |
| 1162 |
}% |
| 1163 |
% \end{macrocode} |
| 1164 |
% \end{macro} |
| 1165 |
%\end{macro} |
| 1166 |
|
| 1167 |
% \subsection{Drawing elliptical arcs} |
| 1168 |
% |
| 1169 |
%\begin{macro}{\elliparc} |
| 1170 |
%\begin{macro}{\pIIeelliparc} |
| 1171 |
% \oarg{start}\marg{center-x}\marg{center-y}\marg{radius-x}\marg{radius-y}\marg{start-angle}\marg{end-angle}\\ |
| 1172 |
% \strut\\ |
| 1173 |
% The main elliptical arc drawing routine. We start with |\pIIeelliparc| to avoid conflicts with |
| 1174 |
% other packages. |
| 1175 |
% \begin{macrocode} |
| 1176 |
\newcommand*\pIIeelliparc[7][0]{% |
| 1177 |
\@killglue |
| 1178 |
\pIIe@elliparc[#1]{#2\unitlength}{#3\unitlength}{#4\unitlength}{#5\unitlength}{#6}{#7}% |
| 1179 |
\ignorespaces% |
| 1180 |
} |
| 1181 |
\ifx\undefined\elliparc\else |
| 1182 |
\PackageWarning{ellipse}{\protect\elliparc\space is redefined}% |
| 1183 |
\fi |
| 1184 |
\let\elliparc\pIIeelliparc |
| 1185 |
% \end{macrocode} |
| 1186 |
% \end{macro} |
| 1187 |
% \end{macro} |
| 1188 |
|
| 1189 |
% \begin{macro}{\earc} |
| 1190 |
% \begin{macro}{\earc*} |
| 1191 |
% |[|\rarg{$\alpha_0$}|,|\rarg{$\alpha_1$}|]|\marg{radius-x}\marg{radius-y}\\ |
| 1192 |
% \strut\\ |
| 1193 |
% The \cmd{\earc} command generalizes the standard \cmd{\arc} with both |
| 1194 |
% a $x$- and $y$-radius. The |\earc*| version draws a filled elliptical arc while |
| 1195 |
% |\earc| only strokes the elliptical arc. Both take an optional comma separated pair of |
| 1196 |
% angles which specify the initial and final angle ($0$ and $360$ by default). |
| 1197 |
% We start with \cmd{\pIIeearc} to avoid conflicts with otherpackages. |
| 1198 |
% \begin{macrocode} |
| 1199 |
\newcommand*\pIIeearc |
| 1200 |
{\@ifstar{\@tempswatrue\pIIe@earc@}{\@tempswafalse\pIIe@earc@}} |
| 1201 |
\newcommand*\pIIe@earc@[3][0,360]{\pIIe@earc@@(#1){#2}{#3}} |
| 1202 |
\def\pIIe@earc@@(#1,#2)#3#4{% |
| 1203 |
\if@tempswa |
| 1204 |
\pIIe@moveto\z@\z@ |
| 1205 |
\pIIe@elliparc{\z@}{\z@}{#3\unitlength}{#4\unitlength}{#1}{#2}% |
| 1206 |
\pIIe@closepath\pIIe@fillGraph |
| 1207 |
\else |
| 1208 |
\pIIe@elliparc[1]{\z@}{\z@}{#3\unitlength}{#4\unitlength}{#1}{#2}% |
| 1209 |
\pIIe@strokeGraph |
| 1210 |
\fi} |
| 1211 |
\ifx\undefined\earc\else |
| 1212 |
\PackageWarning{ellipse}{\protect\earc\space is redefined}% |
| 1213 |
\fi |
| 1214 |
\let\earc\pIIeearc |
| 1215 |
% \end{macrocode} |
| 1216 |
% \end{macro} |
| 1217 |
% \end{macro} |
| 1218 |
|
| 1219 |
% \begin{macro}{\ellipse} |
| 1220 |
% \begin{macro}{\ellipse*} |
| 1221 |
% \marg{radius-x}\marg{radius-y}\\ |
| 1222 |
% \strut\\ |
| 1223 |
% The \cmd{\ellipse} draws an ellipse with the specified $x$- and $y$-radius. |
| 1224 |
% The |\ellipse*| version draws a filled ellipse. |
| 1225 |
% We start with \cmd{\pIIeellipse} to avoid conflicts with other packages. |
| 1226 |
% The implementation redirects immediately to |earc| which generalized this command. |
| 1227 |
% \begin{macrocode} |
| 1228 |
\newcommand*\pIIeellipse |
| 1229 |
{\@ifstar{\@tempswatrue\pIIe@earc@}{\@tempswafalse\pIIe@earc@}} |
| 1230 |
\let\ellipse\pIIeellipse |
| 1231 |
% \end{macrocode} |
| 1232 |
% \end{macro} |
| 1233 |
% \end{macro} |
| 1234 |
|
| 1235 |
% |
| 1236 |
% \Finale |
| 1237 |
\endinput |
| 1238 |
|