[pstricks] Calculating curves in PsTricks
Denis Girou
Denis.Girou at idris.fr
Wed Jun 27 20:36:52 CEST 2001
>>>>> "Chris.Sangwin" == Chris Sangwin <sangwinc at for.mat.bham.ac.uk> writes:
Chris.Sangwin> I wish to typeset a smooth curve using
Chris.Sangwin> \pscurve...
Chris.Sangwin> To use this I need to calculate a list of co-ordinates
Chris.Sangwin> \pscurve(x_1,y_1)(x_2,y_2)...
Chris.Sangwin> Typically I might have a complicated curve that needs many such points. I
Chris.Sangwin> often typeset mathematical diagrams and need to *calculate* this list of
Chris.Sangwin> points - using something like the fp package. This is what I've done
Chris.Sangwin> below. I believe this sort of calculated typesetting of diagrams is very
Chris.Sangwin> much in the spirit of PST.
Absolutely.
Chris.Sangwin> I'd like LaTeX to perform the calculations (rather than generating a list
Chris.Sangwin> of points with external C code and importing them) to keep the file self
Chris.Sangwin> contained. I don't find the speed of the fp package too slow.
Chris.Sangwin> How do I connect the dots in the example below with a smooth curve (which
Chris.Sangwin> in this example happens to be an ellipse - but that would be cheating as
Chris.Sangwin> this is only an example of a more general problem!)
Ulrich Dirr gave you the way to follow. Here is your example rewritted using
external temporary files to store the data.
Just note that I made few other changes:
- You doesn't need to use fixed point real numbers in the multido loops,
are you use only integer values.
- I use two files. The problem is that you need to store consecutively
in a file the values to join, so you can't store in the same time the
symetrical part of the curve in one unique file. An alternative solution
is to use only one file but to split the loop in two ones (but this will be
of course slower).
- I suppress the "\psdots(\iX,\iY)(\iXX,\iY)" line, as this is easiest
to plot the points during curve drawing, using the "showpoints" parameter.
\documentclass[11pt]{article}
\usepackage{pst-plot} % From PSTricks
\usepackage{multido}
\usepackage[nomessages]{fp}
\newwrite\DataFileA
\newwrite\DataFileB
\newcommand{\DataFileNameA}{MyCurveA.dat}
\newcommand{\DataFileNameB}{MyCurveB.dat}
\pagestyle{empty}
\begin{document}
\def\Xpsz{6}
\def\Ypsz{6}
\newcommand{\PerCalc}[2]{%
\def\ix{#1}\def\iy{#2}%
\FPeval{\iY}{\Ypsz * \iy / (\iy + 1.0)} % Calculates Y-coordinate
\FPeval{\iX}{(\Ypsz - \iY)* \ix / \Xpsz} % Calculates X-coordinate
}% End perspective calculate
\begin{pspicture}(-6,0)(6,6)
\multido{\I=-6+1}{13}{\psline(0,6)(\I,0)}
% The horizontal perspective grid
\multido{\IR=0+1}{13}{%
\PerCalc{-6.0}{\IR}
\FPneg{\iXX}{\iX} % Exploits symmetry
\psline(\iXX,\iY)(\iX,\iY)} % End of the horizontal grid
\immediate\openout\DataFileA=\DataFileNameA
\immediate\openout\DataFileB=\DataFileNameB
\multido{\IRx=0+1}{90}{%
\FPeval{\Ry}{ (\IRx * \IRx) / 30.0 } % Defines the quadratic
\PerCalc{\IRx}{\Ry}
\immediate\write\DataFileA{(\iX,\iY)}
\FPneg{\iXX}{\iX} % Exploits symmetry - so we'll have to loose this...
\immediate\write\DataFileB{(\iXX,\iY)}}
\immediate\closeout\DataFileA
\immediate\closeout\DataFileB
\readdata{\MyCurve}{\DataFileNameA}
\dataplot[plotstyle=curve,showpoints=true]{\MyCurve}
\readdata{\MyCurve}{\DataFileNameB}
\dataplot[plotstyle=curve,showpoints=true]{\MyCurve}
\end{pspicture}
\end{document}
D.G.
More information about the PSTricks
mailing list