diff options
author | Karl Berry <karl@freefriends.org> | 2015-06-14 17:52:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-06-14 17:52:09 +0000 |
commit | 0064febc472a7423c4e27f5e6708263587c19b89 (patch) | |
tree | 1184d8b95c92b85224b4e4bf9c26cb7d5df8eb9a /Master/texmf-dist/source | |
parent | 3f2aeeffbd8d4dd39f5b5d6a80fe209951e54478 (diff) |
curve2e (6jun15)
git-svn-id: svn://tug.org/texlive/trunk@37532 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r-- | Master/texmf-dist/source/latex/curve2e/curve2e.dtx | 751 |
1 files changed, 499 insertions, 252 deletions
diff --git a/Master/texmf-dist/source/latex/curve2e/curve2e.dtx b/Master/texmf-dist/source/latex/curve2e/curve2e.dtx index 599f0a2da38..3af8caafb3e 100644 --- a/Master/texmf-dist/source/latex/curve2e/curve2e.dtx +++ b/Master/texmf-dist/source/latex/curve2e/curve2e.dtx @@ -1,12 +1,13 @@ % \iffalse +% !TEX encoding = UTF-8 Unicode %<*internal> \begingroup \input docstrip.tex \keepsilent \preamble ______________________________________________________ - The curve2e package for LaTeX and XeLaTeX - Copyright (C) 2005-2012 Claudio Beccari + The curve2e package for LaTeX and XeLATeX + Copyright (C) 2010 Claudio Beccari All rights reserved License information appended @@ -14,7 +15,7 @@ \endpreamble \postamble -Copyright 2005-2012 Claudio Beccari +Copyright 2005-2015 Claudio Beccari Distributable under the LaTeX Project Public License, version 1.3c or higher (your choice). The latest version of @@ -37,7 +38,7 @@ and the derived files curve2e.sty and curve2e.pdf. % %% %% File `curve2e.dtx'. -%% Copyright (C) 2005--2011 Claudio Beccari all rights reserved. +%% Copyright (C) 2005--2015 Claudio Beccari all rights reserved. %% % What follows is the usual trick that is not typeset in the documentation % dvi file that is produced by LaTeX. It is used to define the date, the version @@ -50,26 +51,28 @@ and the derived files curve2e.sty and curve2e.pdf. % % \iffalse %<*package> -%<package>\NeedsTeXFormat{LaTeX2e} +%<package>\NeedsTeXFormat{LaTeX2e}[2014/05/01] %</package> %<*driver> \ProvidesFile{curve2e.dtx}% %</driver> %<+package>\ProvidesPackage{curve2e}% %<*package> - [2012/12/11 v.1.41 Extension package for pict2e] + [2015/06/06 v.1.42 Extension package for pict2e] %</package> %<*driver> -\documentclass{ltxdoc} +\documentclass{ltxdoc}\errorcontextlines=9 \hfuzz 10pt -\usepackage{multicol} +\usepackage{multicol,amsmath} \usepackage[utf8]{inputenc} +\usepackage{lmodern,textcomp} +\usepackage{mflogo} \usepackage{curve2e} \GetFileInfo{curve2e.dtx} -\title{The extension package \textsf{curve2e}\thanks{Version number -\fileversion; last revised \filedate.}} +\title{The extension package \textsf{curve2e}} \author{Claudio Beccari} -\date{} +\date{Version number \fileversion; last revised \filedate.} +\providecommand*\diff{\mathop{}\!\mathrm{d}} \begin{document} \maketitle \begin{multicols}{2} @@ -80,7 +83,7 @@ and the derived files curve2e.sty and curve2e.pdf. %</driver> % \fi % -% \CheckSum{2264} +% \CheckSum{2484} % \begin{abstract} % This file documents the |curve2e| extension package to the recent % implementation of the |pict2e| bundle that has been described by Lamport @@ -90,8 +93,8 @@ and the derived files curve2e.sty and curve2e.pdf. % |pict2e| has been released that incorporates some of the commands defined in % this package; apparently there are no conflicts, but only the advanced features % of |curve2e| remain available for extending the above package. Moreover -% the |xetex.def| driver was introduced so that certian commands previously -% defined in this extension not only become unnnecessary, but also would produce +% the |xetex.def| driver was introduced so that certain commands previously +% defined in this extension not only become unnecessary, but also would produce % errors when the program is used under XeLaTeX. Therefore these commands were % either eliminated or corrected. % @@ -154,10 +157,9 @@ and the derived files curve2e.sty and curve2e.pdf. % \begin{enumerate} % \item commands for setting the line terminations are introduced; the user can % chose between square or rounded caps; the default is set to rounded caps (now -% available also with |pict2e|); the 2011 upgrade of |pict2e| made these commands -% superfluous and redefined the internal special commands for the drivers, so that -% I deicided to completely eliminate these definitions and relay on those produced -% by |pict2e|; +% available also with |pict2e|); +% \item commands for specifying the way two lines or curves join to one nanother; +% ^^A % \item the |\line| macro is redefined so as to allow integer and fractional % direction coefficients, but maintaining the same syntax as in the original % \texttt{picture} environment (now available also with |pict2e|); @@ -183,15 +185,17 @@ and the derived files curve2e.sty and curve2e.pdf. % pointing to the second point; % \item a new macro |\polyline| for drawing polygonal lines is defined that % accepts from two vertices up to an arbitrary (reasonably limited) number of -% them (available now also in |pict2e|); +% them (available now also in |pict2e|); here if is redefined so as to allow +% an optional specification of the way segments fo the polyline are join to +% one another.; % \item a new macro |\Arc| is defined in order to draw an arc with arbitrary % radius and arbitrary angle amplitude; this amplitude is specified in % sexagesimal degrees, not in radians; the same functionality is now achieved with -% the |\arc| macro of |pict2e|, which provides also the star version |\arc*| that +% the |\arc| macro of |pict2e|, which provides also the strar version |\arc*| that % fills up the interior of the generated circular arc. It must be noticed that % the syntax is slighltly different, so that it's reasonable that both commands, -% in spite of producing identical arcs, might be more comfortable with this or that -% syntax. +% in spite of producing identical arcs, might be more comfortable with this or +% that syntax. % \item two new macros are defined in order to draw circular arcs with one % arrow at one or both ends; % \item a new macro |\Curve| is defined so as to draw arbitrary curved lines @@ -200,20 +204,25 @@ and the derived files curve2e.sty and curve2e.pdf. % \end{enumerate} % % In order to make the necessary calculations many macros have been defined so -% as to use complex number arithmetics to manipulate point coordinates, directions, -% rotations and the like. The trigonometric functions have also been defined in -% a way that the author believes to be more efficient than that implied by the -% \texttt{trig} package; in any case the macro names are sufficiently -% different to accommodate both definitions in the same \LaTeX\ run. +% as to use complex number arithmetics to manipulate point coordinates, +% directions (directional versors), rotations and the like. The trigonometric +% functions have also been defined in a way that the author believes to be +% more efficient than that implied by the \texttt{trig} package; in any case +% the macro names are sufficiently different to accommodate both definitions +% in the same \LaTeX\ run. % % Many aspects of this extension could be fine tuned for better performance; % many new commands could be defined in order to further extend this extension. % If the new service macros are accepted by other \TeX\ and \LaTeX\ programmers, % this beta version could become the start for a real extension of the -% \texttt{pict2e} package or even become a part of it. +% \texttt{pict2e} package or even become a part of it. Actually some macros +% have already been included in the \texttt{pict2e} package. Actually the +% \verb|\Curve| algorithm might be redefined so as to use the macros introduced +% in the \texttt{hobby} package, that implements for the typesetting engines +% the same functionalities that John Hobby wrote for \MF\ and \MP\ programs. % % For this reason I suppose that every enhancement should be submitted to -% Gäßlein and Niepraschk who are the prime maintainers of \texttt{pict2e}; +% Gäßlein and Niepraschk who are the prime maintainers of \texttt{pict2e}; % they only can decide whether or not to incorporate new macros in their package. % % \section{Summary of modifications and new commands} @@ -226,13 +235,25 @@ and the derived files curve2e.sty and curve2e.pdf. % either \LaTeX\ or PostScript styled, because it is assumed that if you use this % package you are not interested in using the original \LaTeX\ commands. See the % |pict2e| documentation in order to use the correct options |pict2e| can receive. +% \item The user is offered new commands in order to control the line terminators +% and the line joins; specifically: +% \begin{itemize} +% \item |\roundcap|: the line is terminated with a semicircle; +% \item |\squarecap|: the line is terminated with a half square; +% \item |\roundjoin|: two lines are joined with a rounded join; +% \item |\beveljoin|: two lines are joined with a bevel join; +% \item |\miterjoin|: two lines are joined with a miter join. +% \end{itemize} +% All the above commands should respect the intended range; but since they act at +% the PostScript or PDF level, not at \TeX\ level, it might be necessary to issue +% the necessary command in order to restore the previous terminator or join. % \item The commands |\linethickness|, |\thicklines|, |\thinlines| together with % |\defaultlinethickness| always redefine the internal |\@wholewidth| and -% |\@halfwidth| -% so that the former always refer to a full width and the latter to a half of it in this -% way: if you issue the command |\defaultlinewidth{2pt}| all thin lines will be -% drawn with a thickeness of 1\,pt while if a drawing command directly refers to the -% internal value |\@wholewidth|, its line will be drawn with a thickness of 2\,pt. +% |\@halfwidth| so that the latter always refer to a full width and to a half of +% it in this way: if you issue the command |\defaultlinewidth{2pt}| all thin +% lines will be drawn with a thickeness of 1\,pt while if a drawing command +% directly refers to the internal value |\@wholewidth|, its line will be drawn +% with a thickness of 2\,pt. % If one issues the declaration |\thinlines| all lines will be drawn with a 1\,pt % width, but if a command refers to the internal value |\@halfwidth| the line will % be drawn with a thickness of 0.5\,pt. The command |\linethickness| redefines the @@ -242,25 +263,26 @@ and the derived files curve2e.sty and curve2e.pdf. % |thicklines| are declarations that do not take arguments; on the opposite the % other two commands follow the standard syntax: % \begin{flushleft} -% |\linethickness|\marg{dimension value}\\ -% |\defaultlinewidth|\marg{dimension value} +% |\linethickness|\marg{dimensioned value}\\ +% |\defaultlinewidth|\marg{dimensioned value} % \end{flushleft} -% where \meta{dimension value} means a length specification complete of its units -% or a dimensional expression. -% \item Straight lines and vectors are redefined in such a way that fractional slope -% coefficients may be specified; the zero length line does not produce errors and is -% ignored; the zero length vectors draw only the arrow tips. +% where \meta{dimensioned value} means a length specification complete of its +% units or a dimensional expression. +% \item Straight lines and vectors are redefined in such a way that fractional +% slope coefficients may be specified; the zero length line does not produce +% errors and is ignored; the zero length vectors draw only the arrow tips. % \item New line and vector macros are defined that avoid the necessity of -% specifying the horizontal component |\put(3,4){\LIne(25,15)}| specifies a segment -% that starts at point $(3,4)$ and goes to point $(3+25,4+15)$; the command -% |\segment(3,4)(28,19)| achieves the same result without the need of the using -% command |\put|. +% specifying the horizontal component |\put(3,4){\LIne(25,15)}| specifies a +% segment that starts at point $(3,4)$ and goes to point $(3+25,4+15)$; the +% command |\segment(3,4)(28,19)| achieves the same result without the need of +% the using command |\put|. % The same applies to the vector commands |\Vector| and |\VECTOR|. Experience has % shown that the commands intended to joint two specified coordinates are % particularly useful. -% \item The |\polyline| command has been introduced: it accepts an unlimited list of -% point coordinates enclosed within round parentheses; the command draws a sequence -% of connected segments that joins in sequence the specified points; the syntax is: +% \item The |\polyline| command has been introduced: it accepts an unlimited +% list of point coordinates enclosed within round parentheses; the command +% draws a sequence of connected segments that joins in sequence the specified +% points; the syntax is: % \begin{flushleft} % \cs{polyline[}\marg{optional join style}\texttt{](}\meta{$P_1$}\texttt{)(}% % \meta{$P_2$}\texttt{)...(}\meta{$P_n$}\texttt{)} @@ -290,22 +312,23 @@ and the derived files curve2e.sty and curve2e.pdf. % \end{figure} % % Although you can draw polygons with |\polyline|, as it was done in -% figure~\ref{fig:polyline}, do not confuse this command with the command |\polygon| -% defined in |pict2e| 2009; the latter automatically joins the last specified -% coordinate to the first one, therefore closing the path. |pict2e| defines also the -% starred command that fills up the inside of the generated polygon. +% figure~\ref{fig:polyline}, do not confuse this command with the command +% |\polygon| defined in |pict2e| 2009; the latter automatically joins the +% last specified coordinate to the first one with a straight line, therefore +% closing the path. |pict2e| defines also the starred command that fills up +% the inside of the generated polygon. % \item The new command % \begin{flushleft} % |\Dline(|\textit{first point}|)(|\textit{second point}|)(|\textit{dash length}|)| % \end{flushleft} -% draws a dashed line containing as many dashes as possible, long as specified, and -% separated by a gap exactly the same size; actually, in order to make an even -% gap-dash sequence, the desired dash length is used to do some computations in -% order to find a suitable length, close to the one specified, such that the +% draws a dashed line containing as many dashes as possible, long as specified, +% and separated by a gap exactly the same size; actually, in order to make an +% even gap-dash sequence, the desired dash length is used to do some computations +% in order to find a suitable length, close to the one specified, such that the % distance of the end points is evenly divided in equally sized dashes and gaps. -% The end points may be anywhere in -% the drawing area, without any constraint on the slope of the joining segment. The -% desired dash length is specified as a fractional multiple of |\unitlength|; see +% The end points may be anywhere in the drawing area, without any constraint on +% the slope of the joining segment. The desired dash length is specified as a +% fractional multiple of |\unitlength|; see % figure~\ref{fig:dashline}. % \begin{figure}[!ht] % \begin{minipage}{.48\textwidth} @@ -339,30 +362,32 @@ and the derived files curve2e.sty and curve2e.pdf. % \end{minipage} % \caption{Dashed lines and graph grid}\label{fig:dashline} % \end{figure} -% \item |\GraphGrid| is a command that draws a red grid over the drawing area with -% lines separated |10\unitlength|s; it is described only with a comma separated -% couple of numbers, representing the base and the height of the grid, see -% figure~\ref{fig;dashline}; it's better to specify multiples of ten and the grid -% can be placed anywhere in the drawing plane by means of |\put|, whose coordinates -% are multiples of 10; nevertheless the grid line distance is rounded to the -% nearest multiple of 10, while the point coordinates specified to |\put| are not -% rounded at all; therefore some care should be used to place the working grid in -% the drawing plane. This grid is intended as an aid in drawing; even if you sketch -% your drawing on millimeter paper, the drawing grid turns out to be very useful; -% one must only delete or comment out the command when the drawing is finished. -% \item New trigonometric function macros have been implemented; possibly they are -% not better than the corresponding macros of the |trig| package, but they are -% supposed to be more accurate at least they were intended to be so. The other -% difference is that angles are specified in sexagesimal degrees ($360^\circ$ to one -% revolution), so that reduction to the fundamental quadrant is supposed to be more -% accurate; the tangent of odd multiples of $90^\circ$ are approximated with a -% ``\TeX\ infinity'', that is the signed value 16383.99999. This will possibly -% produce computational errors in the subsequent calculations, but at least it does -% not stop the tangent computation. In order to avoid overflows or underflows in the -% computation of small angles (reduced to the first quadrant), the sine and the -% tangent of angles smaller than $1^\circ$ are approximated by the first term of the -% McLaurin series, while for the cosine the approximation is given by the first two -% terms of the McLaurin series. In both cases theoretical errors are smaller +% \item |\GraphGrid| is a command that draws a red grid over the drawing area +% with lines separated |10\unitlength|s; it is described only with a comma +% separated couple of numbers, representing the base and the height of the grid, +% see figure~\ref{fig:dashline}; it's better to specify multiples of ten and +% the grid can be placed anywhere in the drawing plane by means of |\put|, +% whose coordinates are multiples of 10; nevertheless the grid line distance is +% rounded to the nearest multiple of 10, while the point coordinates specified +% to |\put| are not rounded at all; therefore some care should be used to place +% the working grid in the drawing plane. This grid is intended as an aid in +% drawing; even if you sketch your drawing on millimetre paper, the drawing grid +% turns out to be very useful; one must only delete or comment out the command +% when the drawing is finished. +% \item New trigonometric function macros have been implemented; possibly they +% are not better than the corresponding macros of the |trig| package, but they +% are supposed to be more accurate at least they were intended to be so. The +% other difference is that angles are specified in sexagesimal degrees +% ($360^\circ$ to one revolution), so that reduction to the fundamental quadrant +% is supposed to be more accurate; the tangent of odd multiples of $90^\circ$ +% are approximated with a ``\TeX\ infinity'', that is the signed value +% 16383.99999. This will possibly produce computational errors in the +% subsequent calculations, but at least it does not stop the tangent +% computation. In order to avoid overflows or underflows in the computation +% of small angles (reduced to the first quadrant), the sine and the tangent +% of angles smaller than $1^\circ$ are approximated by the first term of the +% McLaurin series, while for the cosine the approximation is given by the first +% two terms of the McLaurin series. In both cases theoretical errors are smaller % than what \TeX\ arithmetics can handle. % % These trigonometric functions are used within the complex number macros; but if @@ -417,41 +442,47 @@ and the derived files curve2e.sty and curve2e.pdf. % \end{figure} % \item A multitude of commands have been defined in order to manage complex % numbers; actually complex numbers are represented as a comma separated pair of -% fractional numbers. They are used to point to specific points in the drawing +% fractional numbers. They are used to address to specific points in the drawing % plane, but also as operators so as to scale and rotate other objects. In the % following \meta{vector} means a comma separated pair of fractional numbers, -% possibly stored in macros; \meta{argument} means a brace delimiteded numeric -% value, possibly a macro; \textit{macro} is a valid macro name, a backslash -% followed by letters, or anything else that can receive a definition. +% \meta{vector macro} means a macro the contains a comma separated pair of +% fractional numbers; \meta{angle macro} means a macro that contains the angle +% of a vector in sexagesimal degrees; \meta{argument} means a brace delimited +% numeric value, possibly a macro; \textit{macro} is a valid macro name, that +% is a backslash followed by letters, or anything else that can receive a +% definition. A `direction' of a vector is its versor; the angle of a vector +% is the angle between the vector and the positive $x$ axis, generally directly +% used in the Euler formula $ \vec{v} = Me^{\mathrm{j}\varphi}$. % % {\footnotesize\begin{itemize} -% \item |\MakeVectorFrom|\meta{two arguments}|to|\meta{vector} -% \item |\CopyVect|\meta{first vector}|to|\meta{second vector} +% \item |\MakeVectorFrom|\meta{two arguments}|to|\meta{vector macro} +% \item |\CopyVect|\meta{first vector}|to|\meta{second vector macro} % \item |\ModOfVect|\meta{vector}|to|\meta{macro} -% \item |\DirOfvect|\meta{vector}|to|\meta{macro} -% \item |\DmodAndDirOfVect|\meta{vector}|to|\meta{first macro}|and|\meta{second macro} -% \item |\DistanceAndDirOfVect|\meta{first vector}|minus|\meta{second vector}|to|\meta{first macro}|and|\meta{second macro} +% \item |\DirOfvect|\meta{vector}|to|\meta{versor macro} +% \item |\ModAndDirOfVect|\meta{vector}|to|\meta{1st macro}|and|\meta{2nd macro} +% \item |\DistanceAndDirOfVect|\meta{first vector}|minus|\meta{second vector}|to|\meta{1st macro}|and|\meta{2nd macro} % \item |\XpartOfVect|\meta{vector}|to|\meta{macro} % \item |\YpartOfVect|\meta{vector}|to|\meta{macro} -% \item |\DirFromAngle|\meta{angle}|to|\meta{macro} -% \item |\ScaleVect|\meta{vector}|by|\meta{scaling factor}|to|\meta{macro} -% \item |\ConjVect|\meta{vector}|to|\meta{conjugate vector} -% \item |\SubVect|\meta{first vector}|from|\meta{second vector}|to|\meta{vector} -% \item |\AddVect|\meta{first vector}|and|\meta{second vector}|to|\meta{vector} -% \item |\MultVect|\meta{first vector}|by|\meta{second vector}|to|\meta{vector} -% \item |\MultVect|\meta{first vector}|by*|\meta{second vector}|to|\meta{vector} -% \item |\DivVect|\meta{first vector}|by|\meta{second vector}|to|\meta{vector} +% \item |\DirFromAngle|\meta{angle}|to|\meta{versor macro} +% \item |\ArgOfVect|\meta{vector}|to|\meta{angle macro} +% \item |\ScaleVect|\meta{vector}|by|\meta{scaling factor}|to|\meta{vector macro} +% \item |\ConjVect|\meta{vector}|to|\meta{conjugate vector macro} +% \item |\SubVect|\meta{first vector}|from|\meta{second vector}|to|\meta{vector macro} +% \item |\AddVect|\meta{first vector}|and|\meta{second vector}|to|\meta{vector macro} +% \item |\MultVect|\meta{first vector}|by|\meta{second vector}|to|\meta{vector macro} +% \item |\MultVect|\meta{first vector}|by*|\meta{second vector}|to|\meta{vector macro} +% \item |\DivVect|\meta{first vector}|by|\meta{second vector}|to|\meta{vector macro} % \end{itemize}} % -% \item General curves can be drawn with the |pict2e| macro |\curve| but it requires -% the specification of the Bézier third order spline control points; sometimes it's -% better to be very specific with the control points and there is no other means to -% do a decent graph; sometimes the curves to be drawn are not so tricky and a -% general set of macros can be defined so as to compute the control points, while -% letting the user specify only the nodes through which the curve must pass, and the -% tangent direction of the curve in such nodes. This macro is |\Curve| and must be -% followed by an ``unlimited" sequence of node-direction coordinates as a quadruple -% defined as +% \item General curves can be drawn with the |pict2e| macro |\curve| but it +% requires the specification of the Bézier third order spline control points; +% sometimes it's better to be very specific with the control points and there +% is no other means to do a decent graph; sometimes the curves to be drawn +% are not so tricky and a general set of macros can be defined so as to compute +% the control points, while letting the user specify only the nodes through +% which the curve must pass, and the tangent direction of the curve in such +% nodes. This macro is |\Curve| and must be followed by an ``unlimited'' +% sequence of node-direction coordinates as a quadruple defined as %\[ % \texttt{(}\meta{node coordinates}\texttt{)<}\meta{direction vector}\texttt{>} %\] @@ -460,15 +491,14 @@ and the derived files curve2e.sty and curve2e.pdf. %\[ % \texttt{...(...)<...>[}\meta{new direction vector}\texttt{](...)<...>...} %\] -% The |\Curve| macro does not (still) have facilities for cycling the path, that is -% to close the path from the last specified node-direction to the first specified -% node-direction. -% The tangent direction need not be specified with a unit vector, although only its -% direction is relevant; the scaling of the specified direction vector to a unit -% vector is performed by the macro itself. Therefore one cannot specify the fine -% tuning of the curve convexity as it can be done with other programs, as for -% example with METAFONT or the |pgf/tikz| package and environment. -% See figure~\ref{fig:curve} for an example. +% The |\Curve| macro does not (still) have facilities for cycling the path, +% that is to close the path from the last specified node-direction to the first +% specified node-direction. The tangent direction need not be specified with +% a unit vector, although only its direction is relevant; the scaling of the +% specified direction vector to a unit vector is performed by the macro itself. +% Therefore one cannot specify the fine tuning of the curve convexity as it +% can be done with other programs, as for example with \MF\ or the |pgf/tikz| +% package and environment. See figure~\ref{fig:curve} for an example. % \end{enumerate} % \begin{figure} % \begin{minipage}{.48\textwidth} @@ -483,11 +513,11 @@ and the derived files curve2e.sty and curve2e.pdf. % \end{verbatim} % \end{minipage} % \hfill -% \begin{minipage}{.48\textwidth}\raggedleft -% \unitlength=8mm +% \begin{minipage}{.48\textwidth}\raggedleft\relax +% \unitlength=8mm\relax % \begin{picture}(5,5) -% \put(0,0){\framebox(5,5){}}\thicklines\roundcap -% \Curve(2.5,0)<1,1>(5,3.5)<0,1>(2.5,3.5)<-0.5,-1.2>[-0.5,1.2](0,3.5)<0,-1>(2.5,0)<1,-1> +% \put(0,0.5){\put(0,0){\framebox(5,5){}}\thicklines\roundcap +% \Curve(2.5,0)<1,1>(5,3.5)<0,1>(2.5,3.5)<-0.5,-1.2>[-0.5,1.2](0,3.5)<0,-1>(2.5,0)<1,-1>} % \end{picture} % \end{minipage} % \caption{A heart shaped curve with cusps drawn with \texttt{\string\Curve}} @@ -504,21 +534,22 @@ and the derived files curve2e.sty and curve2e.pdf. % package is a simple attempt to follow the initial path while extending the drawing % facilities; but Till Tantau's |pgf| package has gone much farther. % -% \section{Notice} +% \section{Remark} % There are other packages in the \textsc{ctan} archives that deal with tracing -% curves of various kinds. |PSTricks| and |tikz/pgf| are the most powerful ones. But -% there are also the package |curves| that is intended to draw almost anything by -% using little dots or other symbols partially superimposed to one another. It used -% only quadratic Bézier curves and the curve tracing is eased by specifying only the -% curve nodes, without specifying the control nodes; with a suitable option to the -% package call it is possible to reduce the memory usage by using short straight -% segments drawn with the PostScript facilities offered by the |dvips| driver. +% curves of various kinds. |PSTricks| and |tikz/pgf| are the most powerful ones. +% But there are also the package |curves| that is intended to draw almost +% anything by using little dots or other symbols partially superimposed to one +% another. It used only quadratic Bézier curves and the curve tracing is eased +% by specifying only the curve nodes, without specifying the control nodes; +% with a suitable option to the package call it is possible to reduce the +% memory usage by using short straight segments drawn with the PostScript +% facilities offered by the |dvips| driver. % % Another package |ebezier| performs about the same as |curve2e| but draws its % Bézier curves by using little dots partially superimposed to one another. The -% documentation is quite interesting but since it explains very clearly what exactly -% are the Bézier splines, it appears that |ebezier| should be used only for dvi -% output without recourse to PostScript machinery. +% documentation is quite interesting but since it explains very clearly what +% exactly are the Bézier splines, it appears that |ebezier| should be used only +% for dvi output without recourse to PostScript machinery. % % \section{Acknowledgements} % I wish to express my deepest thanks to Michel Goosens who spotted some errors @@ -527,18 +558,18 @@ and the derived files curve2e.sty and curve2e.pdf. % Josef Tkadlec and the author collaborated extensively in order to make a better % real long division so as to get the fractional part and to avoid as much as % possible any numeric overflow; many Josef's ideas are incorporated in the macro -% that is implemented in this package, although the macro used by Josef is slightly -% different from this one. Both versions aim at a better accuracy and at widening -% the operand ranges. Some of the work we did together was incorporated in |pict2e| 2009. +% that is implemented in this package, although the macro used by Josef is +% slightly different from this one. Both versions aim at a better accuracy and +% at widening the operand ranges. % % Daniele Degiorgi spotted a fault in the kernel definition of |\linethickness| % that heavily influenced also |curve2e|; see below. % -% Thanks also to Jin-Hwan Cho and Juho Lee who suggested a small but crucial modification -% in order to have \texttt{curve2e} work smoothly also with XeTeX (XeLaTeX). -% Actually if version 0.2x or later, dated 2009/08/05 or later, of |pict2e| is being used, -% such modification is not necessary, but it's true that it becomes imperative if older -% versions are used. +% Thanks also to Jin-Hwan Cho and Juho Lee who suggested a small but crucial +% modification in order to have \texttt{curve2e} work smoothly also with XeTeX +% (XeLaTeX). Actually if version 0.2x or later, dated 2009/08/05 or later, of +% |pict2e| is being used, such modification is not necessary, but it's true +% that it becomes imperative if older versions are used. % % \StopEventually{% % \begin{thebibliography}{9} @@ -556,13 +587,12 @@ and the derived files curve2e.sty and curve2e.pdf. % make sure that a sufficiently recent version is used. % \begin{macrocode} \RequirePackage{color} -\RequirePackageWithOptions{pict2e}[2011/04/01] +\RequirePackageWithOptions{pict2e}[2014/01/01] % \end{macrocode} % -% The next macros are just for debugging. With the \texttt{trace} package it +% The next macros are just for debugging. With the \texttt{tracing} package it % would probably be better to define other macros, but this is not for the -% developers, not the users. - +% users, but for the developers. % \begin{macrocode} \def\TRON{\tracingcommands\tw@ \tracingmacros\tw@}% \def\TROF{\tracingcommands\z@ \tracingmacros\z@}% @@ -590,9 +620,9 @@ and the derived files curve2e.sty and curve2e.pdf. % default whole width of thick lines is 0,8pt, but this is specified in the % kernel of \LaTeX\ and\slash or in \texttt{pict2e}. On the opposite it is % necessary to redefine |\linethickness| because the \LaTeX\ kernel global -% definition does not hide the space after the closed brace when you enter something -% such as |\linethickness{1mm}| followed by a space or a new line.\footnote{Thanks -% to Daniele Degiorgi (\texttt{degiorgi@inf.ethz.ch}).} +% definition does not hide the space after the closed brace when you enter +% something such as |\linethickness{1mm}| followed by a space or a new line. +%\footnote{Thanks to Daniele Degiorgi (\texttt{degiorgi@inf.ethz.ch}).} % \begin{macrocode} \gdef\linethickness#1{\@wholewidth#1\@halfwidth.5\@wholewidth\ignorespaces}% \newcommand\defaultlinethickness[1]{\defaultlinewidth=#1\relax @@ -612,15 +642,15 @@ and the derived files curve2e.sty and curve2e.pdf. % coordinate point. The two arguments define the horizontal and the % vertical component respectively. % \begin{macrocode} -\def\LIne(#1,#2){\pIIe@moveto\z@\z@ - \pIIe@lineto{#1\unitlength}{#2\unitlength}\pIIe@strokeGraph}% +\def\LIne(#1,#2){\moveto(0,0) + \pIIe@lineto{#1\unitlength}{#2\unitlength}\strokepath}% % \end{macrocode} % % A similar macro |\segment| operates between two explicit points with absolute % coordinates, instead of relative to the position specified by a |\put| % command; it resorts to the |\polyline| macro that is to be defined in a while. -% The |\@killglue|command might be unnecessary, but it does not harm; it eliminates -% any explicit or implicit spacing that might precede this command. +% The |\@killglue| command might be unnecessary, but it does not harm; it +% eliminates any explicit or implicit spacing that might precede this command. % \begin{macrocode} \def\segment(#1)(#2){\@killglue\polyline(#1)(#2)}% % \end{macrocode} @@ -644,7 +674,7 @@ and the derived files curve2e.sty and curve2e.pdf. % \end{macrocode} % but as soon as it is verified that the line length is not negative, things % change remarkably; in facts the machinery for complex numbers is invoked. -% This makes the code muche simpler, not necessarily more efficient; nevertheless +% This makes the code much simpler, not necessarily more efficient; nevertheless % |\DirOfVect| takes the only macro argument (that actually contains a comma % separated pair of fractional numbers) and copies it to |\Dir@line| (an % arbitrarily named control sequence) after re-normalizing to unit magnitude; @@ -667,7 +697,7 @@ and the derived files curve2e.sty and curve2e.pdf. \@linelen=\sc@lelen\@linelen \fi % \end{macrocode} -% Of course, it the line is vertical this division must not take place. +% Of course, if the line is vertical this division must not take place. % Finally the \texttt{moveto}, \texttt{lineto} and \texttt{stroke} language % keywords are invoked by means of the internal \texttt{pict2e} commands in % order to draw the line. Notice that even vertical lines are drawn with the @@ -677,31 +707,32 @@ and the derived files curve2e.sty and curve2e.pdf. % any when lines are drawn by the driver that drives the output to a visible % document form, not by \TeX\ the program. % \begin{macrocode} - \pIIe@moveto\z@\z@ + \moveto(0,0) \pIIe@lineto{\d@mX\@linelen}{\d@mY\@linelen}% - \pIIe@strokeGraph + \strokepath \fi \endgroup\ignorespaces}% % \end{macrocode} -% The new definition of the command |\line|, besides tha ease with which is +% The new definition of the command |\line|, besides the ease with which is % readable, does not do different things from the definition of |pict2e| 2009, but -% it did preform in a better way whith the 2004 version that was limited to integer -% direction coefficients up to 999 in magnitude. -% -% Another usefull line-type macro creates a dashed line between two given points -% with a dash length that must be specified; actually the specified dash length is a -% desired dash length; the actual length is computed by integer division between -% the distance of the given points and the desired dash length; this integer is -% tested in order to see if it's odd; if it's not, it is increased by one. Then the -% actual dash length is obtained by dividing the above distance by this odd number. +% it did preform in a better way whith the 2004 version that was limited to +% integer direction coefficients up to 999 in magnitude. +% +% Another useful line-type macro creates a dashed line between two given points +% with a dash length that must be specified; actually the specified dash length +% is a desired dash length; the actual length is computed by integer division +% between the distance of the given points and the desired dash length; this +% integer is tested in order to see if it's odd; if it's not, it is increased by +% one. Then the actual dash length is obtained by dividing the above distance by +% this odd number. % Another vector is created from $P_1-P_0$ by dividing it by the magic odd number; % then it is multiplied by two in order to have the increment from one dash to the -% next, and finally the number of patterns is obtained by integer dividing the magic -% odd number by 2 and increasing it by 1. A simple |\multiput| completes the job, -% but in order to use the various vectors and numbers within a group and to throw -% the result outside the group while restoring all the intermediate counters and -% registers, a service macro is created with an expanded definition and then this -% service macro is executed. +% next, and finally the number of patterns is obtained by integer dividing the +% magic odd number by 2 and increasing it by 1. A simple |\multiput| completes the +% job, but in order to use the various vectors and numbers within a group and to +% throw the result outside the group while restoring all the intermediate counters +% and registers, a service macro is created with an expanded definition and then +% this service macro is executed. % \begin{macrocode} \ifx\Dline\undefined \def\Dline(#1,#2)(#3,#4)#5{% @@ -712,7 +743,7 @@ and the derived files curve2e.sty and curve2e.pdf. \SubVect\V@ttA from\V@ttB to\V@ttC \ModOfVect\V@ttC to\DlineMod \DividE\DlineMod\p@ by#5\p@ to\NumD - \NumA\expandafter\Integer\NumD.?? + \NumA\expandafter\Integer\NumD?? \ifodd\NumA\else\advance\NumA\@ne\fi \NumB=\NumA \divide\NumB\tw@ \DividE\DlineMod\p@ by\NumA\p@ to\D@shMod @@ -817,7 +848,7 @@ and the derived files curve2e.sty and curve2e.pdf. \pIIe@concat\@xdim\@ydim{-\@ydim}\@xdim{\@xnum\@linelen}{\@ynum\@linelen}% \@linelen\z@ \pIIe@vector - \pIIe@fillGraph + \fillpath % \end{macrocode} % Now we can restore the stem length that must be shortened by the dimension of % the arrow; examining the documentation of \texttt{pict2e} we discover that @@ -832,9 +863,9 @@ and the derived files curve2e.sty and curve2e.pdf. \@tdA=\pIIe@FAL\@tdA \advance\@linelen-\@tdA \ifdim\@linelen>\z@ - \pIIe@moveto\z@\z@ + \moveto(0,0) \pIIe@lineto{\@xnum\@linelen}{\@ynum\@linelen}% - \pIIe@strokeGraph\fi + \strokepath\fi \endgroup} % \end{macrocode} % @@ -842,8 +873,8 @@ and the derived files curve2e.sty and curve2e.pdf. % or the $l_x$ length component; the way the new |\vector| macro works does not % actually require this specification, because \TeX\ can compute the vector % length, provided the two direction components are exactly the horizontal and -% vertical vector components. If the horizontal component is zero, the actual length -% must be specified as the vertical component. +% vertical vector components. If the horizontal component is zero, the actual +% length% must be specified as the vertical component. % \begin{macrocode} \def\Vector(#1,#2){% \ifdim#1\p@=\z@\vector(#1,#2){#2} @@ -892,7 +923,7 @@ and the derived files curve2e.sty and curve2e.pdf. % macros.}\label{fig:vectors} % \end{figure} % -% \subsubsection{Polygonal lines} +% \subsubsection{Polylines} % We now define the polygonal line macro; its syntax is very simple % \begin{flushleft} % \cs{polygonal}\texttt{(}$P_0$\texttt{)(}$P_1$\texttt{)(}$P_2$)% @@ -916,20 +947,22 @@ and the derived files curve2e.sty and curve2e.pdf. % not necessarily is put in position through a |\put| command that provides to % eliminate any spurious spaces preceding this command. % -% Remember: |\polyline| has been incorporated into |pict2e| 2009, but we redefine it so as to allow an optional argument to allow the line join specification. +% Remember: |\polyline| has been incorporated into |pict2e| 2009, but we +% redefine it so as to allow an optional argument to allow the line join +% specification. % -% In order to allow a specification for the joints of the various segements of +% In order to allow a specification for the joints of the various segments of % a polygonal line it is necessary to allow for an optional parameter; the default % join is the bevel join. % \begin{macrocode} -\providecommand*\polyline[1][\beveljoin]{\p@lylin@[#1]} +\renewcommand*\polyline[1][\beveljoin]{\p@lylin@[#1]} \def\p@lylin@[#1](#2){\@killglue#1\GetCoord(#2)\d@mX\d@mY \pIIe@moveto{\d@mX\unitlength}{\d@mY\unitlength}% \@ifnextchar\lp@r{\p@lyline}{% \PackageWarning{curve2e}% - {Polygonal lines require at least two vertices!\MessageBreak - Control your polygonal line specification\MessageBreak}% + {Polylines require at least two vertices!\MessageBreak + Control your polyline specification\MessageBreak}% \ignorespaces}} % \end{macrocode} @@ -940,7 +973,7 @@ and the derived files curve2e.sty and curve2e.pdf. % \begin{macrocode} \def\p@lyline(#1){\GetCoord(#1)\d@mX\d@mY \pIIe@lineto{\d@mX\unitlength}{\d@mY\unitlength}% - \@ifnextchar\lp@r{\p@lyline}{\pIIe@strokeGraph\ignorespaces}} + \@ifnextchar\lp@r{\p@lyline}{\strokepath\ignorespaces}} % \end{macrocode} % % \subsubsection{The red service grid} @@ -991,39 +1024,40 @@ and the derived files curve2e.sty and curve2e.pdf. % It must take care of the signs, so that it examines the operand signs and % determines the result sign separately conserving this computed sign in the % macro |\segno|; this done, we are sure that both operands are or are -% made positive; should the -% numerator be zero it directly issues the zero quotient; should the -% denominator be zero it outputs ``infinity'' (|\maxdimen| in points), that is -% the maximum allowable length measured in points that \TeX\ can deal with. +% made positive; should the numerator be zero it directly issues the zero +% quotient; should the denominator be zero it outputs +% ``infinity'' (|\maxdimen| in points), that is the maximum allowable length +% measured in points that \TeX\ can deal with. % Since the result is assigned a value, the calling statement must pass as the % third argument either a control sequence or an active character. Of course the % first operand is the dividend, the second the divisor and the third the % quotient. % -% Since |curve2e| is supposed to be an extension of |pic2e| and this macro package -% already contains a division maro, we do not define any other division macro; -% nevetheless, since the macro in |pic2e| may not be so efficient as it might be -% if the |e-tex| extensions of the interpreter program were available, here we -% check and eventually provide a more efficient macro. The latter exploits the -% scaling mechanism embedded in |pdftex| since 2007, if the extended mode is +% Since |curve2e| is supposed to be an extension of |pict2e| and this macro +%package already contains a division macro, we do not define any other division +% macro; nevertheless, since the macro in |pict2e| may not be so efficient as it +% might be if the |e-tex| extensions of the interpreter program were available, +% here we check and eventually provide a more efficient macro. The latter exploits +% the scaling mechanism embedded in |pdftex| since 2007, if the extended mode is % enabled, that is used to scale a dimension by a fraction: $L\times N/D$, where % $L$ is a dimension, and $N$ and $D$ are the numerator an denominator of the % scaling factor; these might be integers, but it's better they represent the % numbers of scaled points another two dimensions correspond to, in the philosophy -% that floating point numbers are represented by the measures of lengths in points. +% that floating point numbers are represented by the measures of lengths in +% points. % % Therefore first we test if the macro is already defined: % \begin{macrocode} -\ifx\DividE\undefined +\ifdefined\dimexpr % \end{macrocode} -%then we test if the extended mode exists and/or is enabled: +% then we test if the extended mode exists and/or is enabled: % \begin{macrocode} -\ifx\dimexpr\undefined\else + \unless\ifdefined\DividE % \end{macrocode} -% Notice that |\dimexpr| is the specific extended mode control sequence we are going -% to use in order to perform our task; if the interpeter program is too old and/or -% it is a recent version, but it was compiled without activating the extended mode, -% the macro |\dimexpr| is undefined. +% Notice that |\dimexpr| is the specific extended mode control sequence we are +% going to use in order to perform our task; if the interpreter program is too +% old and/or it is a recent version, but it was compiled without activating the +% extended mode, the macro |\dimexpr| is undefined. % % The macro, creates a group where the names of two counters and a % dimensional register are defined; the numbers of these integer and dimension @@ -1033,51 +1067,75 @@ and the derived files curve2e.sty and curve2e.pdf. % does not damage the other macros; we just have to use a dirty trick to throw % the result beyond the end-group command. % -% The efficiency of this macro is contained in the extended command |\dimexpr|; both -% the |\@DimA| and |\Num| registers are program words of 32\,bits; the result is -% stored into an internal register of 64\,bits; the final division by a factor -% stored into a register of 32 bits, so that in terms of scaled points a division by -% 1\,pt = $1\times 2^{16}$, scales down the result by 16 bits, and if the total +% The efficiency of this macro is contained in the extended command |\dimexpr|; +% both the |\@DimA| and |\Num| registers are program words of 32\,bits; the result +% is stored into an internal register of 64\,bits; the final division by a factor +% stored into a register of 32 bits, so that in terms of scaled points a division +% by 1\,pt = $1\times 2^{16}$, scales down the result by 16 bits, and if the total % length of the result is smaller than $2^{30}$, the result can be correctly % assigned to a dimension register. In any other case the extended features imply -% suitable error messages end the termination of the program. During the division a -% scaling down by 16 bits, the result is not simply truncated, but it is rounded to -% the nearest integer (in scaled points) +% suitable error messages end the termination of the program. During the division +% a scaling down by 16 bits, the result is not simply truncated, but it is rounded +% to the nearest integer (in scaled points). The first two operands are lengths +% and the third is a macro. % % \begin{macrocode} - \def\DividE#1by#2to#3{% - \begingroup + \def\DividE#1by#2to#3{\bgroup \countdef\Num2254\relax \countdef\Den2252\relax \dimendef\@DimA 2254 \Num=\p@ \@DimA=#2\relax \Den=\@DimA \ifnum\Den=\z@ - \edef\x{\noexpand\endgroup\noexpand\def\noexpand#3{\strip@pt\maxdimen}}% + \edef\x{\noexpand\endgroup\noexpand\def\noexpand#3{\strip@pt\maxdimen}}% \else - \@DimA=#1\relax - \@DimA=\dimexpr\@DimA*\Num/\Den\relax - \edef\x{\noexpand\endgroup\noexpand\def\noexpand#3{\strip@pt\@DimA}}% + \@DimA=#1\relax + \@DimA=\dimexpr\@DimA*\Num/\Den\relax + \edef\x{\noexpand\egroup\noexpand\def\noexpand#3{\strip@pt\@DimA}}% \fi - \x} + \x\ignorespaces}% + \fi % \end{macrocode} +% +% We need a similar macro to divide two fractional or integer numbers, +% not dimensions, and produce a macro that contains the fractional result. % \begin{macrocode} -\fi\fi + \unless\ifdefined\DivideFN + \def\DivideFN#1by#2to#3{\DividE#1\p@ by#2\p@ to#3}% + \fi % \end{macrocode} % -% The next two macros are one of the myriad variants of the dirty trick used by -% Knuth for separating a measure from its units that \textit{must} be points, -% ``\texttt{pt}''. One has to call |\Numero| with a control sequence and a -% dimension; the dimension value in points is assigned to the control sequence. +% We do the same in order to multiply two integer o fractional numbers held +% in the first two arguments and the third argument is a definable token that +% will hold the result of multiplication in the form of a fractional number, +% possibly with a non null fractional part; a null fractional part is +% eliminated by \verb|strip@pt|. % \begin{macrocode} -\ifx\undefined\@Numero% - {\let\cc\catcode \cc`p=12\cc`t=12\gdef\@Numero#1pt{#1}}% + \unless\ifdefined\MultiplY + \def\MultiplY#1by#2to#3{\bgroup + \dimendef\@DimA 2254 \dimendef\@DimB2255 + \@DimA=#1\p@\relax \@DimB=#2\p@\relax + \@DimA=\dimexpr\@DimA*\@DimB/\p@\relax + \edef\x{\noexpand\egroup\noexpand\def\noexpand#3{\strip@pt\@DimA}}% + \x\ignorespaces}% + \fi \fi -\ifx\undefined\Numero - \def\Numero#1#2{\dimen254#2\relax - \edef#1{\expandafter\@Numero\the\dimen254}\ignorespaces}% +% \end{macrocode} + +% The next macro uses the \verb|\strip@pt| \LaTeX\ kernel macro to get the +% numerical value of a measure in points. One has to call |\Numero| with +% a control sequence and a dimension; the dimension value in points is +% assigned to the control sequence. +% \begin{macrocode} +\unless\ifdefined\Numero + \def\Numero#1#2{\dimen3254#2\relax + \edef#1{\strip@pt\dimen3254}\ignorespaces}% \fi % \end{macrocode} -% For both macros the |\ifx|\dots|\fi| constructs avoid messing up the -% definitions I have in several packages. +% The \verb|\ifdefined| primitive command is provided by the e-\TeX\ extension +% of the typesetting engine; the test does not create any hash table entry; +% it is a different way than the \verb|\ifx\csname ....\endcsname| test, +% because the latter first possibly creates a macro with meaning \verb|relax| +% then executes the test; therefore an undefined macro name is always defined +% to mean \verb|\relax|. % % \subsection{Trigonometric functions} % We now start with trigonometric functions. We define the macros |\SinOf|, @@ -1123,7 +1181,7 @@ and the derived files curve2e.sty and curve2e.pdf. % Computations are done with the help of counter |\I|, of the length |\@tdB|, % and the auxiliary control sequences |\Tan| and |\Cot| whose meaning is % transparent. The iterative process controlled by |\@whilenum| implements the -% (truncated) continued fraction expansion of the tangent function +% (truncated) continued fraction expansion of the tangent function. % \[ % \tan x = \frac{1}{\displaystyle \frac{1\mathstrut}{\displaystyle x} % -\frac{1}{\displaystyle \frac{3\mathstrut}{\displaystyle x} @@ -1134,7 +1192,7 @@ and the derived files curve2e.sty and curve2e.pdf. % -\cdots}}}}}} % \] % \begin{macrocode} -\countdef\I=254\def\Tan{0}\I=11\relax +\countdef\I=2546\def\Tan{0}\I=11\relax \@whilenum\I>\z@\do{% \@tdC=\Tan\p@ \@tdD=\I\@tdB \advance\@tdD-\@tdC \DividE\p@ by\@tdD to\Tan @@ -1158,7 +1216,7 @@ and the derived files curve2e.sty and curve2e.pdf. % auxiliary function is not defined any more, although its expansion keeps getting % executed so that the expanded result is thrown beyond the group end. % \begin{macrocode} -\def\SinOf#1to#2{\begingroup% +\def\SinOf#1to#2{\bgroup% \@tdA=#1\p@% \ifdim\@tdA>\z@% \@whiledim\@tdA>180\p@\do{\advance\@tdA -360\p@}% @@ -1193,15 +1251,15 @@ and the derived files curve2e.sty and curve2e.pdf. \fi \fi \fi -\edef\endSinOf{\noexpand\endgroup +\edef\endSinOf{\noexpand\egroup \noexpand\def\noexpand#2{\@tempA}\noexpand\ignorespaces}% \endSinOf}% % \end{macrocode} % -% For the computation of the cosine we behave in a similar way using also the identical -% trick for throwing the result beyond the group end. +% For the computation of the cosine we behave in a similar way using also the +% identical trick for throwing the result beyond the group end. % \begin{macrocode} -\def\CosOf#1to#2{\begingroup% +\def\CosOf#1to#2{\bgroup% \@tdA=#1\p@% \ifdim\@tdA>\z@% \@whiledim\@tdA>360\p@\do{\advance\@tdA -360\p@}% @@ -1238,7 +1296,7 @@ and the derived files curve2e.sty and curve2e.pdf. \fi \fi \fi -\edef\endCosOf{\noexpand\endgroup +\edef\endCosOf{\noexpand\egroup \noexpand\def\noexpand#2{\@tempA}\noexpand\ignorespaces}% \endCosOf}% % \end{macrocode} @@ -1248,7 +1306,7 @@ and the derived files curve2e.sty and curve2e.pdf. % multiples of $90^\circ$ we assign the result a \TeX\ infinity value, that is % the maximum a dimension can be. % \begin{macrocode} -\def\TanOf#1to#2{\begingroup% +\def\TanOf#1to#2{\bgroup% \@tdA=#1\p@% \ifdim\@tdA>90\p@% \@whiledim\@tdA>90\p@\do{\advance\@tdA -180\p@}% @@ -1277,7 +1335,7 @@ and the derived files curve2e.sty and curve2e.pdf. \fi \fi \fi -\edef\endTanOf{\noexpand\endgroup +\edef\endTanOf{\noexpand\egroup \noexpand\def\noexpand#2{\@tempA}\noexpand\ignorespaces}% \endTanOf}% % \end{macrocode} @@ -1390,7 +1448,7 @@ and the derived files curve2e.sty and curve2e.pdf. % \begin{macrocode} \def\DirOfVect#1to#2{\GetCoord(#1)\t@X\t@Y \ModOfVect#1to\@tempa -\ifdim\@tempdimc=\z@\else +\unless\ifdim\@tempdimc=\z@ \DividE\t@X\p@ by\@tempdimc to\t@X \DividE\t@Y\p@ by\@tempdimc to\t@Y \fi @@ -1442,6 +1500,195 @@ and the derived files curve2e.sty and curve2e.pdf. \MakeVectorFrom\t@X\t@Y to#2\ignorespaces}% % \end{macrocode} % +% As of today the anomaly (angle) of a complex number may not be necessary, but +% it might become useful in the future; therefore with macro \verb|\ArgOfVect| +% we calculate the four quadrant arctangent (in degrees) of the given vector +% taking into account the sings of the vector components. For the principal +% value of the arctangent we would like to use the continued fraction: +%\begin{equation} +%\arctan x = \cfrac{x}{1+ \cfrac{x^2}{3-x^2 + \cfrac{(3x)^2}{5-3x^2 + +% \cfrac{(5x)^2}{7-5x^2 + \cfrac{(7x)^2}{9-7x^2 + \ddots}}}}} +%\label{equ:arctan-fraz-cont} +%\end{equation} +% but after some testing we had to give up due to the slow convergence of +% continued fraction~\eqref{equ:arctan-fraz-cont}, strictly connected with +% the slow convergence of the McLaurin series from which it is derived. +% +% Waiting for a faster convergence continued fraction, we examined the +% parametric formula and its inverse: +%\begin{equation} +%\begin{subequations} +%\begin{aligned} +%\tan\theta &= \frac{2\tan(\theta/2))}{1 - \tan^2(\theta/2)}\\ +%\tan(\theta/2) &= \frac{\sqrt{\tan^2\theta +1}-1}{\tan\theta} +%\label{equ:tanfimezzi} +%\end{aligned} +%\end{subequations} +%\end{equation} +% If we count the times we use the above formula we can arrive at a point +% where we have to compute the arctangent of a very small value, where the +% arctangent and it argument are approximately equal, so that the angle value +% in radians is equal to its tangent; at that point we multiply by $2^n$, +% where $n$ is the number of bisections and transform the radians in degrees. +% The procedure is pretty good, even if is is very rudimental and based on an +% approximation; the fixed radix computation of the typesetting engine does +% not help, but we get pretty decent results, although we loose some accuracy +% that hopefully would not harm further computations. +% +% The results obtainable with equation~\eqref{equ:tanfimezzi} are possibly +% acceptable, but the square that must be computed in it tends to go in +% underflow if too many iterations are performed and the algorthim crashes; +% therefore it's virtually impossibile to get more than three correct digits +% after the decimal separator. +% +% It is probably better to refer to the Newton iterations for solving the +% equation: +%\begin{equation} +% \tan\theta -\tan\theta_\infty= 0 +%\end{equation} +% in the unknown $\theta$ given the value $t=\tan\theta_\infty$; see +% figure~\ref{fig:tangenti}. +% +%\begin{figure}\centering\unitlength=0.007\textwidth +%\begin{picture}(100,70) +%\put(10,63){\framebox(18,7){$y=\tan\theta$}} +%\put(30,63){\framebox(20,7){$t=\tan\theta_\infty$}} +%\put(0,0){\vector(1,0){100}}\put(100,3){\makebox(0,0)[br]{$\theta$}} +%\put(0,0){\vector(0,1){70}}\put(3,70){\makebox(0,0)[tl]{$y$}} +%\multiput(75,0)(0,5){14}{\line(0,1){2.5}}\put(77,2){\makebox(0,0)[bl]{$\pi/2$}} +%{\linethickness{1pt}\cbezier(0,0)(5,5)(55,40)(60,70)} +%\put(51,50){\circle*{2}} +%\multiput(51,0)(0,5){10}{\line(0,1){2.5}}\put(54,3){\makebox(0,0)[bl]{$\theta_{i-1}$}} +%\multiput(0,50)(5,0){10}{\line(1,0){2.5}}\put(3,53){\makebox(0,0)[bl]{$y_{i-1}$}} +%\put(0,20){\line(1,0){70}}\put(3,23){\makebox(0,0)[bl]{$t$}} +%\Line(34,20)(51,50) +%\put(34,20){\circle*{2}} +%\multiput(34,0)(0,5){4}{% +% \line(0,1){2.5}}\put(36,3){\makebox(0,0)[bl]{$\theta_{i}$}} +%\put(24,20){\circle*{2}} +%\multiput(24,0)(0,5){4}{\line(0,1){2.5}}\put(21,3){\makebox(0,0)[br]{$\theta_\infty$}} +%\end{picture} +%\caption{Newton method}\label{fig:tangenti} +%\end{figure} +% +% The iterative algorithm with Newton method implies the recurrence +%\begin{equation}\begin{subequations}\begin{aligned} +%y'_{i-1} &= \frac{\diff\tan(\theta_{i-1})}{\diff\theta} +% = \frac{1}{\cos^2\theta_{i-1}}\\ +%\theta_i &= \theta_{i-1} - y'_{i-1}(\tan \theta_{i-1} - t) +% =\theta_{i-1} - \cos^2 \theta_{i-1}(\tan \theta_{i-1} - t) +%\end{aligned} +%\label{equ:iterazione} +%\end{subequations}\end{equation} +% +% The algorithm starts with an initial value $\theta_0$, at each iteration +% for $i=1, 2, 3,\dots$ a new value of $\theta_i$ is computed from the data +% of the previous iteration $i-1$. When for a certain $i$, $\tan\theta_i$ +% is sufficiently close to $t$, the iterations may be stopped; since we +% already have the algorithms for computing both the tangent and the cosine; +% such Newton iterative method dos not pose any problems, especially if we +% use the properties of the trigonometric functions and we confine the +% computations to the first quadrant. +% \begin{macrocode} +\def\ArcTanOf#1to#2{\bgroup +\edef\@tF{#1}\@tdF=\@tF\p@ +\@tdE=57.295779\p@ +\ifdim\@tdF=\z@\def\@tX{0}\else +\edef\@tXX{1}% +\MultiplY57.295779by\@tXX to \@tX +\countdef\I 2323 \I=7\relax +\@whilenum\I>0\do{\TanOf\@tX to\@tG +\CosOf\@tX to \@tH +\edef\@tG{\strip@pt\dimexpr\@tG\p@-\@tdF\relax}% +\MultiplY\@tH by\@tH to\@tH +\MultiplY\@tH by\@tG to \@tH +\edef\@tXX{\strip@pt\dimexpr\@tXX\p@ - \@tH\p@\relax}% +\MultiplY57.295779by\@tXX to\@tX +\advance\I\m@ne}\fi +\edef\x{\egroup\noexpand\edef\noexpand#2{\@tX}}\x}% +% \end{macrocode} +% +% Now we have the algorithm to compute the arctangent of a number; and +% it should be relatively easy to compute the angle of a complex number. +% We have to pay attention that the algorithm to compute the arctangent +% does not care about the quadrant where the complex number lays in, and +% it yields the principal value of the arctan in the domain $\pi/2 < +% \theta \leq \pi/2$. with complex numbers we have just a sign change in +% their angle when the lay in the first or the fourth quadrants; while +% for the third and second quadrants we have to reflect the complex number +% to its opposite and in the result we have to add a ``flat angle'', that +% is 180°, since we are working in degrees. Even if mathematically it +% is undefined we decided to assign a null angle to a null complex number; +% possibly a warning message would be helpful, but for drawing purposes +% we think that the problem is irrelevant. +% +% \begin{macrocode} +\def\ArgOfVect#1to#2{\bgroup\GetCoord(#1){\t@X}{\t@Y}% +\def\s@gno{}\def\addflatt@ngle{0} +\ifdim\t@X\p@=\z@ + \ifdim\t@Y\p@=\z@ + \def\ArcTan{0}% + \else + \def\ArcTan{90}% + \ifdim\t@Y\p@<\z@\def\s@gno{-}\fi + \fi +\else + \ifdim\t@Y\p@=\z@ + \ifdim\t@X\p@<\z@ + \def\ArcTan{180}% + \else + \def\ArcTan{0}% + \fi + \else + \ifdim\t@X\p@<\z@% + \def\addflatt@ngle{180}% + \edef\t@X{\strip@pt\dimexpr-\t@X\p@}% + \edef\t@Y{\strip@pt\dimexpr-\t@Y\p@}% + \ifdim\t@Y\p@<\z@ + \def\s@gno{-}% + \edef\t@Y{-\t@Y}% + \fi + \fi + \DivideFN\t@Y by\t@X to \t@A + \ArcTanOf\t@A to\ArcTan + \fi +\fi +\edef\ArcTan{\unless\ifx\s@gno\empty\s@gno\fi\ArcTan}% +\unless\ifnum\addflatt@ngle=0\relax + \edef\ArcTan{% + \strip@pt\dimexpr\ArcTan\p@\ifx\s@gno\empty-\else+\fi + \addflatt@ngle\p@\relax}% +\fi +\edef\x{\noexpand\egroup\noexpand\edef\noexpand#2{\ArcTan}}% +\x\ignorespaces} +% \end{macrocode} +%^^A \begin{tabular}{ll} +%^^A 0 & \ArcTanOf 0 to\Res \Res\\ +%^^A 1 & \ArcTanOf 1 to\Res \Res\\ +%^^A 2 & \ArcTanOf 2 to\Res \Res\\ +%^^A 0.5 & \ArcTanOf 0.5 to\Res \Res\\ +%^^A 0.707 & \ArcTanOf 0.707 to\Res \Res\\ +%^^A \end{tabular} +%^^A +%^^A\bigskip +%^^A +%^^A \begin{tabular}{rl} +%^^A 0,0 & \ArgOfVect0,0to\Res \Res\\ +%^^A 1,0 & \ArgOfVect1,0to\Res \Res\\ +%^^A -1,0 & \ArgOfVect-1,0to\Res \Res\\ +%^^A 0,1 & \ArgOfVect0,1to\Res \Res\\ +%^^A 0,-1 & \ArgOfVect0,-1to\Res \Res\\ +%^^A 1,1 & \ArgOfVect1,1to\Res \Res\\ +%^^A 1,-1 & \ArgOfVect1,-1to\Res \Res\\ +% ^^A-1,1 & \ArgOfVect-1,1to\Res \Res\\ +% ^^A-1,-1 & \ArgOfVect-1,-1to\Res \Res\\ +%^^A \end{tabular} +% It is worth noting that the absolute error in these computations is lower +% than 0.001°, that is 0.000017\,rad; pretty satisfactory since the typesetting +% engines work in fixed radix notation with 16 fractional binary digits, and +% an error on the fifth fractional digit is almost the best it can be expected +% from this kind of arithmetics. +% % Sometimes it is necessary to scale a vector by an arbitrary real factor; this % implies scaling both the real and imaginary part of the input given vector. % \begin{macrocode} @@ -1573,7 +1820,7 @@ and the derived files curve2e.sty and curve2e.pdf. % macro, stroke the line and exit. % \begin{macrocode} \@@Arc -\pIIe@strokeGraph\ignorespaces}% +\strokepath\ignorespaces}% % \end{macrocode} % And the new macro |\@@Arc| starts with moving the drawing point to the first % point and does everything needed for tracing the requested arc, except @@ -1699,12 +1946,12 @@ and the derived files curve2e.sty and curve2e.pdf. % macro is almost identical to that of the plain arc; the beginning also is % quite similar. The central part is dedicated to the positioning of the arrow % tip and to the necessary calculations for determining the tip tilt and the -% reduction of the total arc length; pay attention that the arrow length, stored in -% |\@tdE| is a real length, while the radius stored in |\@Raggio| is just a multiple -% of the |\unitlength|, so that the division (that yields a good angular -% approximation to the arrow length as seen from the center of the arc) must be done -% with real lengths. The already defined |\@@Arc| macro actually draws the curved -% vector stem without stroking it. +% reduction of the total arc length; pay attention that the arrow length, stored +% in |\@tdE| is a real length, while the radius stored in |\@Raggio| is just +% a multiple of the |\unitlength|, so that the division (that yields a good +% angular approximation to the arrow length as seen from the center of the arc) +% must be done with real lengths. The already defined |\@@Arc| macro actually +% draws the curved vector stem without stroking it. % \begin{macrocode} \def\@VArc(#1)(#2){% \ifdim\@tdA>\z@ @@ -1741,7 +1988,7 @@ and the derived files curve2e.sty and curve2e.pdf. \advance\@tdA -\@tdE \Numero\@gradi\@tdA \CopyVect#1to\@Cent \GetCoord(\@pPun)\@pPunX\@pPunY \@@Arc -\pIIe@strokeGraph\ignorespaces}% +\strokepath\ignorespaces}% % \end{macrocode} % % The macro for the arc terminated with arrow tips at both ends is again very @@ -1797,7 +2044,7 @@ and the derived files curve2e.sty and curve2e.pdf. \AddVect\@Cent and\@V to\@pPun \GetCoord(\@pPun)\@pPunX\@pPunY \@@Arc -\pIIe@strokeGraph\ignorespaces}% +\strokepath\ignorespaces}% % \end{macrocode} % % It must be understood that the curved vectors, the above circular arcs @@ -1881,7 +2128,7 @@ and the derived files curve2e.sty and curve2e.pdf. % The next macro is the finishing one; it strokes the whole curve and closes the % group that was opened with |\StartCurve|. % \begin{macrocode} -\def\CurveFinish{\pIIe@strokeGraph\endgroup\ignorespaces}% +\def\CurveFinish{\strokepath\endgroup\ignorespaces}% % \end{macrocode} % % The ``real'' curve macro comes next; it is supposed to determine the control @@ -2114,7 +2361,7 @@ and the derived files curve2e.sty and curve2e.pdf. \def\@ChangeDir[#1]{\ChangeDir<#1>\@Curve} % \end{macrocode} % -% As a concluding remark, please notice the the |\Curve| macro is certainly the +% As a concluding remark, please notice that the |\Curve| macro is certainly the % most comfortable to use, but it is sort of frozen in its possibilities. The % user may certainly use the |\StartCurve|, |\CurveTo|, |\ChangeDir|, and % |\CurveFinish| for a more versatile set of drawing macros; evidently nobody |