[pstricks] ps code redundancy

Matteo Gattanini matteo.gattanini at libero.it
Mon Jun 16 14:16:22 CEST 2003


Hi to everybody (my excuses for my bad English).

basing myself on the suggestions of Denis Girou in this newsletter
(thanks.)  I have written a stupid macro (based on pstricks and
pst-node) that draws a closed line that embraces three nodes (I used it
in a recent work to emphasize in the mathematical formulas the terms
that must be simplified). The line is composed by two beziers and three
arcs.

  

A lot of annoying limitations are due to the fact that is not possible
retrieve information on position and radius of the circular nodes,
forcing the user to insert them as parameters of the macro; a lot of
other ones are due to my mediocrity. I post this macro for two reason:

- I would like to understand how to optimize my apparent redundant
postscript code

  and eventually fix macro limitations

- For the remote possibility that this macro can interest someone...

 

 

\documentclass{article}

\usepackage{pstricks,pst-node}

\SpecialCoor

 

%------------------------------------------------------begin Macro %
use:  \embr[par](central-node, peripheral-node, peripheral-node) % this
macro needs \SpecialCoor \makeatletter
\def\psset at alphaA#1{\edef\psk at alphaA{#1}} % angles relative to
directions \def\psset at alphaB#1{\edef\psk at alphaB{#1}}

\def\psset at thetaA#1{\edef\psk at thetaA{#1}} % directions of peripherals
nodes \def\psset at thetaB#1{\edef\psk at thetaB{#1}}

\def\psset at Radius#1{\edef\psk at Radius{#1}}

\def\psset at Curv#1{\edef\psk at Curv{#1}}

