[pstricks] Using the "psplot"
Chris Sangwin
sangwinc at for.mat.bham.ac.uk
Fri Nov 16 11:12:48 CET 2001
Dear Stephane,
I often use PSTricks to calculate mathematical functions, etc and then
plot them.
The LaTeX package `fp' is useful for performing calculations, and the
following example - very helpfuly supplied by DG a few months ago in reply
to a similar queary of my own - uses psplot. The image produced is a
quadratic equation (line 36) projected using single point
perspective. This *is* an ellipse - but using psellipse would have been
cheating wouldn't it!
The moral is - there is no need to write more than one piece of
code. LaTeX is capable of calculating without recourse to external
packages, such as Mathematica.
Regards
Chris
------ LaTeX Code follows --------------
\documentclass[11pt]{article}
\usepackage{pst-plot} % From PSTricks
\usepackage{multido}
\usepackage[nomessages]{fp}
\newwrite\DataFileA
\newcommand{\DataFileNameA}{MyCurveA.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
\multido{\IRx=-90+1}{181}{%
\FPeval{\Ry}{ (\IRx * \IRx) / 30.0 } % Defines the quadratic
\PerCalc{\IRx}{\Ry}
\immediate\write\DataFileA{(\iX,\iY)}
}
\immediate\closeout\DataFileA
\readdata{\MyCurve}{\DataFileNameA}
% \dataplot[plotstyle=curve,showpoints=true]{\MyCurve}
\dataplot[plotstyle=curve]{\MyCurve}
\end{pspicture}
\end{document}
More information about the PSTricks
mailing list