summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/generic/mfpic/grafbase.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/generic/mfpic/grafbase.dtx')
-rw-r--r--Master/texmf-dist/source/generic/mfpic/grafbase.dtx193
1 files changed, 163 insertions, 30 deletions
diff --git a/Master/texmf-dist/source/generic/mfpic/grafbase.dtx b/Master/texmf-dist/source/generic/mfpic/grafbase.dtx
index 32d14a5b676..a309f242f6e 100644
--- a/Master/texmf-dist/source/generic/mfpic/grafbase.dtx
+++ b/Master/texmf-dist/source/generic/mfpic/grafbase.dtx
@@ -1,10 +1,10 @@
% \iffalse
-%%% File: grafbase.dtx
-%%% A part of mfpic 1.05 2010/06/10
-%%%
+% File: grafbase.dtx
+% A part of mfpic 1.06 2011/03/08
+%
% -------------------------------------------------------------------
%
-% Copyright 2002--2010, Daniel H. Luecking
+% Copyright 2002--2011, Daniel H. Luecking
%
% Mfpic may be distributed and/or modified under the conditions of the
% LaTeX Project Public License, either version 1.3b of this license or (at
@@ -19,7 +19,7 @@
%
%<*driver>
\ProvidesFile{grafbase.dtx}
- [2010/06/10 v1.05. Metafont/post macros to interface with mfpic.]%
+ [2011/03/08 v1.06. Metafont/post macros to interface with mfpic.]%
\documentclass{ltxdoc}
\usepackage{docmfp}
@@ -113,7 +113,7 @@
%</driver>
%\fi
%
-% \CheckSum{1453}
+% \CheckSum{1473}
% \CharacterTable
% {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
% 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
@@ -187,7 +187,7 @@ fi
boolean grafbase; grafbase := true;
string fileversion, filedate;
-fileversion := "1.05"; filedate := "2010/06/10";
+fileversion := "1.06"; filedate := "2011/02/25";
message " Loading grafbase macros, version " & fileversion & ", " &
filedate & ".";
@@ -236,7 +236,7 @@ def checkversions (expr g)=
fi
enddef;
-checkversions (105);
+checkversions (106);
% \end{macrocode}
%
@@ -672,11 +672,11 @@ vardef cmykgray (expr g) = cmyk(0,0,0,1 - snapto g) enddef;
% with three-way booleans (often containing nested booleans).
%
% For all three engines we require a definition of the color functions
-% \gbc{gray(g)}, \gbc{rgb(r,g,b)}, and \gbc{cmyk(c,m,y,k)}, conversion
-% functions \gbc{makegray(x)}, \gbc{makergb(x)}, amd \gbc{makecmyk(x)},
-% and the boolean \gbc{iscolor clr}. The first three have to return
-% numerics for \MF{}, colors for early \MP{}, and the associated color
-% type for recent \MP{}.
+% \gbc{gray(g)}, \gbc{rgb(r,g,b)}, and \gbc{cmyk(c,m,y,k)}, as well as
+% conversion functions \gbc{makegray(x)}, \gbc{makergb(x)}, and
+% \gbc{makecmyk(x)}, and the boolean \gbc{iscolor clr}. The first three
+% have to return numerics for \MF{}, colors for early \MP{}, and the
+% associated color type for recent \MP{}.
% \begin{macrocode}
%<*MP>
if has_cmyk :
@@ -729,7 +729,8 @@ if has_cmyk :
enddef;
vardef makergb primary clr =
colorchoice (clr)(rgbblack)(rgbgray(clr))(clr)
- (cmyktorgb(cyanpart clr, magentapart clr, yellowpart clr, blackpart clr))
+ (cmyktorgb(cyanpart clr, magentapart clr, yellowpart clr,
+ blackpart clr))
enddef;
vardef makegray primary clr =
colorchoice (clr)(grayscaleblack)(grayscalegray(clr))
@@ -4513,12 +4514,14 @@ enddef;
% Once we know what segment we are in, we determine the time by linear
% interpolation between the times corresponding to \gbc{ct} and
% \gbc{ct+1}. Note: in the \mfc{forever} loop, the exit must come before
-% the increment.
+% the increment. The function \gbc{inrange} is defined in
+% section~\ref{axes}. It checks if the third argument is between the
+% first two, or equal to one of them.
% \begin{macrocode}
vardef gettime (suffix arr, ct) (expr lngth) =
setnumeric (_gtl) emax (arr[ct], emin (arr[arr], lngth));
setsplit (_s) segment_split;
- forever: exitif ( (arr[ct] <= _gtl) and (_gtl <= arr[ct+1]) );
+ forever: exitif inrange (arr[ct], arr[ct+1]) (_gtl);
next ct;
endfor
if arr[ct] = arr[ct+1]: ct
@@ -4987,17 +4990,48 @@ vardef axisline.t = axisline.x shifted (0, yhigh) enddef;
vardef axis@# (expr len) = headpath (len, 0, 0) axisline@# enddef;
+% \end{macrocode}
+%
+% \DescribeRoutine{borderrect}
+% These are mostly for the simplification of \mfpic{} and readability of
+% code. The command \gbc{borderrect} produces the border of the picture
+% in graph coordinates, taking into account the four margins.
+%
+% \DescribeRoutine{between}
+% The boolean \gbc{between} checks if the last argument is strictly
+% between the first two (which must be in order).
+%
+% \DescribeRoutine{inrange}
+% The boolean \gbc{inrange} checks if the last argument is in the closed
+% interval determined by the first two (which must be in order).
+%
+% \DescribeRoutine{inbounds}
+% The boolean \gbc{inbounds} checks if the argument (a pair) is in
+% the closed border rectangle (\gbc{borderrect}). It is not yet used in
+% \grafbase{}, though it would seem it ought to be useful.
+% \begin{macrocode}
vardef borderrect =
rect((xlow,ylow),(xhigh,yhigh))
enddef;
+vardef between (expr A, B, X) = (A < X) and (X < B) enddef;
+vardef inrange (expr A, B, X) = (A <= X) and (X <= B) enddef;
+
vardef inbounds (expr Z) =
- (xpart Z >= xlow ) and (ypart Z >= ylow ) and
- (xpart Z <= xhigh) and (ypart Z <= yhigh)
+ inrange (xlow, xhigh) (xpart Z) and inrange (ylow, yhigh) (ypart Z)
enddef;
% \end{macrocode}
%
+% Possible binary relation versions. The last is just a reversal of the
+% order of the first. These are not yet used in \grafbase{}.
+% \begin{macrocode}
+tertiarydef X isbetween P = between (xpart P, ypart P, X) enddef;
+tertiarydef X isinrange P = inrange (xpart P, ypart P, X) enddef;
+tertiarydef P contains X = between (xpart P, ypart P, X) enddef;
+
+% \end{macrocode}
+%
% Tick marks can be on the inside or outside of a border axis,
% above or below any horizontal axes, left or right of any vertical axis
% or centered on any axis. The following numerics are merely used to
@@ -5216,7 +5250,7 @@ def plrvectorfield (expr len, rsp, tsp) (text fcn) (text cond) =
vardef _vf (expr r,t) = ((0,0)--(fcn)) shifted (r*dir t) enddef;
vardef _is_OK (expr r,t) =
save _X, _Y; _X := r*cosd t; _Y := r*sind t;
- (cond) and (_A < _X) and (_X < _B) and (_C < _Y) and (_Y < _D)
+ (cond) and between (_A, _B) (_X) and between (_C, _D) (_Y)
enddef;
mkplrvectorfield (len, rsp, tsp) (_vf, _is_OK);
enddef;
@@ -5385,7 +5419,7 @@ def getpolarbounds =
% \gbc{tmin}${} < \theta < {}$\gbc{tmax} includes the graph.
% \begin{macrocode}
rmin := 0;
- if (xneg < 0) and (xpos > 0) and (yneg < 0) and (ypos > 0):
+ if between (xneg, xpos) (0) and between (yneg, ypos) (0):
tmin := 0; tmax := 360;
elseif (p0 = origin): tmin := 0; tmax := 90;
elseif (p1 = origin): tmin := -90; tmax := 0;
@@ -5406,9 +5440,9 @@ def getpolarbounds =
% the following order: (1)~above or below, (2)~left or right, and (3)~one
% of the four corner regions.
% \begin{macrocode}
- if (xneg < 0) and (0 < xpos):
+ if between (xneg, xpos) (0):
rmin := emin (abs(yneg), abs(ypos));
- elseif (yneg < 0) and (0 < ypos):
+ elseif between (yneg, ypos) (0):
rmin := emin (abs(xneg), abs(xpos));
else:
rmin := min (r0, r1, r2, r3);
@@ -5596,8 +5630,10 @@ vardef anglefromto (expr u, v) =
enddef;
vardef cornerangle (expr A, B, C) =
- if (A = B) and (B = C) : 60
- elseif (A=B) or (A=C) : 90
+ if (A = B) or (A = C) :
+ if (B = C) : 60
+ else: 90
+ fi
else: anglefromto (B - A, C - A)
fi
enddef;
@@ -6834,14 +6870,14 @@ vardef pshcircle (expr disk, ctr, rad) =
if disk:
if rad >= 1 :
if rad > 1:
- GBerrmsg ("Impossible pseudohyperbolic circle.")
+ GBerrmsg ("Impossible radius of pseudohyperbolic circle.")
"The radius of a pseudohyperbolic circle can be at most 1.";
fi
circle ((0,0),1)
elseif abs(ctr) >= 1 :
if abs(ctr) > 1:
- GBerrmsg ("Impossible pseudohyperbolic circle.")
- "The center of a pseudohyperbolic circle must be in"
+ GBerrmsg ("Impossible center of pseudohyperbolic circle.")
+ "The center of a pseudohyperbolic circle must be in "
& "the unit disk.";
fi
onepointpath (true,ctr)
@@ -6861,7 +6897,7 @@ vardef pshcircle (expr disk, ctr, rad) =
elseif ypart ctr <= 0:
if ypart ctr < 0:
GBerrmsg ("Impossible pseudohyperbolic circle.")
- "The center of a pseudohyperbolic circle must be in"
+ "The center of a pseudohyperbolic circle must be in "
& "the upper half-plane.";
fi
onepointpath (true,ctr)
@@ -7112,8 +7148,7 @@ tolerancefactor := .02;
vardef mklevelset (expr sm, tens, X, Y, t, a, b, c, d) =
save _inside_;
vardef _inside_ (expr U, V) =
- inside_levelset (U, V) and (a < U) and (U < b)
- and (c < V) and (V < d)
+ inside_levelset (U, V) and between (a, b) (U) and between (c, d) (V)
enddef;
if not _inside_ (X, Y):
GBwarn "Invalid seed point for levelset.";
@@ -7175,6 +7210,104 @@ enddef;
% \end{macrocode}
%
+% Our next set of macros produce approximations to the solutions of
+% differential equations. While we could have several different macros
+% each using a different method (Euler, two-step Runge-Kutta, four-step
+% Runge-Kutta, etc.), our point of view is that we just want to draw a
+% reasonably accurate solution, so we only utilize one method: four-step
+% Runge-Kutta. The variations we allow are the following:
+% \begin{enumerate}
+% \item Drawing the graph of a one-dimensional differential
+% equation,
+% \[ \frac{dy}{dx} = g(x,y)\,.\]
+%
+% \item Drawing the trajectory of a two-dimensional differential
+% equation,
+% \[ \left( \frac{dx}{dt},\frac{dy}{dt} \right) =
+% (f(x,y,t), g(x,y,t))\,.\]
+% \end{enumerate}
+% The first of these is implemented using the second with $f(x,y,t) \equiv
+% 1$ and $g(x,y,t)$ not depending on $t$. The parameters passed include
+% the starting point, the step size, the number of steps and an expression
+% representing the right side of the equation.
+%
+% We do not use exactly the traditional Runge-Kutta method: we use the
+% Runge-Kutta algorithm, but with a variable step size. The time step
+% $\Delta t$ is chosen so that $|\mathbf{F}(x,y,t)|\Delta t$ equals the
+% given step size parameter, and thus the parameter passed is actually a
+% distance step. This makes drawing more stable, especially if the DE is
+% one that produces an infinite path in finite time.
+%
+% This modification is itself unstable if $|\mathbf{F}|$ is very
+% small (and impossible if it is zero), so we never use a $\Delta t$
+% larger than the given step size parameter $\Delta s$. That is, we
+% actually use $\Delta t = \Delta s/\max(1,|\mathbf{F}|)$.
+%
+% As with our other function-like paths, we offer two variants. The basic
+% version has a final text parameter which is the name of a pair-valued
+% function of a numeric (representing $t$) and a pair variable
+% (representing $x$ and $y$). The other version takes a text
+% parameter, which must be a pair-valued expression in \mfc{x}, \mfc{y}
+% and \mfc{t}. This parameter is copied into the definition text of a
+% function and then the first form is called with that function's name.
+%
+% Also like other function-like paths, we offer polygonal or smooth
+% versions controlled by a boolean argument, and the smooth versions make
+% use of a tension parameter.
+% \begin{macrocode}
+def RKIV (expr sm) = tRKIV (sm, default_tension)
+enddef;
+vardef tRKIV (expr sm, tens, zstart, ds, N) (text _RHS_) =
+ save _trj, _ztr, _dz, _ztmp, _ctm;
+ pair _trj[], % The trajectory
+ _ztr, % current point
+ _dz[], % array[4] of displacements
+ _ztmp; % current point for calculating velocity
+%
+ _trj := N+1; % ultimate size of _trj array
+ _trj1 := _ztr := zstart;
+ save _tt, % current time
+ _dt, % current time step
+ _th; % current time plus half a step
+ _tt := 0;
+ for _idx := 2 upto _trj:
+ _dt := ds/emax(1,abs(_RHS_(_tt,_ztr)));
+ _th := _tt + .5_dt;
+ _dz1 := _dt*_RHS_(_tt, _ztr); % displacement based on current point
+ _ztmp := _ztr + .5_dz1; % 1st midpoint
+ % use _th instead of twice calculating (_tt + .5_dt)
+ _dz2 := _dt*_RHS_(_th, _ztmp); % displacement based on 1st midpoint
+ _ztmp := _ztr + .5_dz2; % 2nd midpoint
+ _dz3 := _dt*_RHS_(_th, _ztmp); % displacement based on 2nd midpoint
+ _ztmp := _ztr + _dz3; % temporary end point
+ % get time for next loop now since we need it right away in next line:
+ _tt := _tt + _dt;
+ _dz4 := _dt*_RHS_(_tt, _ztmp); % displacement based on end point
+ % get next point
+ _ztr := _ztr + (_dz1 + 2_dz2 + 2_dz3 + _dz4)/6;
+ _trj[_idx] := _ztr;
+ endfor
+ mkpath (sm, tens, false, _trj)
+enddef;
+
+def xyRKIV (expr sm) = txyRKIV (sm, default_tension)
+enddef;
+vardef txyRKIV (expr sm, tens, zstart, ds, N) (text _RHS_) =
+ save _fgxy, __fgxy;
+ vardef __fgxy (expr t, x, y) = _RHS_ enddef;
+ vardef _fgxy (expr t, Z) = __fgxy(t, xpart Z, ypart Z) enddef;
+ tRKIV (sm, tens, zstart, ds, N) (_fgxy)
+enddef;
+
+def odeRKIV (expr sm) = todeRKIV (sm, default_tension)
+enddef;
+vardef todeRKIV (expr sm, tens, xstart, ystart, ds, N)
+(text _fxy) =
+ txyRKIV (sm, tens, (xstart, ystart), ds, N) ((1, _fxy))
+enddef;
+
+% \end{macrocode}
+%
% \section{Modification of Paths}\label{modification}
%
% \subsection{Closing a path}\label{closing}