[pstricks] pscurve and psbezier and psplot...

Denis Girou Denis.Girou at idris.fr
Fri Nov 29 21:24:42 CET 2002


>>>>> "Cyrille.Piatecki" == Cyrille Piatecki <cyrille.piatecki at univ-orleans.fr> writes:

    Cyrille.Piatecki> Suppose you have had to work hard to construct a curve. Then sudenly you 
    Cyrille.Piatecki> discover that ther is a part, two part tree... of your curve that must 
    Cyrille.Piatecki> change of color or of style. Is it possible to define such a macro .

  No. I cannot imagine that it can be done in the general case. For instance,
you can built a special version of \psline which keep in memory the various
segments and allow to redraw them in a different way giving only the indice
of the segment. But do not hope to have such thing for a general function
plotted with \psplot... You must redraw explicitely the part of curve you
need.

    Cyrille.Piatecki> Secondly, I have to plot some function. I would be please to know. But in 
    Cyrille.Piatecki> postscript such function as exp(x^2) doesnot exist. Can I define a 
    Cyrille.Piatecki> postcript dictionary and pass it to psplot.

  You do not need to use a dictionary, only the correct PostScript sequence.
It require some basic knowledge of PostScript, but few things are needed
(mainly to understand the reverse polish notation and to know some
operators). exp(x^2) must be coded "2.71828 x x mul exp", etc.

\documentclass{article}

\usepackage{pst-plot}

\pagestyle{empty}

\begin{document}

\begin{pspicture}(-2,-0.5)(2,10)
  \psaxes(0,0)(-2,0)(2,10)
  \psplot{-1.5}{1.5}{2.71828 x exp}                      % exp(x)
  \psplot[linecolor=red]{-1.5}{1.5}{2.71828 x x mul exp} % exp(x^2)
\end{pspicture}

\end{document}


  Look at the references I gave in an answer in the archives:
http://tug.org/pipermail/pstricks/2001/000602.html

  The references to the pages of P.J. Weingartner are not valid anymore
(http://gamba.math.ubc.ca/localdoc/Flat/...). Today, you can found a copy
of theses pages at:

http://www.nottingham.ac.uk/~ppzsjm/manuals/ps/math.html
http://www.nottingham.ac.uk/~ppzsjm/manuals/ps/math-ref.html
http://www.nottingham.ac.uk/~ppzsjm/manuals/ps/PS-index.html

  There are some examples on the PSTricks Web pages:
http://tug.org/applications/PSTricks/Mathematics
http://tug.org/applications/PSTricks/Curves

  You can also look at the recent articles by Laura Jackson and Herbert Voss
in the publication of the german TeX user's group, Die TeXnische
Komoedie (in german, but of course the codes are readable by non german
speakers) - I will add these references on the Web page:

Die mathematischen Funktionen von PostScript
(The mathematical Functions of PostScript)
http://www.perce.de/LyX/Documentation/pst-plot.pdf

Die Plotfunktionen von pst-plot
(The plot Commands of pst-plot)
http://www.perce.de/LyX/Documentation/pst-plot2.pdf

    Cyrille.Piatecki> Third, Could some one explain how work the clipping tool for coloring the 
    Cyrille.Piatecki> intersection of two curves. I certainly have not understood the way it 
    Cyrille.Piatecki> works since each time I use it it cost me many hours to arrive to my end.

  There is nothing more that what is explained in the manual page 55.
To understand it, study it step by step as in the following code. I think that
the main difficulty is to understand why the \lineto(4,4) and \lineto(0,0) are
required. In fact, you will see that \lineto(4,4) could be omitted here,
due to what is the maximum of the second function (3 x x mul 3 div sub)
for the values plotted, but would be necessary for some other functions.

  You can found a more sophisticated example written by Philippe Esperet in
1996 on http://tug.org/applications/PSTricks/Mathematics (2 - Associativity).


\documentclass{article}

\usepackage{pst-plot}

\setlength{\textheight}{25cm}

\pagestyle{empty}

\begin{document}

\begin{pspicture}(-0.5,-1)(4,4)
  \psaxes(4,4)
  \psplot{0}{3}{3 x x mul 3 div sub}
  \psplot{0.5}{4}{2 x div}
\end{pspicture}
\hfill
\begin{pspicture}(-0.5,-1)(4,4)
  \psframe*[linecolor=lightgray](4,4)
  \psaxes(4,4)
  \psplot{0.5}{4}{2 x div}
  \psplot{0}{3}{3 x x mul 3 div sub}
\end{pspicture}

\begin{pspicture}(-0.5,-1)(4,4)
  \psaxes(4,4)
  \pscustom[linecolor=red]{%
    \psplot{0.5}{4}{2 x div}
    \lineto(4,4)}
  \pscustom[linecolor=blue]{%
    \psplot{0}{3}{3 x x mul 3 div sub}
    \lineto(0,0)}
\end{pspicture}
\hfill
\begin{pspicture}(-0.5,-1)(4,4)
  \psaxes(4,4)
  \begin{psclip}{\pscustom[linecolor=red]{%
                   \psplot{0.5}{4}{2 x div}
                   \lineto(4,4)}
                 \pscustom[linecolor=blue]{%
                   \psplot{0}{3}{3 x x mul 3 div sub}
                   \lineto(0,0)}}
    \psframe*[linecolor=lightgray](4,4)
  \end{psclip}%
\end{pspicture}

% The two next versions are wrong,
% but this is important to understand why...
\begin{pspicture}(-0.5,-1)(4,4)
  \psaxes(4,4)
  \begin{psclip}{\pscustom[linecolor=red]{%
                   \psplot{0.5}{4}{2 x div}}
                 \pscustom[linecolor=blue]{%
                   \psplot{0}{3}{3 x x mul 3 div sub}}}
    \psframe*[linecolor=lightgray](4,4)
  \end{psclip}%
\end{pspicture}
\hfill
\begin{pspicture}(-0.5,-1)(4,4)
  \psaxes(4,4)
  \begin{psclip}{\pscustom[linecolor=red]{%
                   \psplot{0.5}{4}{2 x div}}
                 \pscustom[linecolor=blue]{%
                   \psplot{0}{3}{3 x x mul 3 div sub}}}
    \psframe*[linecolor=lightgray](4,4)
  \end{psclip}%
  \psline[linecolor=green](0,3)(3,0)
\end{pspicture}

\begin{pspicture}(-0.5,-1)(4,4)
  \psaxes(4,4)
  \begin{psclip}{\pscustom[linecolor=red]{%
                   \psplot{0.5}{4}{2 x div}
                   \lineto(4,4)}
                 \pscustom[linecolor=blue]{%
                   \psplot{0}{3}{3 x x mul 3 div sub}
                   \lineto(0,0)}}
    \psframe*[linecolor=lightgray](4,4)
  \end{psclip}%
  \psplot{0}{3}{3 x x mul 3 div sub}
  \psplot{0.5}{4}{2 x div}
\end{pspicture}
\hfill
\begin{pspicture}(-0.5,-1)(4,4)
  \psaxes(4,4)
  \begin{psclip}{\pscustom[linestyle=none]{%
                   \psplot{0.5}{4}{2 x div}
                   \lineto(4,4)}
                 \pscustom[linestyle=none]{%
                   \psplot{0}{3}{3 x x mul 3 div sub}
                   \lineto(0,0)}}
    \psframe*[linecolor=lightgray](4,4)
  \end{psclip}%
  \psplot{0}{3}{3 x x mul 3 div sub}
  \psplot{0.5}{4}{2 x div}
\end{pspicture}

\end{document}


D.G.



More information about the PSTricks mailing list