\psset at thetaA{225} \psset at thetaB{-45} \psset at Radius{.6} % default values
\psset at alphaA{0} \psset at alphaB{0} \psset at Curv{.9} \psset at linecolor{gray}
\psset at linewidth{.2pt} \def\embr{\pst at object{embr}}
\def\embr at i(#1){\@ifnextchar({\embr at ii(#1)}{\embr at ii(#1)}} % default
input not used \def\embr at ii(#1,#2,#3){% \begin at OpenObj \psset{unit=1cm}
\cnode[linestyle=none](#1){\psk at Radius}{OCN}

\cnode[linestyle=none](#2){\psk at Radius}{ACN}

\cnode[linestyle=none](#3){\psk at Radius}{BCN}

%
*** Beziers O->A ***

\pccurve[angleA=!\psk at thetaA\space \psk at alphaA\space add

                 \psk at thetaB\space \psk at alphaB\space add 180 add gt

                 {\psk at thetaA\space \psk at alphaA\space add}

                 {\psk at thetaA\space \psk at alphaA\space add
\psk at thetaB\space add \psk at alphaB\space add 2 div 90 add}

                  ifelse%

        ,angleB=!\psk at thetaA\space \psk at alphaA\space sub 180
add,ncurv=\psk at Curv]{-}%

        ([angle=!\psk at thetaA\space \psk at alphaA\space add

                 \psk at thetaB\space \psk at alphaB\space add 180 add gt

                {\psk at thetaA\space \psk at alphaA\space add 90 sub}

                {\psk at thetaA\space \psk at alphaA\space add
\psk at thetaB\space add \psk at alphaB\space add 2 div}

                 ifelse]OCN)%

        ([angle=!\psk at thetaA\space \psk at alphaA\space sub 90 sub]ACN)
\pccurve[angleA=!\psk at thetaA\space \psk at alphaA\space add

                 \psk at thetaB\space \psk at alphaB\space add 180 add gt

                 {\psk at thetaA\space \psk at alphaA\space add
\psk at thetaB\space add \psk at alphaB\space add 2 div 90 add}

                 {\psk at thetaA\space \psk at alphaA\space add}

                  ifelse%

        ,angleB=!\psk at thetaA\space \psk at alphaA\space sub 180
add,ncurv=\psk at Curv]{-}%

        ([angle=!\psk at thetaA\space \psk at alphaA\space add

                 \psk at thetaB\space \psk at alphaB\space add 180 add gt

                 {\psk at thetaA\space \psk at alphaA\space add
\psk at thetaB\space add \psk at alphaB\space add 2 div 180 add}

                 {\psk at thetaA\space \psk at alphaA\space add 90 add}

                  ifelse]OCN)%

        ([angle=!\psk at thetaA\space \psk at alphaA\space sub 90 add]ACN)

%
*** Beziers O->B ***

\pccurve[angleA=!\psk at thetaA\space \psk at alphaA\space add

                 \psk at thetaB\space \psk at alphaB\space add 180 add gt

                 {\psk at thetaB\space \psk at alphaB\space add}

                 {\psk at thetaA\space \psk at alphaA\space add
\psk at thetaB\space add \psk at alphaB\space add 2 div 90 sub}

                  ifelse%

        ,angleB=!\psk at thetaB\space \psk at alphaB\space sub 180
add,ncurv=\psk at Curv]{-}%

        ([angle=!\psk at thetaA\space \psk at alphaA\space add

                 \psk at thetaB\space \psk at alphaB\space add 180 add gt

                 {\psk at thetaB\space \psk at alphaB\space add 90 add}

                 {\psk at thetaA\space \psk at alphaA\space add
\psk at thetaB\space add \psk at alphaB\space add 2 div}

                  ifelse]OCN)%

        ([angle=!\psk at thetaB\space \psk at alphaB\space sub 90 add]BCN)
\pccurve[angleA=!\psk at thetaA\space \psk at alphaA\space add

                 \psk at thetaB\space \psk at alphaB\space add 180 add gt

                 {\psk at thetaA\space \psk at alphaA\space add
\psk at thetaB\space add \psk at alphaB\space add 2 div 90 sub}

                 {\psk at thetaB\space \psk at alphaB\space add}

                  ifelse%

        ,angleB=!\psk at thetaB\space \psk at alphaB\space sub 180
add,ncurv=\psk at Curv]{-}%

        ([angle=!\psk at thetaA\space \psk at alphaA\space add

                 \psk at thetaB\space \psk at alphaB\space add 180 add gt

                 {\psk at thetaA\space \psk at alphaA\space add
\psk at thetaB\space add \psk at alphaB\space add 2 div 180 add}

                 {\psk at thetaB\space \psk at alphaB\space add 90 sub}
ifelse]OCN)%

        ([angle=!\psk at thetaB\space \psk at alphaB\space sub 90 sub]BCN)

%
*** arc node A and B ***

\psarc{-}(#2){\psk at Radius}{! \psk at thetaA\space \psk at alphaA\space sub 90
sub}%

                          {! \psk at thetaA\space \psk at alphaA\space sub 90
add} \psarc{-}(#3){\psk at Radius}{! \psk at thetaB\space \psk at alphaB\space
sub 90 sub}%

                          {! \psk at thetaB\space \psk at alphaB\space sub 90
add}

%
*** arc node O ***

\psarc{-}(#1){\psk at Radius}{! \psk at thetaA\space \psk at alphaA\space add

                             \psk at thetaB\space \psk at alphaB\space add 180
add gt

                            {\psk at thetaB\space \psk at alphaB\space add 90
add}

                            {\psk at thetaA\space \psk at alphaA\space add 90
add}

                            ifelse}

                          {! \psk at thetaA\space \psk at alphaA\space add

                             \psk at thetaB\space \psk at alphaB\space add 180
add gt

                            {\psk at thetaA\space \psk at alphaA\space add 90
sub}

                            {\psk at thetaB\space \psk at alphaB\space add 90
sub}

                            ifelse}

\end at OpenObj}

\makeatother
%------------------------------------------------------------end Macro

 

\begin{document}

\Huge

\[
\frac{\rnode{A1}{A_1}+\rnode{B1}{B_1}+\rnode{C1}{C_1}}{\rnode{D1}{D_1}+\
rnode{E1}{E_1}+\rnode{F1}{F_1}} \] \bigskip \[
\frac{\rnode{A2}{A_2}+\rnode{B2}{B_2}+\rnode{C2}{C_2}}{\rnode{D2}{D_2}+\
rnode{E2}{E_2}+\rnode{F2}{F_2}} \] \bigskip \[
\frac{\rnode{A3}{A_3}+\rnode{B3}{B_3}+\rnode{C3}{C_3}}{\rnode{D3}{D_3}+\
rnode{E3}{E_3}+\rnode{F3}{F_3}} \] \bigskip \[
\frac{\rnode{A4}{A_4}+\rnode{B4}{B_4}+\rnode{C4}{C_4}}{\rnode{D4}{D_4}+\
rnode{E4}{E_4}+\rnode{F4}{F_4}} \]

 

\embr(B1,D1,F1)

\embr[linecolor=red,linestyle=dashed,thetaA=110,thetaB=60](E2,A2,C2)

\embr[linecolor=blue,linewidth=2pt,thetaA=270,thetaB=-20,alphaA=0,alphaB
=-15](A3,D3,F3)

\embr[linecolor=green,thetaA=180,thetaB=90,alphaA=-40,alphaB=0,Curv=1]F4
,D4,C4)

 

\end{document}

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/pstricks/attachments/20030616/3b6f2970/attachment.html 


More information about the PSTricks mailing list