[pstricks] \psLCNode variant

Michael Sharpe msharpe at ucsd.edu
Fri Oct 3 01:08:50 CEST 2008


On Oct 2, 2008, at 1:48 AM, Herbert Voss wrote:

> Michael,
> please give also an example, where you use it.

The following example could be handled using more traditional  
techniques, but in my opinion, this way allows for simpler Postscript  
coding.

\documentclass[11pt]{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\pagestyle{empty}
%macro to make polyline joining sequence of nodes
\def\psnline#1(#2,#3)#4{\xdef\tmp{#1}\multido{\i=#2+1}{#3}%
{\xdef\tmp{\tmp(#4\i)}}\expandafter\psline\tmp}
%\psnline[linecolor=red,arrows=->](0,101){P} expands to
% \psline[linecolor=red,arrows=->](P0)(P1)...(P100)
% assuming P0,...,P100 are previously defined nodes.

\makeatletter
% build the linear combination #3[1]]*#1+#3[[2]]*#2=#4
\def\psLCNodeVar(#1)(#2)(#3)#4{%
  \pst at getcoor{#1}\pst at tempA%
  \pst at getcoor{#2}\pst at tempB%
  \pnode(#3){tmpn at de}
  \pnode(!%
    \pst at tempA /YA exch \pst at number\psyunit div def
    /XA exch \pst at number\psxunit div def
    \pst at tempB /YB exch \pst at number\psyunit div def
    /XB exch \pst at number\psxunit div def %stack now empty
    \psGetNodeCenter{tmpn at de}\space
    XA tmpn at de.x mul XB tmpn at de.y mul add
    YA tmpn at de.x mul YB tmpn at de.y mul add){#4}%
}
\makeatother
\begin{document}
\SpecialCoor
% Given two sequences of pnodes, P0...Pn, Q0...Qn, draw polyline joining
% some interpolating points R0...Rn
\begin{pspicture}[showgrid=true](-5,-5)(5,5)
\multido{\i=0+1}{361}{%
\pnode(! \i\space dup cos 3 mul exch sin 2 mul){P\i}%points on inner  
ellipse
\pnode(! \i\space dup cos 5 mul exch sin 3 mul){Q\i}%points on outer  
ellipse
\pnode(! \i\space 3 mul cos dup mul dup 1 sub neg){C\i}%coefficients
\psLCNodeVar(P\i)(Q\i)(C\i){R\i}% define interpolating points
}
\psnline(0,361){P}\psnline(0,361){Q}
\psnline[linecolor=red](0,361){R}
\end{pspicture}
\end{document}




More information about the PSTricks mailing list