# [pstricks] Calculating curves in PsTricks

Chris Sangwin sangwinc at for.mat.bham.ac.uk
Wed Jun 27 14:10:36 CEST 2001

Dear all,

If this issue has been previously addressed then I apologize - I cannot
find solution posted on the web.

This is a problem I often encounter and the LaTeX file below is only a
typical example.

I wish to typeset a smooth curve using
\pscurve...

To use this I need to calculate a list of co-ordinates

\pscurve(x_1,y_1)(x_2,y_2)...

Typically I might have a complicated curve that needs many such points.  I
often typeset mathematical diagrams and need to *calculate* this list of
points - using something like the fp package.  This is what I've done
below.  I believe this sort of calculated typesetting of diagrams is very
much in the spirit of PST.

I'd like LaTeX to perform the calculations (rather than generating a list
of points with external C code and importing them) to keep the file self
contained.  I don't find the speed of the fp package too slow.

How do I connect the dots in the example below with a smooth curve (which
in this example happens to be an ellipse - but that would be cheating as
this is only an example of a more general problem!)

I would be very grateful for any suggestions.

Please note - if you've not used the multido and fp packages together
before you'll need to read the fp documentation first before it will
work...

Regards

Dr C. J. Sangwin
----------------------------------------------
School of Mathematics and Statistics
University of Birmingham
Birmingham, B15 2TT
United Kingdom
+44 121 414 6197
----------------------------------------------

\documentclass[11pt]{article}

\usepackage{graphicx}     % From LaTeX distribution
\usepackage{pst-all}      % From PSTricks
\usepackage{multido}      % From PSTricks
\usepackage[nomessages]{fp}

\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-coodinate
\FPeval\iX{(\Ypsz - \iY)* \ix / \Xpsz} % calculates X-coodinate
}% end perspective calculate

\pspicture(-6,0)(6,6)
\multido{\I=-6+1}{13}{\psline(0,6)(\I,0)}
% The horizontal perspective grid
\multido{\R=0.0+1.0}{13}{%
\PerCalc{-6.0}{\R}
\FPmul\iXX\iX{-1.0} % Exploits symmetry
\psline(\iXX,\iY)(\iX,\iY)
} % end of the horizontal grid

% some dots - I WANT TO CONNECT THESE!!!
\multido{\Rx=0.0+1.0}{90}{%
\FPeval\Ry{ (\Rx * \Rx) / 30.0 }  % Defines the quadratic
\PerCalc{\Rx}{\Ry}
\FPmul\iXX\iX{-1.0} % Exploits symmetry - so we'll have to loose this...
\psdots(\iX,\iY)(\iXX,\iY)
}
\endpspicture

\end{document}