[pstricks] Power Balance Schemes

Matteo Gattanini matteo.gattanini at libero.it
Sat Jan 17 11:28:13 CET 2004


In "Politecnico of Milan" we sometimes describe power balances with 
graphical schemes representing the power main flux and losses.
LaTeX and PStricks give a good way to automate the drawing of such schemes; 
the following code seems to work, and perhaps may be useful for someone 
(even if it can be improved).
An annoying thing is that isn't possible to put PS code in `nodesep' 
option; to perform some multiplications `fp.sty' is loaded, I don't find a 
better way. How can be avoided the use of additional calculation packages?
The code:

\NeedsTeXFormat{LaTeX2e}
\documentclass{report}
\usepackage{amsmath}
\usepackage{pstricks,pst-node}
\usepackage{fp} % avoidable?
\SpecialCoor
%___ POWER SCHEME ___
%
%      \begin{PSpic_PowSch}{`width'}{`height'}{`label pow-in'}{`label pow-out'}
%          \PowLoss[`inter pow flux label']{`relative horizontal 
position'}{`loss relative amount'}{`label'}
%          ...
%      \end{PSpic_PowSch}
%
\newcommand{\PowLoss}[4][ ]{%
%                               CALCULATIONS NEEDED: NO PS IN `nodesep'
     \FPmul\DeltaX\Lrgh{#2} % with `fp.sty'
     \FPmul\DeltaY\PW{#3}
     \FPmul\HalfDeltaY\DeltaY{.5}
     \FPmul\SmallRadius\DeltaY\rCur
     \FPmul\ArrowFly\DeltaY\rLarr
     \FPmul\ArrowPeak\DeltaY\rHarr
%                               NODE DEFINITIONS
     \pnode(CurPoint){PrevPoint}
     \pnode(\DeltaX,0|PrevPoint){PointRelX}
     \pnode([nodesep=\DeltaY,angle=-90]PrevPoint){PointRelY}
     \pnode(PointRelX|PointRelY){CurPoint}
     \pnode([nodesep=\SmallRadius,angle=90]PointRelX){PointRadius}
     \pnode([nodesep=\SmallRadius,angle=0]PointRadius){PointOne}
     \pnode([nodesep=\ArrowFly,angle=180]PointOne){PointTwo}
     \pnode([nodesep=\DeltaY,angle=0]PointOne){PointThree}
     \pnode([nodesep=\ArrowFly,angle=0]PointThree){PointFour}
     \pnode([nodesep=\HalfDeltaY,angle=0]PointOne|[nodesep=\ArrowPeak,angle=90]PointOne){PointPeak}
%                               DRAWING ARROW
     \psline(PrevPoint)(PointRelX)
     \ncarc[arcangle=-45]{-}{PointRelX}{PointOne}
     \ncarc[arcangle=-45]{-}{CurPoint}{PointThree}
     \psline(PointOne)(PointTwo)(PointPeak)(PointFour)(PointThree)
     \nput[labelsep=.2]{90}{PointPeak}{#4}% loss label
%                               OPTIONAL POWER FLUX LABEL
     \ifx#1 \relax % if no label do nothing
     \else\ncline[linestyle=none]{-}{PrevPoint}{PointRelX}\ncput{\pnode{MPointUp}}
          \pnode(MPointUp|0,0){MPointDwn}
          \ncline[linestyle=solid,linewidth=.5pt,nodesep=.05]{<->}{MPointUp}{MPointDwn}\naput{#1}\fi
}
\newenvironment{PSpic_PowSch}[4]{% >>> OPENING ENVIRONMENT
     \psset{unit=1cm,linestyle=solid,linewidth=.035}
%                               DIMENSIONAL PARAMETERS DEFINITION
     \def\Lrgh{#1}\def\Altz{#2}% PSpicture dimensions
     \def\Hcoeff{.65}\FPmul\PW\Altz\Hcoeff% pow-in relative value (`fp.sty' 
needed)
     \def\rHarr{.8}\def\rLarr{.35}% loss arrows relative dimensions
     \def\rCur{1}% arrows curvature radius relative value
     \def\Punta{.5}% in-out peak dimension
%                               PICTURE
     \begin{pspicture}(\Lrgh,\Altz)
         \pnode(!0 \Hcoeff\space \Altz\space mul){StartPoint}
         \pnode(StartPoint){CurPoint}
         \pnode(!\Punta\space \Hcoeff\space \Altz\space mul 2 div){MiddleSx}
         \psline(0,0)(MiddleSx)(StartPoint)
         \nput[labelsep=.3]{0}{MiddleSx}{#3}% pow-in label
         \def\potUlabel{#4}}% pow-out label
                                 {% >>> CLOSING ENVIRONMENT
         \pnode(\Lrgh,0){ExtPointDxDown}
         \pnode(ExtPointDxDown|CurPoint){ExtPointDxUp}
         \ncline[linestyle=none]{-}{ExtPointDxUp}{ExtPointDxDown}\ncput{\pnode{MiddleDx}}
         \psline(CurPoint)([nodesep=\Punta,angle=180]ExtPointDxUp)(MiddleDx)%
                ([nodesep=\Punta,angle=180]ExtPointDxDown)(0,0)
         \newlength{\ObjWidth}\settowidth{\ObjWidth}{\potUlabel}
         \pnode([nodesep=\ObjWidth,angle=180]MiddleDx){LabelDx}
         \nput[labelsep=-.3]{0}{LabelDx}{\potUlabel}
     \end{pspicture}}
%¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
\begin{document}
In figure~\ref{fig:power-scheme} there's the output; the choosed dimensions 
are \(12cm \times 6cm\).
\begin{figure}[h]\centering
     \begin{PSpic_PowSch}{12}{6}{\(P_e\)}{\(P_u\)}
         \PowLoss{.18}{.12}{\(R_s \, I_s^2\)} % Joule
         \PowLoss{.35}{.08}{\(G_{Fe} \, E_s^{\phantom{.}2}\)} % iron
         \PowLoss[\(P_{tr}=\dfrac{\omega}{n} C_e\)]{.62}{.13}{\(R_R \, 
I_r^2\)} % Joule
         \PowLoss[\(\dfrac{\omega_m}{n} C_e\)]{.79}{.09}{\textit{attr}} % mec
     \end{PSpic_PowSch}
     \caption{A power scheme for the asyncronous motor}\label{fig:power-scheme}
\end{figure}
\end{document}




More information about the PSTricks mailing list